Re: [PATCH] Drop -Wdeclaration-after-statement
From: Alexey Dobriyan
Date: Fri Feb 25 2022 - 12:25:09 EST
On Fri, Feb 25, 2022 at 10:01:23AM +0000, David Laight wrote:
> From: Alexey Dobriyan
> > Sent: 25 February 2022 08:16
> >
> > 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.
>
> That could enclose its declaration inside a block.
It could but why put useless characters on the screen?
> But then it wouldn't be usable at global scope (is it anyway?)
It is usable in global scope.
> > 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.
>
> NAK it makes it very hard for a human (some of us are) to find
> the declaration.
What?
Which editor are you using?
Shift+3 with selection highlighting in vim works just fine.
I don't believe Emacs doesn't have an equivalent.
> Indeed putting them anywhere other that the top of a function
> or the top of a very short code block makes them hard to find.