aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c.opt
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2015-09-14 09:49:47 +0000
committerMark Wielaard <mark@gcc.gnu.org>2015-09-14 09:49:47 +0000
commit0f876f22887f239cedca64ff170b71e5f1daaf54 (patch)
tree69691ab92ba1ad50826f35684fac28f7495db523 /gcc/c-family/c.opt
parentcc099b03c01f74b2b8ddf87f93890bdbde2305f9 (diff)
downloadgcc-0f876f22887f239cedca64ff170b71e5f1daaf54.zip
gcc-0f876f22887f239cedca64ff170b71e5f1daaf54.tar.gz
gcc-0f876f22887f239cedca64ff170b71e5f1daaf54.tar.bz2
PR28901 -Wunused-variable ignores unused const initialised variables in C
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 in C with -Wunused-variable. And it adds a new option -Wno-unused-const-variable to turn this warning off. For C++ this new warning is off by default, since const variables can be used as #defines in C++. New testcases for the new defaults in C and C++ are included testing the new warning and suppressing it with an unused attribute or using -Wno-unused-const-variable. gcc/ChangeLog PR c/28901 * toplev.c (check_global_declaration): Check and use warn_unused_const_variable. * doc/invoke.texi (Warning Options): Add -Wunused-const-variable. (-Wunused-variable): Remove non-constant. For C implies -Wunused-const-variable. (-Wunused-const-variable): New. gcc/c-family/ChangeLog PR c/28901 * c.opt (Wunused-variable): Option from common.opt. (Wunused-const-variable): New option. gcc/cp/ChangeLog PR c/28901 * cp-objcp-common.c (cxx_warn_unused_global_decl): Remove hard-coded VAR_P TREE_READONLY override. gcc/testsuite/ChangeLog PR c/28901 * g++.dg/warn/unused-variable-1.C: New test. * g++.dg/warn/unused-variable-2.C: Likewise. * 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. From-SVN: r227742
Diffstat (limited to 'gcc/c-family/c.opt')
-rw-r--r--gcc/c-family/c.opt8
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index d519d7a..47ba070 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -912,6 +912,14 @@ Wunused-result
C ObjC C++ ObjC++ Var(warn_unused_result) Init(1) Warning
Warn if a caller of a function, marked with attribute warn_unused_result, does not use its return value
+Wunused-variable
+C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wunused)
+; documented in common.opt
+
+Wunused-const-variable
+C ObjC C++ ObjC++ Var(warn_unused_const_variable) Warning LangEnabledBy(C ObjC,Wunused-variable)
+Warn when a const variable is unused
+
Wvariadic-macros
C ObjC C++ ObjC++ CPP(warn_variadic_macros) CppReason(CPP_W_VARIADIC_MACROS) Var(cpp_warn_variadic_macros) Init(0) Warning LangEnabledBy(C ObjC C++ ObjC++,Wpedantic || Wtraditional)
Warn about using variadic macros