Skip to content

Commit c2f75c7

Browse files
committed
[clang][Interp] Handle CXXDefaultInitExpr of composite type
1 parent 6598f63 commit c2f75c7

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,11 +2916,7 @@ template <class Emitter>
29162916
bool ByteCodeExprGen<Emitter>::VisitCXXDefaultInitExpr(
29172917
const CXXDefaultInitExpr *E) {
29182918
SourceLocScope<Emitter> SLS(this, E);
2919-
if (Initializing)
2920-
return this->visitInitializer(E->getExpr());
2921-
2922-
assert(classify(E->getType()));
2923-
return this->visit(E->getExpr());
2919+
return this->delegate(E->getExpr());
29242920
}
29252921

29262922
template <class Emitter>

clang/test/AST/Interp/records.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,3 +1264,24 @@ namespace {
12641264
static_assert(true_type::value, "");
12651265
static_assert(true_type::value, "");
12661266
}
1267+
1268+
#if __cplusplus >= 202002L
1269+
namespace {
1270+
/// Used to crash because the CXXDefaultInitExpr is of compound type.
1271+
struct A {
1272+
int &x;
1273+
constexpr ~A() { --x; }
1274+
};
1275+
struct B {
1276+
int &x;
1277+
const A &a = A{x};
1278+
};
1279+
constexpr int a() {
1280+
int x = 1;
1281+
int f = B{x}.x;
1282+
B{x}; // both-warning {{expression result unused}}
1283+
1284+
return 1;
1285+
}
1286+
}
1287+
#endif

0 commit comments

Comments
 (0)