From: Daniel Dunbar Date: Wed, 19 May 2010 21:07:14 +0000 (+0000) Subject: Revert r104117, "Provide a naming class for UnresolvedLookupExprs, even when X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf1cbaf1b0ac9d967ff6abf27788cc98f0f5e7da;p=clang Revert r104117, "Provide a naming class for UnresolvedLookupExprs, even when occuring on..." which breaks some Objective-C code. Working on getting a test case... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104150 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 94aa6b09fe..5e1f21b4c3 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -1077,12 +1077,17 @@ Sema::OwningExprResult Sema::ActOnIdExpression(Scope *S, // Perform the required lookup. LookupResult R(*this, Name, NameLoc, LookupOrdinaryName); if (TemplateArgs) { - // Lookup the template name again to correctly establish the context in - // which it was found. This is really unfortunate as we already did the - // lookup to determine that it was a template name in the first place. If - // this becomes a performance hit, we can work harder to preserve those - // results until we get here but it's likely not worth it. - LookupTemplateName(R, S, SS, QualType(), /*EnteringContext=*/false); + // Just re-use the lookup done by isTemplateName. + DecomposeTemplateName(R, Id); + + // Re-derive the naming class. + if (SS.isSet()) { + NestedNameSpecifier *Qualifier + = static_cast(SS.getScopeRep()); + if (const Type *Ty = Qualifier->getAsType()) + if (CXXRecordDecl *NamingClass = Ty->getAsCXXRecordDecl()) + R.setNamingClass(NamingClass); + } } else { bool IvarLookupFollowUp = (!SS.isSet() && II && getCurMethodDecl()); LookupParsedName(R, S, &SS, !IvarLookupFollowUp); diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index b25ecb1e06..774a82b7c7 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -665,8 +665,6 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) { // DeclContext *OutsideOfTemplateParamDC = 0; for (; S && !isNamespaceOrTranslationUnitScope(S); S = S->getParent()) { - DeclContext *Ctx = static_cast(S->getEntity()); - // Check whether the IdResolver has anything in this scope. bool Found = false; for (; I != IEnd && S->isDeclScope(DeclPtrTy::make(*I)); ++I) { @@ -677,11 +675,10 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) { } if (Found) { R.resolveKind(); - if (S->isClassScope()) - R.setNamingClass(dyn_cast(Ctx)); return true; } + DeclContext *Ctx = static_cast(S->getEntity()); if (!Ctx && S->isTemplateParamScope() && OutsideOfTemplateParamDC && S->getParent() && !S->getParent()->isTemplateParamScope()) { // We've just searched the last template parameter scope and diff --git a/test/CXX/temp/temp.names/p2.cpp b/test/CXX/temp/temp.names/p2.cpp deleted file mode 100644 index 8666b61a4e..0000000000 --- a/test/CXX/temp/temp.names/p2.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s - -// Ensure that when enforcing access control an unqualified template name with -// explicit template arguments, we don't loose the context of the name lookup -// because of the required early lookup to determine if it names a template. -namespace PR7163 { - template void h(R (*func)(P)) {} - class C { - template static void g(T*) {}; - public: - void f() { h(g); } - }; -}