Skip to content

Commit

Permalink
[clang][Interp] Handle CXXDefaultInitExpr of composite type
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Mar 18, 2024
1 parent 6598f63 commit c2f75c7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
6 changes: 1 addition & 5 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2916,11 +2916,7 @@ template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitCXXDefaultInitExpr(
const CXXDefaultInitExpr *E) {
SourceLocScope<Emitter> SLS(this, E);
if (Initializing)
return this->visitInitializer(E->getExpr());

assert(classify(E->getType()));
return this->visit(E->getExpr());
return this->delegate(E->getExpr());
}

template <class Emitter>
Expand Down
21 changes: 21 additions & 0 deletions clang/test/AST/Interp/records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,3 +1264,24 @@ namespace {
static_assert(true_type::value, "");
static_assert(true_type::value, "");
}

#if __cplusplus >= 202002L
namespace {
/// Used to crash because the CXXDefaultInitExpr is of compound type.
struct A {
int &x;
constexpr ~A() { --x; }
};
struct B {
int &x;
const A &a = A{x};
};
constexpr int a() {
int x = 1;
int f = B{x}.x;
B{x}; // both-warning {{expression result unused}}

return 1;
}
}
#endif

0 comments on commit c2f75c7

Please sign in to comment.