[clang] [clang][bytecode] Handle negative array sizes in constexpr `new` instead of asserting (PR #155737)

Samarth Narang via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 28 08:04:43 PDT 2025


================
@@ -1069,6 +1069,32 @@ namespace BaseCompare {
   static_assert(foo());
 }
 
+
+namespace NegativeArraySize {
+
+constexpr void f() {
+  int x = -1;
+  int *p = new int[x]; // expected-note {{cannot allocate array with negative size in a constant expression}}
+}
+// both-error at -4 {{constexpr function never produces a constant expression}}
----------------
snarang181 wrote:

Yes, it shows up when the function is called. 

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


More information about the cfe-commits mailing list