&& scope != external_scope)
{
if (!TREE_USED (p))
- warning (OPT_Wunused_variable, "unused variable %q+D", p);
+ {
+ warning (OPT_Wunused_variable, "unused variable %q+D", p);
+ suppress_warning (p, OPT_Wunused_variable);
+ }
else if (DECL_CONTEXT (p) == current_function_decl)
warning_at (DECL_SOURCE_LOCATION (p),
OPT_Wunused_but_set_variable,
&& (TREE_CODE (decl) != FUNCTION_DECL
|| (!DECL_STATIC_CONSTRUCTOR (decl)
&& !DECL_STATIC_DESTRUCTOR (decl)))
+ && (! VAR_P (decl) || !warning_suppressed_p (decl, OPT_Wunused_variable))
/* Otherwise, ask the language. */
&& lang_hooks.decls.warn_unused_global (decl))
warning_at (DECL_SOURCE_LOCATION (decl),
else
warning_at (DECL_SOURCE_LOCATION (decl),
OPT_Wunused_variable, "unused variable %qD", decl);
+ suppress_warning (decl, OPT_Wunused_variable);
}
else if (DECL_CONTEXT (decl) == current_function_decl
// For -Wunused-but-set-variable leave references alone.
--- /dev/null
+/* PR c/108079 */
+/* { dg-do compile } */
+/* { dg-options "-Wunused-variable" } */
+
+int
+main ()
+{
+ static int x; /* { dg-warning "unused variable 'x'" } */
+ /* { dg-bogus "'x' defined but not used" "" { target *-*-* } .-1 } */
+}