Skip to content

Commit 0446268

Browse files
tbaederrsivan-shani
authored andcommitted
[clang][bytecode] Fix rejecting non-constexpr array ctors (llvm#127448)
We shouldn't abort here when compiling, this is happening (and properly diagnosed) when interpreting the bytecode.
1 parent 49b20a2 commit 0446268

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3029,7 +3029,7 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
30293029

30303030
size_t NumElems = CAT->getZExtSize();
30313031
const Function *Func = getFunction(E->getConstructor());
3032-
if (!Func || !Func->isConstexpr())
3032+
if (!Func)
30333033
return false;
30343034

30353035
// FIXME(perf): We're calling the constructor once per array element here,

clang/test/AST/ByteCode/new-delete.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,6 @@ constexpr unsigned short ssmall = SS<unsigned short>(100)[42];
865865
constexpr auto Ss = SS<S>()[0];
866866

867867

868-
869868
namespace IncompleteArray {
870869
struct A {
871870
int b = 10;
@@ -908,8 +907,19 @@ namespace IncompleteArray {
908907
return c;
909908
}
910909
static_assert(test4() == 12);
910+
}
911911

912+
namespace NonConstexprArrayCtor {
913+
struct S {
914+
S() {} // both-note 2{{declared here}}
915+
};
912916

917+
constexpr bool test() { // both-error {{never produces a constant expression}}
918+
auto s = new S[1]; // both-note 2{{non-constexpr constructor}}
919+
return true;
920+
}
921+
static_assert(test()); // both-error {{not an integral constant expression}} \
922+
// both-note {{in call to}}
913923
}
914924

915925
#else

0 commit comments

Comments
 (0)