https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113582
Marek Polacek <mpolacek at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org --- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> --- Hack/fix: diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 3748ccd49ff..224d47f2f90 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -13093,7 +13093,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; } diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 74013533b0f..b6686d8543f 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -18796,11 +18796,13 @@ tsubst_stmt (tree t, tree args, tsubst_flags_t complain, tree in_decl) case LABEL_EXPR: { tree decl = LABEL_EXPR_LABEL (t); - tree label; - - label = finish_label_stmt (DECL_NAME (decl)); + tree label = finish_label_stmt (DECL_NAME (decl)); if (TREE_CODE (label) == LABEL_DECL) - FALLTHROUGH_LABEL_P (label) = FALLTHROUGH_LABEL_P (decl); + { + FALLTHROUGH_LABEL_P (label) = FALLTHROUGH_LABEL_P (decl); + if (warning_suppressed_p (decl, OPT_Wunused_label)) + TREE_USED (label) = true; + } if (DECL_ATTRIBUTES (decl) != NULL_TREE) cplus_decl_attributes (&label, DECL_ATTRIBUTES (decl), 0); }