On Sat, Sep 12, 2015 at 12:29:05AM +0200, Bernd Schmidt wrote:
> On 09/12/2015 12:12 AM, Mark Wielaard wrote:
> >12 years ago it was decided that -Wunused-variable shouldn't warn about
> >static const variables because some code used const static char rcsid[]
> >strings which were never used but wanted in the code anyway. But as the
> >bug points out this hides some real bugs. These days the usage of rcsids
> >is not very popular anymore. So this patch changes the default to warn
> >about unused static const variables with -Wunused-variable. And it adds
> >a new option -Wno-unused-const-variable to turn this warning off. New
> >testcases are included to test the new warning with -Wunused-variable
> >and suppressing it with -Wno-unused-const-variable or unused attribute.
> 
> >        PR c/28901
> >        * gcc.dg/unused-4.c: Adjust warning for static const.
> >        * gcc.dg/unused-variable-1.c: New test.
> >        * gcc.dg/unused-variable-2.c: Likewise.
> 
> Should these go into c-c++-common?

No. It is C only. But I realize that isn't really clear from my patch
nor from the documentation I wrote for it. Since in C++ a const isn't
by default file scoped and const variables always need to be initialized
they are used differently than in C. Where in C you would use a #define
in C++ you would use a const. So the cxx_warn_unused_global_decl ()
lang hook explicitly says to not warn about them. Although I think that
is correct, I now think it is confusing you cannot enable the warning
for C++ if you really want to. It should be off by default for C++, but
on by default for C when -Wunused-variable is enabled. But it would
actually be nice to be able to use it too for C++ if the user really
wants to instead of having the warning suppression for C++ hardcoded.

> Otherwise I'm ok with the patch, please
> wait a few days to see if there are objections to this change then commit.

I'll rewrite my patch a little, add some C++ testcases, and update the
documentation. Then we can discuss again.

Thanks,

Mark

Reply via email to