From 60f2e1efb821259de7ae32d9c1ff5a5cbe2aa849 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 25 Sep 2012 00:23:05 +0000 Subject: [PATCH] Don't produce diagnostics for missing ctor-initializers during template instantiations if we encountered errors parsing some of the initializers. llvm-svn: 164578 --- clang/lib/Sema/SemaDeclCXX.cpp | 6 +++++- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +- .../class-template-ctor-initializer.cpp | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 03cec4ca8642..a4ddba3740d6 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2965,7 +2965,11 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, NumInitializers * sizeof(CXXCtorInitializer*)); Constructor->setCtorInitializers(baseOrMemberInitializers); } - + + // Let template instantiation know whether we had errors. + if (AnyErrors) + Constructor->setInvalidDecl(); + return false; } diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 8c1722fdedbc..d1c30bdf0c87 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2986,7 +2986,7 @@ Sema::InstantiateMemInitializers(CXXConstructorDecl *New, const MultiLevelTemplateArgumentList &TemplateArgs) { SmallVector NewInits; - bool AnyErrors = false; + bool AnyErrors = Tmpl->isInvalidDecl(); // Instantiate all the initializers. for (CXXConstructorDecl::init_const_iterator Inits = Tmpl->init_begin(), diff --git a/clang/test/SemaTemplate/class-template-ctor-initializer.cpp b/clang/test/SemaTemplate/class-template-ctor-initializer.cpp index 44bb4bda791e..6043327b7bab 100644 --- a/clang/test/SemaTemplate/class-template-ctor-initializer.cpp +++ b/clang/test/SemaTemplate/class-template-ctor-initializer.cpp @@ -53,3 +53,20 @@ namespace PR7259 { return 0; } } + +namespace NonDependentError { + struct Base { Base(int); }; // expected-note 2{{candidate}} + + template + struct Derived1 : Base { + Derived1() : Base(1, 2) {} // expected-error {{no matching constructor}} + }; + + template + struct Derived2 : Base { + Derived2() : BaseClass(1) {} // expected-error {{does not name a non-static data member or base}} + }; + + Derived1 d1; + Derived2 d2; +}