https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28901
Josh Triplett <josh at joshtriplett dot org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |josh at joshtriplett dot org --- Comment #23 from Josh Triplett <josh at joshtriplett dot org> --- (In reply to Mark Wielaard from comment #21) > Although in C a static const is not really like a #define Why not? Many C projects try to avoid the preprocessor as much as possible. > I suspect that > there are cases where they are used as such in header files. If that is the > major reason for why there are people opposed to the warning then what we > could do is hide such (non-)usage of static const variables from header > files behind -Wextra and only explicitly warn for static const variable > defined (and then not used) in the main file. Please don't attach this to -Wextra; instead, please consider making it a -Wconst-unused-variable=2 or similar. Otherwise, projects using static const values in header files would get a massive pile of additional warnings, typically all false positives. In a main file, this makes sense and likely has relatively few false positives; the most common false positive would involve defining something only used in ifdef'd code, and even then tagging it with __attribute__((unused)) (Linux's __maybe_unused) seems correct. However, in a header file, any use of static const to define constants for a project will almost certainly get this warning, unless every single user of that header file (directly or indirectly) uses every constant (or unless the header itself does). Silently throwing away the unused constants seems like the right thing to do there.