{
if (!TREE_USED (label))
{
- if (DECL_INITIAL (label))
+ if (warning_suppressed_p (label, OPT_Wunused_label))
+ /* Don't warn. */;
+ else if (DECL_INITIAL (label))
warning (OPT_Wunused_label, "label %q+D defined but not used", label);
else
warning (OPT_Wunused_label, "label %q+D declared but not defined", label);
/* 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;
}
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);
+ copy_warning (label, decl);
+ }
if (DECL_ATTRIBUTES (decl) != NULL_TREE)
cplus_decl_attributes (&label, DECL_ATTRIBUTES (decl), 0);
}
--- /dev/null
+// PR c++/113582
+// { dg-do compile { target c++17 } }
+// { dg-options "-Wunused-label" }
+
+template<bool B> void
+do_something ()
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-label"
+start:
+ if constexpr(B)
+ goto start;
+#pragma GCC diagnostic pop
+}
+
+template<bool B> void
+do_something2 ()
+{
+start: // { dg-warning "defined but not used" }
+ if constexpr(B)
+ goto start;
+}
+
+void
+g ()
+{
+ do_something<0>();
+ do_something2<0>();
+}