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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 27 10:47:57 PDT 2026


================
@@ -2935,6 +2935,16 @@ bool InvalidNewDeleteExpr(InterpState &S, CodePtr OpPC, const Expr *E) {
     const FunctionDecl *OperatorNew = NewExpr->getOperatorNew();
 
     if (NewExpr->getNumPlacementArgs() > 0) {
+      if (NewExpr->getNumPlacementArgs() == 1 &&
+          NewExpr->getPlacementArg(0)->getType()->isNothrowT() &&
+          !OperatorNew
+               ->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
+        S.FFDiag(S.Current->getSource(OpPC),
+                 diag::note_constexpr_new_non_replaceable)
+            << isa<CXXMethodDecl>(OperatorNew) << OperatorNew;
+        return false;
+      }
+
       // This is allowed pre-C++26, but only an std function or if
       // [[msvc::constexpr]] was used.
----------------
efriedma-quic wrote:

This is really hard to follow.

Can we split the isStdFunction()/MSVCConstexprAllowed case into it's own opcode, then make InvalidNewDeleteExpr emit an error unconditionally?

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


More information about the cfe-commits mailing list