[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20220225171004.edfda47af82ae98ef1c18b9d@linux-foundation.org>
Date: Fri, 25 Feb 2022 17:10:04 -0800
From: Andrew Morton <akpm@...ux-foundation.org>
To: Alexey Dobriyan <adobriyan@...il.com>
Cc: linux-kernel@...r.kernel.org,
David Laight <David.Laight@...LAB.COM>
Subject: Re: [PATCH] Drop -Wdeclaration-after-statement
On Fri, 25 Feb 2022 11:15:58 +0300 Alexey Dobriyan <adobriyan@...il.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.
Powered by blists - more mailing lists