diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 4a5444e0258..4e94113168b 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -8109,7 +8109,10 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, tree oldop = TREE_OPERAND (t, 0); tree op = cxx_eval_constant_expression (ctx, oldop, - lval, + VOID_TYPE_P (TREE_TYPE (t)) + ? vc_discard + : tcode == VIEW_CONVERT_EXPR + ? lval : vc_prvalue, non_constant_p, overflow_p); if (*non_constant_p) return t; diff --git a/gcc/testsuite/g++.dg/cpp26/pr115754.C b/gcc/testsuite/g++.dg/cpp26/pr115754.C new file mode 100644 index 00000000000..45a8efcd9a2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/pr115754.C @@ -0,0 +1,36 @@ +// PR c++/115754 +// { dg-do compile { target c++26 } } + +namespace std +{ + using size_t = decltype (sizeof 0); + + template + struct allocator + { + constexpr allocator () noexcept {} + + constexpr T *allocate (size_t n) + { return static_cast (::operator new (n * sizeof(T))); } + + constexpr void + deallocate (T *p, size_t n) + { ::operator delete (p); } + }; +} + +constexpr void * +operator new (std::size_t, void *p) noexcept +{ return p; } + +constexpr bool +foo () +{ + std::allocator a; + auto b = a.allocate (1); + ::new (b) int (); + a.deallocate (b, 1); + return true; +} + +constexpr bool a = foo ();