This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/28901] -Wunused-variable ignores unused const initialised variables


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

--- Comment #27 from Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> ---
(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).

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=).

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))

Whoever wants to see this fixed, should hurry up before GCC 6 closes.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]