diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp index 6193a8d55a146..509abe3ae867f 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp @@ -198,6 +198,14 @@ bool ByteCodeStmtGen::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; } } } diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp index bcc84087fc540..3c866825d1f07 100644 --- a/clang/test/AST/Interp/records.cpp +++ b/clang/test/AST/Interp/records.cpp @@ -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, ""); +}