Does anyone still feel strongly about -Wdeclaration-after-statement ?
Jeremy Sequoia
jeremyhud at mac.com
Wed Jul 31 07:31:42 UTC 2024
I feel very strongly that we should be able to leverage language features that have existed for longer than college graduates have been alive and should remove warnings designed to ensure we maintain compatibility with compilers that existed when pinball machines were all the rage.
I'd even go farther and say that we should allow code that requires C11.
On the point of style, I really prefer declaring variables later (eg: where they're computed). I find it cleaner, and it also has the technical benefit of avoiding uninitialized variables that might be unexpectedly used if someone happens to re-order some code and doesn't realize that they introduced a read before initialization. Yes, that can be caught with static analysis, but still... don't rely on complex solutions when simpler solutions are available.
> On Jul 28, 2024, at 17:48, Alan Coopersmith <alan.coopersmith at oracle.com> wrote:
>
> Back when we first added a default set of compiler warning flags to our
> xorg-macros.m4 for autoconf in 2008, we included -Wdeclaration-after-statement
> since not all the compilers at the time supported this C99 feature (most
> notably some OpenBSD ports that used gcc 2.95, but also MSVC versions before
> 2013).
>
> Since then we've widely adopted other C99 features such as struct initializers
> and declaring variables in for loops ("for (int i = 0; ....)"), but last
> time we discussed this warning in 2013, decided to leave it in place as
> a style choice, not a technical constraint - see the thread starting at:
> https://lists.freedesktop.org/archives/xorg-devel/2013-September/037735.html
>
> But we didn't carry that flag over in our meson conversions - apparently
> intentionally so in the case of the X server code base:
> https://gitlab.freedesktop.org/xorg/xserver/-/commit/db465bae533f85e7f900deb96efecc831c9d550b
> so people patching the X server don't get told that we don't like that style,
> and so now Enrico has submitted a number of merge requests that use it to
> simplify some of our previous code, such as:
> https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1601
>
> Do we want to keep insisting on this as part of our style, or have people
> gotten used to it from other languages/projects now and are willing to
> accept it in X.Org code?
>
> Is it time to re-apply
> https://gitlab.freedesktop.org/xorg/util/macros/-/commit/689ea0ec5d8b7594ba2fa9e27b2458cea8a58724
> to util-macros?
>
> --
> -Alan Coopersmith- alan.coopersmith at oracle.com
> Oracle Solaris Engineering - https://blogs.oracle.com/solaris
More information about the xorg-devel
mailing list