[clang] 155f6b4 - [clang][Interp] Fix reporting invalid new/delete expressions

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 20 01:41:26 PDT 2024


Author: Timm Bäder
Date: 2024-07-20T10:41:12+02:00
New Revision: 155f6b49d90357d4062aa97f035f42617565ee26

URL: https://github.com/llvm/llvm-project/commit/155f6b49d90357d4062aa97f035f42617565ee26
DIFF: https://github.com/llvm/llvm-project/commit/155f6b49d90357d4062aa97f035f42617565ee26.diff

LOG: [clang][Interp] Fix reporting invalid new/delete expressions

This should be a CCEDiag call and we do *not* abort because of it.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.cpp
    clang/test/AST/Interp/new-delete.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index cd6fc60400ebd..6fcd90e5f5849 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -728,8 +728,8 @@ bool CheckDynamicMemoryAllocation(InterpState &S, CodePtr OpPC) {
     return true;
 
   const SourceInfo &E = S.Current->getSource(OpPC);
-  S.FFDiag(E, diag::note_constexpr_new);
-  return false;
+  S.CCEDiag(E, diag::note_constexpr_new);
+  return true;
 }
 
 bool CheckNewDeleteForms(InterpState &S, CodePtr OpPC, bool NewWasArray,

diff  --git a/clang/test/AST/Interp/new-delete.cpp b/clang/test/AST/Interp/new-delete.cpp
index cb46426c0e3be..7a85def784920 100644
--- a/clang/test/AST/Interp/new-delete.cpp
+++ b/clang/test/AST/Interp/new-delete.cpp
@@ -560,4 +560,9 @@ constexpr int a() { // both-error {{never produces a constant expression}}
 }
 static_assert(a() == 1, ""); // both-error {{not an integral constant expression}} \
                              // both-note {{in call to 'a()'}}
+
+
+static_assert(true ? *new int : 4, ""); // both-error {{expression is not an integral constant expression}} \
+                                        // both-note {{read of uninitialized object is not allowed in a constant expression}}
+
 #endif


        


More information about the cfe-commits mailing list