+2017-12-04 Jason Merrill <jason@redhat.com>
+
+ PR c++/83273 - constexpr if allows non-constant condition
+ * semantics.c (finish_if_stmt_cond): Use require_constant_expression
+ rather than is_constant_expression.
+ * constexpr.c (potential_constant_expression_1) [LAMBDA_EXPR]: Allow
+ in C++17.
+
2017-12-01 Jason Merrill <jason@redhat.com>
Give #include hints for <complex>.
return RECUR (STMT_EXPR_STMT (t), rval);
case LAMBDA_EXPR:
+ if (cxx_dialect >= cxx17)
+ /* In C++17 lambdas can be constexpr, don't give up yet. */
+ return true;
+ else if (flags & tf_error)
+ error_at (loc, "lambda-expression is not a constant expression "
+ "before C++17");
+ return false;
+
case DYNAMIC_CAST_EXPR:
case PSEUDO_DTOR_EXPR:
case NEW_EXPR:
{
cond = maybe_convert_cond (cond);
if (IF_STMT_CONSTEXPR_P (if_stmt)
- && is_constant_expression (cond)
+ && require_constant_expression (cond)
&& !value_dependent_expression_p (cond))
{
cond = instantiate_non_dependent_expr (cond);
template <class MustBeTemplate>
constexpr auto bf(T t) {
- if constexpr(t.foo()) {
+ if constexpr(t.foo()) { // { dg-error "constant expression" }
return false;
}
return true;
--- /dev/null
+// PR c++/83273
+// { dg-options -std=c++17 }
+
+int main()
+{
+ auto d = 42;
+ if constexpr (d > 0) { // { dg-error "constant expression" }
+ return d;
+ }
+}