https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/127448
We shouldn't abort here when compiling, this is happening (and properly diagnosed) when interpreting the bytecode. >From 0fdf2160faa4ed9ccd2f36e8333575bf075e0755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Mon, 17 Feb 2025 07:16:33 +0100 Subject: [PATCH] [clang][bytecode] Fix rejecting non-constexpr array ctors We shouldn't abort here when compiling, this is happening (and properly diagnosed) when interpreting the bytecode. --- clang/lib/AST/ByteCode/Compiler.cpp | 2 +- clang/test/AST/ByteCode/new-delete.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index c8ace39d56fd0..59c236c9da8c8 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -3029,7 +3029,7 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) { size_t NumElems = CAT->getZExtSize(); const Function *Func = getFunction(E->getConstructor()); - if (!Func || !Func->isConstexpr()) + if (!Func) return false; // FIXME(perf): We're calling the constructor once per array element here, diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 31f066b37858d..e9850d27666e5 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -865,7 +865,6 @@ constexpr unsigned short ssmall = SS<unsigned short>(100)[42]; constexpr auto Ss = SS<S>()[0]; - namespace IncompleteArray { struct A { int b = 10; @@ -908,8 +907,19 @@ namespace IncompleteArray { return c; } static_assert(test4() == 12); +} +namespace NonConstexprArrayCtor { + struct S { + S() {} // both-note 2{{declared here}} + }; + constexpr bool test() { // both-error {{never produces a constant expression}} + auto s = new S[1]; // both-note 2{{non-constexpr constructor}} + return true; + } + static_assert(test()); // both-error {{not an integral constant expression}} \ + // both-note {{in call to}} } #else _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits