Skip to content

Commit

Permalink
[clang][Interp] Fix record initialization via CallExpr subclasses
Browse files Browse the repository at this point in the history
We can't just use VisitCallExpr() here, as that doesn't handle CallExpr
subclasses such as CXXMemberCallExpr.

Differential Revision: https://reviews.llvm.org/D141772
  • Loading branch information
tbaederr committed Mar 31, 2023
1 parent 6231ba0 commit cef69ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ bool ByteCodeExprGen<Emitter>::visitRecordInitializer(const Expr *Initializer) {
if (!this->emitDupPtr(Initializer))
return false;

return this->VisitCallExpr(CE);
return this->visit(CE);
} else if (const auto *DIE = dyn_cast<CXXDefaultInitExpr>(Initializer)) {
return this->visitInitializer(DIE->getExpr());
} else if (const auto *CE = dyn_cast<CastExpr>(Initializer)) {
Expand Down
8 changes: 8 additions & 0 deletions clang/test/AST/Interp/records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@ class C {
int b;

constexpr C() : a(100), b(200) {}

constexpr C get() const {
return *this;
}
};

constexpr C c;
static_assert(c.a == 100, "");
static_assert(c.b == 200, "");

constexpr C c2 = C().get();
static_assert(c.a == 100, "");
static_assert(c.b == 200, "");

constexpr int getB() {
C c;
int &j = c.b;
Expand Down

0 comments on commit cef69ce

Please sign in to comment.