From 2c63cc7268fd5615997989f153e9405d0f5aaa50 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 10 Mar 2023 10:10:24 +0100 Subject: c, c++, cgraphunit: Prevent duplicated -Wunused-value warnings [PR108079] On the following testcase, we warn with -Wunused-value twice, once in the FEs and later on cgraphunit again with slightly different wording. The following patch fixes that by registering a warning suppression in the FEs when we warn and not warning in cgraphunit anymore if that happened. 2023-03-10 Jakub Jelinek PR c/108079 gcc/ * cgraphunit.cc (check_global_declaration): Don't warn for unused variables which have OPT_Wunused_variable warning suppressed. gcc/c/ * c-decl.cc (pop_scope): Suppress OPT_Wunused_variable warning after diagnosing it. gcc/cp/ * decl.cc (poplevel): Suppress OPT_Wunused_variable warning after diagnosing it. gcc/testsuite/ * c-c++-common/Wunused-var-18.c: New test. --- gcc/c/c-decl.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gcc/c/c-decl.cc') diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 9159965..e537d33 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -1310,7 +1310,10 @@ pop_scope (void) && 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, -- cgit v1.1