From d6068482648a366ac9fc297a84780e922ab63a7a Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 26 Mar 2010 22:43:07 +0000 Subject: [PATCH] When adding initializers to a constructor, be sure that we are looking through the bases and fields of the definition of the class in which the constructor is declared, rather than some other declaration of that class. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99661 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 6 +++++- test/CodeGenCXX/constructor-init.cpp | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 1f6630e343..1b4710e3d0 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1433,7 +1433,11 @@ Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor, bool AnyErrors) { // We need to build the initializer AST according to order of construction // and not what user specified in the Initializers list. - CXXRecordDecl *ClassDecl = cast(Constructor->getDeclContext()); + CXXRecordDecl *ClassDecl + = cast(Constructor->getDeclContext())->getDefinition(); + if (!ClassDecl) + return true; + llvm::SmallVector AllToInit; llvm::DenseMap AllBaseFields; bool HasDependentBaseInit = false; diff --git a/test/CodeGenCXX/constructor-init.cpp b/test/CodeGenCXX/constructor-init.cpp index a0a35fa16f..284b8b5938 100644 --- a/test/CodeGenCXX/constructor-init.cpp +++ b/test/CodeGenCXX/constructor-init.cpp @@ -80,3 +80,24 @@ void f() { // CHECK-NOT: call void @_ZN1AIsED1Ev // CHECK: ret void } + +template +struct X { + X(const X &); + + T *start; + T *end; +}; + +template struct X; + +// Make sure that the instantiated constructor initializes start and +// end properly. +// CHECK: define linkonce_odr void @_ZN1XIiEC2ERKS0_ +// CHECK: {{store.*null}} +// CHECK: {{store.*null}} +// CHECK: ret +template +X::X(const X &other) : start(0), end(0) { } + +X get_X(X x) { return x; } -- 2.40.0