Paul Eggert wrote:
> > Is that use of -Wextra an experiment, or do you want to use it always?
> 
> Oh, it was just an experiment.
> 
> > I'm asking because some the warnings that it enables are undesired, IMO,
> 
> Quite right.

Glad to hear this.

I went through all warnings I could get from GCC 13 and formulated three
recommended sets of warnings for Gnulib; see the patch below. (I essentially
used the same approach as we do with the 'manywarnings' module. But rather
than hardwiring some "preferred" set of warning options into gnulib-tool's
--create-testdir command, I find it better to leave the choice to the
individual developer.)

> I expect that many of the warnings you found are false alarms, and that 
> it's low priority to look into this.

It really depends on the warning category. Some of the warnings I fixed
yesterday were really helpful:
  - for maintainability: -Wshadow
  - for finishing unfinished code: -Wunused-value
  - for POSIX compliance: -Wanalyzer-unsafe-call-within-signal-handler
  - other: -Wanalyzer-allocation-size

> I adjusted test code for the "xxx 
> is unused" warnings only because it was easy in the context of coreutils 
> and the warnings I found by the experiment were arguably useful.

The various forms of the 'main' declaration are _arguable_, yes.
  main ()
  main (_GL_UNUSED int argc, _GL_UNUSED char *argv[])
  main (_GL_UNUSED int argc, char *argv[])
  main (int argc, _GL_UNUSED char *argv[])
  main (int argc, char *argv[])
To me, that's clutter: it distracts the attention when I'm reading the code.


2023-09-05  Bruno Haible  <br...@clisp.org>

        Add info about recommended warning options.
        * HACKING: New section "Warning Options".

================================ >> HACKING ================================

Warning Options
===============

For packages that use Gnulib, we recommend to use the 'warnings' or
'manywarnings' module, as documented in
https://www.gnu.org/software/gnulib/manual/html_node/warnings.html
https://www.gnu.org/software/gnulib/manual/html_node/manywarnings.html

When building Gnulib testdirs, e.g. when preparing a Gnulib patch,
there are three possible approaches:

* The simplest approach, which warns about the most common mistakes, is to
  use GCC's -Wall option, both for C and C++ compilation units. Just set
    $ ./configure CPPFLAGS="-Wall"
    $ make
  You should generally fix all compiler warnings that you see from this
  approach.

* If you are developing on a glibc system and have GCC version 13 binaries
  available, here's a recipe that will find more mistakes, but is nearly
  as easy to use. Here, different warning options are needed for C and
  for C++:
    $ WARN_GCC13="-fanalyzer -Wall -Warith-conversion -Wcast-align=strict 
-Wdate-time -Wdisabled-optimization -Wduplicated-cond -Wextra 
-Wformat-signedness -Winit-self -Winvalid-pch -Wlogical-op 
-Wmissing-include-dirs -Wopenmp-simd -Woverlength-strings -Wpacked 
-Wpointer-arith -Wstrict-overflow -Wsuggest-final-methods -Wsuggest-final-types 
-Wsync-nand -Wsystem-headers -Wtrampolines -Wuninitialized -Wunknown-pragmas 
-Wunsafe-loop-optimizations -Wvariadic-macros -Wvector-operation-performance 
-Wwrite-strings -Warray-bounds=2 -Wattribute-alias=2 -Wformat-overflow=2 
-Wformat-truncation=2 -Wshift-overflow=2 -Wunused-const-variable=2 
-Wvla-larger-than=4031 -Wno-empty-body -Wno-analyzer-allocation-size 
-Wno-analyzer-fd-double-close -Wno-analyzer-double-fclose 
-Wno-analyzer-double-free -Wno-analyzer-fd-leak 
-Wno-analyzer-fd-use-after-close -Wno-analyzer-fd-use-without-check 
-Wno-analyzer-free-of-non-heap -Wno-analyzer-malloc-leak 
-Wno-analyzer-mismatching-deallocation -Wno-analyzer-null-argument 
-Wno-analyzer-null-dereference -Wno-analyzer-out-of-bounds 
-Wno-analyzer-possible-null-argument -Wno-analyzer-possible-null-dereference 
-Wno-analyzer-use-after-free -Wno-analyzer-use-of-pointer-in-stale-stack-frame 
-Wno-analyzer-use-of-uninitialized-value -Wno-analyzer-va-arg-type-mismatch 
-Wno-attribute-warning -Wno-cast-align -Wno-clobbered -Wno-dangling-pointer 
-Wno-format -Wno-implicit-fallthrough -Wno-maybe-uninitialized 
-Wno-missing-field-initializers -Wno-restrict -Wno-sign-compare -Wno-switch 
-Wno-type-limits -Wno-unused-parameter"
    $ WARN_CFLAGS_GCC13="$WARN_GCC13 -Wnested-externs -Wshadow=local 
-Wno-discarded-qualifiers"
    $ WARN_CXXFLAGS_GCC13="$WARN_GCC13 -Wno-cpp"
    $ ./configure CFLAGS="-O2 -g $WARN_CFLAGS_GCC13" CXXFLAGS="-O2 -g 
$WARN_CXXFLAGS_GCC13"
    $ make
  You should generally fix all compiler warnings that you see from this
  approach, or report when this approach produced a pointless warning
  (so that we can fix the value of WARN_GCC13 above).

* If you are developing on a glibc system and have GCC version 13 binaries
  available: Here's a recipe that will find even more mistakes, but it
  requires that you are willing to filter out and ignore pointless warnings.
    $ WARN_GCC13="-fanalyzer -Wall -Warith-conversion -Wcast-align=strict 
-Wdate-time -Wdisabled-optimization -Wduplicated-cond -Wextra 
-Wformat-signedness -Winit-self -Winvalid-pch -Wlogical-op 
-Wmissing-include-dirs -Wnull-dereference -Wopenmp-simd -Woverlength-strings 
-Wpacked -Wpointer-arith -Wstrict-overflow -Wsuggest-attribute=format 
-Wsuggest-final-methods -Wsuggest-final-types -Wsync-nand -Wsystem-headers 
-Wtrampolines -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations 
-Wvariadic-macros -Wvector-operation-performance -Wwrite-strings 
-Warray-bounds=2 -Wattribute-alias=2 -Wformat-overflow=2 -Wformat=2 
-Wformat-truncation=2 -Wimplicit-fallthrough=5 -Wshift-overflow=2 
-Wunused-const-variable=2 -Wvla-larger-than=4031 -Wno-empty-body 
-Wno-analyzer-double-fclose -Wno-analyzer-double-free 
-Wno-analyzer-free-of-non-heap -Wno-analyzer-malloc-leak 
-Wno-analyzer-null-argument -Wno-analyzer-null-dereference 
-Wno-analyzer-use-after-free -Wno-attribute-warning -Wno-cast-align 
-Wno-clobbered -Wno-format-nonliteral -Wno-sign-compare -Wno-type-limits 
-Wno-unused-parameter"
    $ WARN_CFLAGS_GCC13="$WARN_GCC13 -Wnested-externs -Wshadow=local"
    $ WARN_CXXFLAGS_GCC13="$WARN_GCC13 -Wno-cpp"
    $ ./configure CFLAGS="-O2 -g $WARN_CFLAGS_GCC13" CXXFLAGS="-O2 -g 
$WARN_CXXFLAGS_GCC13"
    $ make
  With this approach, use your own judgement whether to fix warnings
  arising from your new code or not.
  Do *not* submit patches to silence warnings from existing code:
    - For these warnings, often the cure will be worse than the disease.
    - Some of the warnings are false positives. Rather than silencing
      these warnings, we prefer to report them in the GCC bug tracker
      and wait until they are fixed in a future GCC release.




Reply via email to