https://gcc.gnu.org/bugzilla/show_bug.cgi?id=28901

--- Comment #29 from Mark Wielaard <mark at gcc dot gnu.org> ---
(In reply to Manuel López-Ibáñez from comment #27)
> (In reply to Mark Wielaard from comment #21)
> > Although in C a static const is not really like a #define 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.
> 
> We should not use -Wextra in this way, because after seeing the warning, it
> is not apparent to the user which option controls it. (That is, the same
> warning option printed in the output behaves differently when -Wextra is
> given).

OK, fair point.

> My suggestion is to never warn if declared in a header. If an extra option
> is desired (whether enabled by -Wextra or explicitly), then it would be
> better to call it something like Wunused-any-const-variable, because the
> meaning of numeric values are not apparent (and they do not play nicely with
> -Werror=).

I don't like to introduce yet another warning option name, there are several
warnings with increasing levels. If we go with enabling higher levels only
explicitly it seems fairly clear which level is meant. And I believe they are
clearly documented. If this is an issue with -Werror= then lets fix -Werror.
There are multiple warnings which have increasing levels.

> Note that it is trivial to find all unused static const variables in your
> headers: Just preprocess the file, remove line info and compile with
> -Wunused.
> 
> > +                   || filename_cmp (main_input_filename,
> > +                                    DECL_SOURCE_FILE (decl)) == 0)))
> 
> Better use MAIN_FILE_P(DECL_SOURCE_LOCATION (decl))

MAIN_FILE_P doesn't take a source location, but a line_map_ordinary, which
seems more cumbersome to get at from a decl then the filename to compare
against.

Reply via email to