diff options
author | Marek Polacek <polacek@redhat.com> | 2024-01-24 18:06:48 -0500 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-05-08 12:22:05 -0400 |
commit | d9318caed3bbff8136d13e00dcfc020a59d10f78 (patch) | |
tree | 30c1fe8184bce80b96b0af66c0e4c90d7b7561d3 /gcc/cp/parser.cc | |
parent | 5726de79e2154a16d8a045567d2cfad035f7ed19 (diff) | |
download | gcc-d9318caed3bbff8136d13e00dcfc020a59d10f78.zip gcc-d9318caed3bbff8136d13e00dcfc020a59d10f78.tar.gz gcc-d9318caed3bbff8136d13e00dcfc020a59d10f78.tar.bz2 |
c++: #pragma doesn't disable -Wunused-label [PR113582]
The PR complains that
void do_something(){
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-label"
start:;
#pragma GCC diagnostic pop
} #1
doesn't work. That's because we warn_for_unused_label only while we're
in finish_function, meaning we're at #1 where we're outside the #pragma
region. We can use suppress_warning + warning_suppressed_p to fix this.
Note that I'm not using TREE_USED. Propagating it in tsubst_stmt/LABEL_EXPR
from decl to label would mean that we don't warn in do_something2, but
I think we want the warning there: we're in a template and the goto is
a discarded statement.
PR c++/113582
gcc/c-family/ChangeLog:
* c-warn.cc (warn_for_unused_label): Don't warn if -Wunused-label has
been suppressed for the label.
gcc/cp/ChangeLog:
* parser.cc (cp_parser_label_for_labeled_statement): suppress_warning
if it's not enabled at input_location.
* pt.cc (tsubst_stmt): Call copy_warning.
gcc/testsuite/ChangeLog:
* g++.dg/warn/Wunused-label-4.C: New test.
Diffstat (limited to 'gcc/cp/parser.cc')
-rw-r--r-- | gcc/cp/parser.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index c419120..7306ce9 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -13108,7 +13108,11 @@ cp_parser_label_for_labeled_statement (cp_parser* parser, tree attributes) /* Anything else must be an ordinary label. */ label = finish_label_stmt (cp_parser_identifier (parser)); if (label && TREE_CODE (label) == LABEL_DECL) - FALLTHROUGH_LABEL_P (label) = fallthrough_p; + { + FALLTHROUGH_LABEL_P (label) = fallthrough_p; + if (!warning_enabled_at (input_location, OPT_Wunused_label)) + suppress_warning (label, OPT_Wunused_label); + } break; } |