[dcl.constexpr]/3 says that the function-body of a constexpr function
shall not contain an identifier label, but we aren't enforcing that.
This patch implements that. Of course, we can't reject artificial
labels.
gcc/cp/ChangeLog:
PR c++/97846
* constexpr.c (potential_constant_expression_1): Reject
LABEL_EXPRs that use non-artifical LABEL_DECLs.
gcc/testsuite/ChangeLog:
PR c++/97846
* g++.dg/cpp1y/constexpr-label.C: New test.
case OVERLOAD:
case TEMPLATE_ID_EXPR:
case LABEL_DECL:
- case LABEL_EXPR:
case CASE_LABEL_EXPR:
case PREDICT_EXPR:
case CONST_DECL:
return false;
}
+ case LABEL_EXPR:
+ t = LABEL_EXPR_LABEL (t);
+ if (DECL_ARTIFICIAL (t))
+ return true;
+ else if (flags & tf_error)
+ error_at (loc, "label definition is not a constant expression");
+ return false;
+
case ANNOTATE_EXPR:
return RECUR (TREE_OPERAND (t, 0), rval);
--- /dev/null
+// PR c++/97846
+// { dg-do compile { target c++14 } }
+
+constexpr int
+f ()
+{
+x: // { dg-error "label definition is not a constant expression" }
+ return 42;
+}