From: Andrew Morton <akpm@linux-foundation.org>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: linux-kernel@vger.kernel.org, David Laight <David.Laight@ACULAB.COM>
Subject: Re: [PATCH] Drop -Wdeclaration-after-statement
Date: Fri, 25 Feb 2022 17:10:04 -0800 [thread overview]
Message-ID: <20220225171004.edfda47af82ae98ef1c18b9d@linux-foundation.org> (raw)
In-Reply-To: <YhiQPhsoODiXRAPy@localhost.localdomain>
On Fri, 25 Feb 2022 11:15:58 +0300 Alexey Dobriyan <adobriyan@gmail.com> wrote:
> Putting declarations before statement is relict of single pass compiler
> era. It was necessary to allocate stack slots before generating code.
>
> Recently added static_assert() is a declaration. -Wdeclaration-after-statement
> prevents its placement anywhere in the code for no reason.
>
> Placing variable declarations in the beginning of the block increases
> variable "LOC lifetime" so to speak and chances that it will be misused.
> This is very low probability bug but still. Declaring variables right
> before first use will make "LOC lifetime" smaller.
>
> {
> int x;
> [x is misused due to a typo]
> f(x); // first correct use
> }
>
> vs
>
> {
> [can't misuse undeclared variable]
> int x;
> f(x); // first correct use
> }
>
Oh man. I so wish you'd cc'ed Linus on this one so we could admire his
reaction.
next prev parent reply other threads:[~2022-02-26 1:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
-- strict thread matches above, loose matches on Subject: below --
2019-03-10 13:35 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
2019-03-12 20:53 ` Andrew Morton
2019-03-12 20:24 ` Alexey Dobriyan
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=20220225171004.edfda47af82ae98ef1c18b9d@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=David.Laight@ACULAB.COM \
--cc=adobriyan@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome