[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 06:19:08 PDT 2025


================
@@ -0,0 +1,15 @@
+// RUN: not %clang_cc1 -std=c++20 -fsyntax-only %s 2>&1 \
+// RUN:   | FileCheck %s --implicit-check-not='Assertion `NumElements.isPositive()` failed'
+
+// In C++20, constexpr dynamic allocation is permitted *only* if valid.
+// A negative element count must be diagnosed (and must not crash).
+
+constexpr void f_bad_neg() {
+  int a = -1;
+  (void) new int[a]; // triggers negative-size path in the interpreter
+}
----------------
snarang181 wrote:

Added

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


More information about the cfe-commits mailing list