[cfe-commits] r142652 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaTemplate/class-template-decl.cpp test/SemaTemplate/member-access-ambig.cpp
Douglas Gregor
dgregor at apple.com
Fri Oct 21 08:47:52 PDT 2011
Author: dgregor
Date: Fri Oct 21 10:47:52 2011
New Revision: 142652
URL: http://llvm.org/viewvc/llvm-project?rev=142652&view=rev
Log:
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 / <rdar://problem/10290422>.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaTemplate/class-template-decl.cpp
cfe/trunk/test/SemaTemplate/member-access-ambig.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=142652&r1=142651&r2=142652&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Oct 21 10:47:52 2011
@@ -8421,16 +8421,25 @@
<< 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<NamedDecl>();
+ switch (Previous.getResultKind()) {
+ case LookupResult::Found:
+ case LookupResult::FoundUnresolvedValue:
+ PrevDecl = Previous.getAsSingle<NamedDecl>();
+ 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.
Modified: cfe/trunk/test/SemaTemplate/class-template-decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/class-template-decl.cpp?rev=142652&r1=142651&r2=142652&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/class-template-decl.cpp (original)
+++ cfe/trunk/test/SemaTemplate/class-template-decl.cpp Fri Oct 21 10:47:52 2011
@@ -74,3 +74,4 @@
Foo<int>::Bar<int> y(x);
}
}
+
Modified: cfe/trunk/test/SemaTemplate/member-access-ambig.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/member-access-ambig.cpp?rev=142652&r1=142651&r2=142652&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/member-access-ambig.cpp (original)
+++ cfe/trunk/test/SemaTemplate/member-access-ambig.cpp Fri Oct 21 10:47:52 2011
@@ -33,3 +33,13 @@
// expected-error{{expected '(' for function-style cast}} \
// expected-error{{expected expression}}
}
+
+namespace PR11134 {
+ template<typename Derived> class A;
+ template<typename Derived> class B : A<Derived> {
+ typedef A<Derived> Base;
+ using Base::member;
+ int member;
+ };
+}
+
More information about the cfe-commits
mailing list