RFR: 8339120: Use more fine-granular gcc unused warnings

Kim Barrett kbarrett at openjdk.org
Wed Aug 28 06:41:19 UTC 2024


On Tue, 27 Aug 2024 20:04:21 GMT, Magnus Ihse Bursie <ihse at openjdk.org> wrote:

> Currently, we issue -Wno-unused for all files in gcc, which is a rather big sledgehammer to get rid of some warnings that proliferate in a few areas of the build.
> 
> We should instead leave -Wunused turned on (as done by -Wall) and use a much more fine-grained approach to disabling specific warnings in specific files or libraries.

We should make a similar set of changes for clang, though doing that in a separate
proposal is good.  Is there a JBS issue for that yet?

make/autoconf/flags-cflags.m4 line 239:

> 237:       # Additional warnings that are not activated by -Wall and -Wextra
> 238:       WARNINGS_ENABLE_ADDITIONAL="-Wpointer-arith -Wreturn-type -Wsign-compare \
> 239:           -Wtrampolines -Wundef -Wunused-const-variable -Wunused-function \

I think we don't want `-Wunused-const-variable=2` (eqv. `-Wunused-const-variable`) for C++
code. Recall that C++ const variables default to internal linkage (e.g. implicitly static). It's normal
to have a non-local constant in a header file that isn't used by every translation unit.  For C++ use
`-Wunused-const-variable=1`.  I think doing this might eliminate the need for disabling this warning
in a bunch of other places in this PR.

-------------

Changes requested by kbarrett (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/20733#pullrequestreview-2265277235
PR Review Comment: https://git.openjdk.org/jdk/pull/20733#discussion_r1734067573


More information about the core-libs-dev mailing list