Skip to content

Commit 0d9decc

Browse files
committed
[clang][Interp] Handle invalid CXXCtorInitializer expressions
Their type might be a null type, in which case we need to abort here.
1 parent bc6955f commit 0d9decc

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ bool ByteCodeStmtGen<Emitter>::visitFunc(const FunctionDecl *F) {
144144

145145
auto emitFieldInitializer = [&](const Record::Field *F, unsigned FieldOffset,
146146
const Expr *InitExpr) -> bool {
147+
// We don't know what to do with these, so just return false.
148+
if (InitExpr->getType().isNull())
149+
return false;
150+
147151
if (std::optional<PrimType> T = this->classify(InitExpr)) {
148152
if (!this->visit(InitExpr))
149153
return false;

clang/test/AST/Interp/records.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,3 +1228,14 @@ namespace InheritedConstructor {
12281228
constexpr S s(1);
12291229
}
12301230
}
1231+
1232+
namespace InvalidCtorInitializer {
1233+
struct X {
1234+
int Y;
1235+
constexpr X() // expected-note {{declared here}}
1236+
: Y(fo_o_()) {} // both-error {{use of undeclared identifier 'fo_o_'}}
1237+
};
1238+
// no crash on evaluating the constexpr ctor.
1239+
constexpr int Z = X().Y; // both-error {{constexpr variable 'Z' must be initialized by a constant expression}} \
1240+
// expected-note {{undefined constructor 'X'}}
1241+
}

0 commit comments

Comments
 (0)