On Thu, Jun 02, 2022 at 03:42:15PM -0400, Jason Merrill wrote:
> On 6/2/22 10:03, Marek Polacek wrote:
> > On Thu, Jun 02, 2022 at 08:42:36AM -0400, Patrick Palka wrote:
> > > On Wed, 1 Jun 2022, Marek Polacek via Gcc-patches wrote:
> > >
> > > > Here we ICE because value_dependent_expression_p gets a NEW_EXPR
> > > > whose operand is a type, and we go to the default case which just
> > > > calls v_d_e_p on each operand of the NEW_EXPR. Since one of them
> > > > is a type, we crash on the new assert in t_d_e_p.
> > >
> > > Looks like NEW_EXPR is considered to be not potentially constant
> > > according to potential_constant_expression. I thought we shouldn't
> > > be calling value_dependent_expression_p on such exprs?
>
> Except in C++20 new-expressions are potentially constant, so the patch is
Thanks, pushed.
> OK, and we should adjust pce1 accordingly.
Is the attached patch OK then? So far dg.exp passed. Though it won't help
with...
> I notice we currently fail to handle
>
> struct A
> {
> int i;
> constexpr A(int *p): i(*p) { delete p; }
> };
>
> constexpr int i = A(new int(42)).i;
>
> though it does work inside a function.
...this test (it complains about a TARGET_EXPR's slot variable not being
declared constexpr), so I'm going to open a PR.
>From cf70354894bc31cc542ed8df40633bea2427fee7 Mon Sep 17 00:00:00 2001
From: Marek Polacek <[email protected]>
Date: Thu, 2 Jun 2022 15:56:18 -0400
Subject: [PATCH] c++: new-expression is potentially constant in C++20
... so adjust p_c_e accordingly.
gcc/cp/ChangeLog:
* constexpr.cc (potential_constant_expression_1): Treat
{,VEC_}NEW_EXPR as potentially constant in C++20.
---
gcc/cp/constexpr.cc | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc
index 1346a1d4c10..2bbd8785627 100644
--- a/gcc/cp/constexpr.cc
+++ b/gcc/cp/constexpr.cc
@@ -9039,10 +9039,18 @@ 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:
+ 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 DELETE_EXPR:
case VEC_DELETE_EXPR:
case THROW_EXPR:
base-commit: 7b98910406b5000a6429c188b0c6cc14e3140637
--
2.36.1