[clang] [Clang][ExprConst] Accept prvalue for nothrow new (PR #226753)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 27 09:15:11 PDT 2026


================
@@ -11030,8 +11030,11 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const CXXNewExpr *E) {
     // (which should presumably be valid only if N is a multiple of
     // alignof(int), and in any case can't be deallocated unless N is
     // alignof(X) and X has new-extended alignment).
-    LValue Nothrow;
-    if (!EvaluateLValue(E->getPlacementArg(0), Nothrow, Info))
+    //
+    // The argument is usually an lvalue (the standard signature takes a
+    // 'const std::nothrow_t &'), but a user-declared allocation function may
+    // take 'std::nothrow_t' by value, in which case it is a prvalue.
+    if (!EvaluateIgnoredValue(Info, E->getPlacementArg(0)))
----------------
efriedma-quic wrote:

[expr.const] defines two cases where a new expression can be cosntant-evaluated.  Both of those cases involve particular signatures for operator new.  None of the allowed signatures take an std::nothrow_t by value.  So we shouldn't be trying to evaluate this.

We probably need to rearrange the checks here.

https://github.com/llvm/llvm-project/pull/226753


More information about the cfe-commits mailing list