Description of problem: It's a common pattern in large software projects to define a single header file shared by many smaller object files. This leads to gcc displaying hundreds of unused const variable warnings where a const defined in the .h may be used in 2 or 3 source, files, but not all. In any file it is not used, the warning is omitted. For example: I0> cat test_b.c #include "test.h" void do_nothing() { return; } I0> cat test_a.c #include "test.h" int main(int argc, char **argv) { do_nothing(); printf("%s\n", hello_world); } I0> cat test.h #include <stdio.h> void do_nothing(); static char* const hello_world = "Hello World"; I0> cat Makefile all: test_a test_a: test_b gcc -Wall -o test test_b.o test_a.c test_b: gcc -Wall -c -fpic -o test_b.o test_b.c Running this yields: gcc -Wall -c -fpic -o test_b.o test_b.c In file included from test_b.c:2:0: test.h:5:20: warning: ‘hello_world’ defined but not used [-Wunused-const-variable] static char* const hello_world = "Hello World"; ^~~~~~~~~~~ gcc -Wall -o test test_b.o test_a.c Which is incorrect: the const variable *is* used, but just not in this file yet. I *like* the idea of the unused-const-variable check, but too many false positives will lead to it being disabled. I am not sure what the correct solution is here: Perhaps const variables in .h files are ignored? Perhaps there needs to be a way to track these over man runs of gcc through a cache / check file? Until this is fixed, I do not think that it is wise to include unused-const-variable in -Wall, as it will create excessive noise and could diminish the value of the feature.
As discussed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28901, -Wunused-const-variable now has two levels: "One level to only check for unused static const variables in the main compilation file. Which is enabled by -Wunused-variable. And a second level that also checks for unused static const variables in included files. Which must be explicitly enabled." It'll be in the next Fedora GCC build I suspect.
This bug appears to have been reported against 'rawhide' during the Fedora 24 development cycle. Changing version to '24'. More information and reason for this action is here: https://fedoraproject.org/wiki/Fedora_Program_Management/HouseKeeping/Fedora24#Rawhide_Rebase
Should be fixed in gcc-6.0.0-0.13.fc24.