From: Douglas Gregor Date: Wed, 4 Nov 2009 17:16:11 +0000 (+0000) Subject: Don't try to check the initialization of fields with dependent X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1fe6b919f70bed58bd8bd43de1a79530b0d55a53;p=clang Don't try to check the initialization of fields with dependent types. Fixes PR5352. Fariborz, please review. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86031 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 3314ee26cb..d1f9ad960f 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1293,11 +1293,16 @@ Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor, continue; } + if ((*Field)->getType()->isDependentType()) { + Fields.push_back(*Field); + continue; + } + QualType FT = Context.getBaseElementType((*Field)->getType()); if (const RecordType* RT = FT->getAs()) { CXXConstructorDecl *Ctor = cast(RT->getDecl())->getDefaultConstructor(Context); - if (!Ctor && !FT->isDependentType()) { + if (!Ctor) { Fields.push_back(*Field); continue; } @@ -1357,12 +1362,16 @@ Sema::BuildBaseOrMemberInitializers(ASTContext &C, SetBaseOrMemberInitializers(Constructor, Initializers, NumInitializers, Bases, Members); - for (unsigned int i = 0; i < Bases.size(); i++) - Diag(Bases[i]->getSourceRange().getBegin(), - diag::err_missing_default_constructor) << 0 << Bases[i]->getType(); - for (unsigned int i = 0; i < Members.size(); i++) - Diag(Members[i]->getLocation(), diag::err_missing_default_constructor) - << 1 << Members[i]->getType(); + for (unsigned int i = 0; i < Bases.size(); i++) { + if (!Bases[i]->getType()->isDependentType()) + Diag(Bases[i]->getSourceRange().getBegin(), + diag::err_missing_default_constructor) << 0 << Bases[i]->getType(); + } + for (unsigned int i = 0; i < Members.size(); i++) { + if (!Members[i]->getType()->isDependentType()) + Diag(Members[i]->getLocation(), diag::err_missing_default_constructor) + << 1 << Members[i]->getType(); + } } static void *GetKeyForTopLevelField(FieldDecl *Field) { diff --git a/test/SemaTemplate/instantiate-deeply.cpp b/test/SemaTemplate/instantiate-deeply.cpp index 27e430be5c..7f15bf1200 100644 --- a/test/SemaTemplate/instantiate-deeply.cpp +++ b/test/SemaTemplate/instantiate-deeply.cpp @@ -1,5 +1,4 @@ // RUN: clang-cc -fsyntax-only -Wall -verify %s - template struct A { template struct B { template struct C { @@ -20,3 +19,18 @@ template struct A { }; A::B::C::D::E global; + +// PR5352 +template +class Foo { +public: + Foo() {} + + struct Bar { + T value; + }; + + Bar u; +}; + +template class Foo;