[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 11:12:01 PDT 2025
================
@@ -1070,14 +1070,13 @@ namespace BaseCompare {
}
-namespace NegativeArraySize {
+namespace NegativeArraySize {
-constexpr void f() {
+constexpr void f() { // both-error {{constexpr function never produces a constant expression}}
int x = -1;
- int *p = new int[x]; // expected-note {{cannot allocate array with negative size in a constant expression}}
+ int *p = new int[x]; // expected-note {{cannot allocate array with negative size in a constant expression}} \
+ // ref-note {{cannot allocate array; evaluated array bound -1 is negative}}
----------------
snarang181 wrote:
I changed the Bytecode interpreter to reuse the same diagnostic now; I had created a new one earlier. There's coherent output between both the interpreters now.
https://github.com/llvm/llvm-project/pull/155737
More information about the cfe-commits
mailing list