Skip to content

Commit 5e37e30

Browse files
committed
[clang][Interp] Handle delegating constructors
1 parent cc69662 commit 5e37e30

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ bool ByteCodeStmtGen<Emitter>::visitFunc(const FunctionDecl *F) {
193193
return false;
194194
if (!this->emitPopPtr(InitExpr))
195195
return false;
196+
} else {
197+
assert(Init->isDelegatingInitializer());
198+
if (!this->emitThis(InitExpr))
199+
return false;
200+
if (!this->visitInitializer(Init->getInit()))
201+
return false;
202+
if (!this->emitPopPtr(InitExpr))
203+
return false;
196204
}
197205
}
198206
}

clang/test/AST/Interp/records.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,3 +1066,26 @@ namespace ParenInit {
10661066
constexpr B b(A(1),2);
10671067
}
10681068
#endif
1069+
1070+
namespace DelegatingConstructors {
1071+
struct S {
1072+
int a;
1073+
constexpr S() : S(10) {}
1074+
constexpr S(int a) : a(a) {}
1075+
};
1076+
constexpr S s = {};
1077+
static_assert(s.a == 10, "");
1078+
1079+
struct B {
1080+
int a;
1081+
int b;
1082+
1083+
constexpr B(int a) : a(a), b(a + 2) {}
1084+
};
1085+
struct A : B {
1086+
constexpr A() : B(10) {};
1087+
};
1088+
constexpr A d4 = {};
1089+
static_assert(d4.a == 10, "");
1090+
static_assert(d4.b == 12, "");
1091+
}

0 commit comments

Comments
 (0)