From: Alexey Dobriyan <adobriyan@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Drop -Wdeclaration-after-statement
Date: Tue, 12 Mar 2019 23:18:53 +0300 [thread overview]
Message-ID: <20190312201853.GA9013@avx2> (raw)
In-Reply-To: <20190312125017.b1f5af3350434ca05b5fe35e@linux-foundation.org>
On Tue, Mar 12, 2019 at 12:50:17PM -0700, Andrew Morton wrote:
> On Tue, 12 Mar 2019 20:24:47 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
>
> > On Mon, Mar 11, 2019 at 05:38:45PM -0700, Andrew Morton wrote:
> > > On Sun, 10 Mar 2019 16:35:35 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> > >
> > > > Newly added static_assert() is formally a declaration, which will give
> > > > a warning if used in the middle of the function.
> > > >
> > > > ...
> > > >
> > > > --- a/Makefile
> > > > +++ b/Makefile
> > > > @@ -792,9 +792,6 @@ endif
> > > > # arch Makefile may override CC so keep this after arch Makefile is included
> > > > NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
> > > >
> > > > -# warn about C99 declaration after statement
> > > > -KBUILD_CFLAGS += -Wdeclaration-after-statement
> > > > -
> > > > # Variable Length Arrays (VLAs) should not be used anywhere in the kernel
> > > > KBUILD_CFLAGS += $(call cc-option,-Wvla)
> > >
> > > I do wish your changelogs were more elaborate :(
> >
> > > So the proposal is to disable -Wdeclaration-after-statement in all
> > > cases for all time because static_assert() doesn't work correctly?
> >
> > Yes. I converted 2 cases in /proc to static_assert() and you can't write
> >
> > {
> > [code]
> > static_assert()
> > }
> >
> > without a warning because static_assert() is declaration.
> > So people would move BUILD_BUG_ON() to where it doesn't belong.
>
> Sure.
>
> > > Surely there's something we can do to squish the static_assert() issue
> > > while retaining -Wdeclaration-after-statement?
> >
> > It is not good in my opinion to stick to -Wdeclaration-after-statement.
>
> Why?
It is useful to have declarations mixed with code.
It reduces effective scope of a variable:
int a;
[a misused]
...
[a used correctly]
vs
[a misused -- compile error]
...
int a;
[a used correctly]
It is possible to partially workaround that but at the cost of a
indentation level. I'll post the following patch soon:
- NEW_AUX_ENT(AT_UID, from_kuid_munged(cred->user_ns, cred->uid));
- NEW_AUX_ENT(AT_EUID, from_kuid_munged(cred->user_ns, cred->euid));
- NEW_AUX_ENT(AT_GID, from_kgid_munged(cred->user_ns, cred->gid));
- NEW_AUX_ENT(AT_EGID, from_kgid_munged(cred->user_ns, cred->egid));
+ {
+ const struct cred *cred = current_cred();
+ struct user_namespace *user_ns = cred->user_ns;
+
+ NEW_AUX_ENT(AT_UID, from_kuid_munged(user_ns, cred->uid));
+ NEW_AUX_ENT(AT_EUID, from_kuid_munged(user_ns, cred->euid));
+ NEW_AUX_ENT(AT_GID, from_kgid_munged(user_ns, cred->gid));
+ NEW_AUX_ENT(AT_EGID, from_kgid_munged(user_ns, cred->egid));
+ }
Often it is simply not possible to shift big function one level
deeper.
Another related thing, C99 has this very cool feature of per-for-loop
declarations:
for (int i = 0; ...)
Once kernel will switch to C99 or C11 it _will_ be used to the point of
requiring it on the coding style level. The superstition of declaring
everything in the beginning of a function will fall, so might as well
start earlier.
next prev parent reply other threads:[~2019-03-12 20:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-10 13:35 [PATCH] Drop -Wdeclaration-after-statement Alexey Dobriyan
2019-03-12 0:38 ` Andrew Morton
2019-03-12 17:24 ` Alexey Dobriyan
2019-03-12 19:50 ` Andrew Morton
2019-03-12 20:18 ` Alexey Dobriyan [this message]
2019-03-12 20:53 ` Andrew Morton
2019-03-12 20:24 ` Alexey Dobriyan
-- strict thread matches above, loose matches on Subject: below --
2022-02-25 8:15 Alexey Dobriyan
2022-02-25 10:01 ` David Laight
2022-02-25 17:24 ` Alexey Dobriyan
2022-02-26 1:10 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190312201853.GA9013@avx2 \
--to=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.