@@ -1564,34 +1564,38 @@ bool CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, const Expr *E,
15641564bool InvalidNewDeleteExpr (InterpState &S, CodePtr OpPC, const Expr *E) {
15651565 assert (E);
15661566
1567- if (S.getLangOpts ().CPlusPlus26 )
1568- return true ;
1569-
1570- const auto &Loc = S.Current ->getSource (OpPC);
1571-
15721567 if (const auto *NewExpr = dyn_cast<CXXNewExpr>(E)) {
15731568 const FunctionDecl *OperatorNew = NewExpr->getOperatorNew ();
15741569
1575- if (!S. getLangOpts (). CPlusPlus26 && NewExpr->getNumPlacementArgs () > 0 ) {
1570+ if (NewExpr->getNumPlacementArgs () > 0 ) {
15761571 // This is allowed pre-C++26, but only an std function.
1577- if (S.Current ->isStdFunction ())
1572+ if (S.getLangOpts (). CPlusPlus26 || S. Current ->isStdFunction ())
15781573 return true ;
1579- S.FFDiag (Loc , diag::note_constexpr_new_placement)
1574+ S.FFDiag (S. Current -> getSource (OpPC) , diag::note_constexpr_new_placement)
15801575 << /* C++26 feature*/ 1 << E->getSourceRange ();
1581- } else if (NewExpr->getNumPlacementArgs () == 1 &&
1582- !OperatorNew->isReservedGlobalPlacementOperator ()) {
1583- S.FFDiag (Loc, diag::note_constexpr_new_placement)
1584- << /* Unsupported*/ 0 << E->getSourceRange ();
15851576 } else if (!OperatorNew->isReplaceableGlobalAllocationFunction ()) {
1586- S.FFDiag (Loc, diag::note_constexpr_new_non_replaceable)
1577+ S.FFDiag (S.Current ->getSource (OpPC),
1578+ diag::note_constexpr_new_non_replaceable)
15871579 << isa<CXXMethodDecl>(OperatorNew) << OperatorNew;
1580+ return false ;
1581+ } else if (!S.getLangOpts ().CPlusPlus26 &&
1582+ NewExpr->getNumPlacementArgs () == 1 &&
1583+ !OperatorNew->isReservedGlobalPlacementOperator ()) {
1584+ if (!S.getLangOpts ().CPlusPlus26 ) {
1585+ S.FFDiag (S.Current ->getSource (OpPC), diag::note_constexpr_new_placement)
1586+ << /* Unsupported*/ 0 << E->getSourceRange ();
1587+ return false ;
1588+ }
1589+ return true ;
15881590 }
15891591 } else {
15901592 const auto *DeleteExpr = cast<CXXDeleteExpr>(E);
15911593 const FunctionDecl *OperatorDelete = DeleteExpr->getOperatorDelete ();
15921594 if (!OperatorDelete->isReplaceableGlobalAllocationFunction ()) {
1593- S.FFDiag (Loc, diag::note_constexpr_new_non_replaceable)
1595+ S.FFDiag (S.Current ->getSource (OpPC),
1596+ diag::note_constexpr_new_non_replaceable)
15941597 << isa<CXXMethodDecl>(OperatorDelete) << OperatorDelete;
1598+ return false ;
15951599 }
15961600 }
15971601
0 commit comments