]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: new-expression is potentially constant in C++20
authorMarek Polacek <polacek@redhat.com>
Thu, 2 Jun 2022 19:56:18 +0000 (15:56 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 2 Jun 2022 20:28:40 +0000 (16:28 -0400)
... so adjust p_c_e accordingly.

gcc/cp/ChangeLog:

* constexpr.cc (potential_constant_expression_1): Treat
{,VEC_}NEW_EXPR and {,VEC_}DELETE_EXPRas potentially constant in C++20.

gcc/cp/constexpr.cc

index 1346a1d4c10ff29daf2ed6f62dcdd57560c936f8..684238883dc8891603f8ebea5e8c808f465cd026 100644 (file)
@@ -9039,12 +9039,20 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
                  "before C++17");
       return false;
 
-    case DYNAMIC_CAST_EXPR:
-    case PSEUDO_DTOR_EXPR:
     case NEW_EXPR:
     case VEC_NEW_EXPR:
     case DELETE_EXPR:
     case VEC_DELETE_EXPR:
+      if (cxx_dialect >= cxx20)
+       /* In C++20, new-expressions are potentially constant.  */
+       return true;
+      else if (flags & tf_error)
+       error_at (loc, "new-expression is not a constant expression "
+                 "before C++20");
+      return false;
+
+    case DYNAMIC_CAST_EXPR:
+    case PSEUDO_DTOR_EXPR:
     case THROW_EXPR:
     case OMP_PARALLEL:
     case OMP_TASK: