From: Douglas Gregor Date: Fri, 21 Oct 2011 15:47:52 +0000 (+0000) Subject: When performing name lookup for the previous declaration of a field, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=95e5510ee07c465abdcc458fabfd93cf09d90125;p=clang When performing name lookup for the previous declaration of a field, be sure to consider all of the possible lookup results. We were assert()'ing (but behaving correctly) for unresolved values. Fixes PR11134 / . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142652 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c7873fa068..f554cffba9 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8421,16 +8421,25 @@ FieldDecl *Sema::HandleField(Scope *S, RecordDecl *Record, << 2; // Check to see if this name was declared as a member previously + NamedDecl *PrevDecl = 0; LookupResult Previous(*this, II, Loc, LookupMemberName, ForRedeclaration); LookupName(Previous, S); - assert((Previous.empty() || Previous.isOverloadedResult() || - Previous.isSingleResult()) - && "Lookup of member name should be either overloaded, single or null"); - - // If the name is overloaded then get any declaration else get the single - // result - NamedDecl *PrevDecl = Previous.isOverloadedResult() ? - Previous.getRepresentativeDecl() : Previous.getAsSingle(); + switch (Previous.getResultKind()) { + case LookupResult::Found: + case LookupResult::FoundUnresolvedValue: + PrevDecl = Previous.getAsSingle(); + break; + + case LookupResult::FoundOverloaded: + PrevDecl = Previous.getRepresentativeDecl(); + break; + + case LookupResult::NotFound: + case LookupResult::NotFoundInCurrentInstantiation: + case LookupResult::Ambiguous: + break; + } + Previous.suppressDiagnostics(); if (PrevDecl && PrevDecl->isTemplateParameter()) { // Maybe we will complain about the shadowed template parameter. diff --git a/test/SemaTemplate/class-template-decl.cpp b/test/SemaTemplate/class-template-decl.cpp index 2e84e93ead..38b1778abf 100644 --- a/test/SemaTemplate/class-template-decl.cpp +++ b/test/SemaTemplate/class-template-decl.cpp @@ -74,3 +74,4 @@ namespace PR8001 { Foo::Bar y(x); } } + diff --git a/test/SemaTemplate/member-access-ambig.cpp b/test/SemaTemplate/member-access-ambig.cpp index bf190435ec..f8a01d5fff 100644 --- a/test/SemaTemplate/member-access-ambig.cpp +++ b/test/SemaTemplate/member-access-ambig.cpp @@ -33,3 +33,13 @@ void X::g() // expected-error{{expected '(' for function-style cast}} \ // expected-error{{expected expression}} } + +namespace PR11134 { + template class A; + template class B : A { + typedef A Base; + using Base::member; + int member; + }; +} +