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

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 27 12:01:12 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.
----------------
aokblast wrote:

Ok. Now the check is inside Compiler.cpp now. In here we only emit error.

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


More information about the cfe-commits mailing list