Skip to content

Commit

Permalink
[clang][Interp] Handle delegating constructors (#67823)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Oct 16, 2023
1 parent d430015 commit de9b3c5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clang/lib/AST/Interp/ByteCodeStmtGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ bool ByteCodeStmtGen<Emitter>::visitFunc(const FunctionDecl *F) {
return false;
if (!this->emitInitPtrPop(InitExpr))
return false;
} else {
assert(Init->isDelegatingInitializer());
if (!this->emitThis(InitExpr))
return false;
if (!this->visitInitializer(Init->getInit()))
return false;
if (!this->emitPopPtr(InitExpr))
return false;
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions clang/test/AST/Interp/records.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,3 +1066,26 @@ namespace ParenInit {
constexpr B b(A(1),2);
}
#endif

namespace DelegatingConstructors {
struct S {
int a;
constexpr S() : S(10) {}
constexpr S(int a) : a(a) {}
};
constexpr S s = {};
static_assert(s.a == 10, "");

struct B {
int a;
int b;

constexpr B(int a) : a(a), b(a + 2) {}
};
struct A : B {
constexpr A() : B(10) {};
};
constexpr A d4 = {};
static_assert(d4.a == 10, "");
static_assert(d4.b == 12, "");
}

0 comments on commit de9b3c5

Please sign in to comment.