Skip to content

Commit de9b3c5

Browse files
authored
[clang][Interp] Handle delegating constructors (#67823)
1 parent d430015 commit de9b3c5

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
@@ -198,6 +198,14 @@ bool ByteCodeStmtGen<Emitter>::visitFunc(const FunctionDecl *F) {
198198
return false;
199199
if (!this->emitInitPtrPop(InitExpr))
200200
return false;
201+
} else {
202+
assert(Init->isDelegatingInitializer());
203+
if (!this->emitThis(InitExpr))
204+
return false;
205+
if (!this->visitInitializer(Init->getInit()))
206+
return false;
207+
if (!this->emitPopPtr(InitExpr))
208+
return false;
201209
}
202210
}
203211
}

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)