From fbf8752597c978015af80ab4e948af1f80d63dd6 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 21 Oct 2011 15:47:52 +0000 Subject: [PATCH] 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 / . llvm-svn: 142652 --- clang/lib/Sema/SemaDecl.cpp | 25 +++++++++++++------ .../test/SemaTemplate/class-template-decl.cpp | 1 + .../test/SemaTemplate/member-access-ambig.cpp | 10 ++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index c7873fa06820..f554cffba9ba 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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/clang/test/SemaTemplate/class-template-decl.cpp b/clang/test/SemaTemplate/class-template-decl.cpp index 2e84e93ead97..38b1778abf44 100644 --- a/clang/test/SemaTemplate/class-template-decl.cpp +++ b/clang/test/SemaTemplate/class-template-decl.cpp @@ -74,3 +74,4 @@ namespace PR8001 { Foo::Bar y(x); } } + diff --git a/clang/test/SemaTemplate/member-access-ambig.cpp b/clang/test/SemaTemplate/member-access-ambig.cpp index bf190435ecd5..f8a01d5fff2a 100644 --- a/clang/test/SemaTemplate/member-access-ambig.cpp +++ b/clang/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; + }; +} +