RE: [PATCH] Drop -Wdeclaration-after-statement

From: David Laight
Date: Fri Feb 25 2022 - 05:01:32 EST


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.
But then it wouldn't be usable at global scope (is it anyway?)

> 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.

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.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)