[cfe-commits] r104277 - in /cfe/trunk: lib/Sema/SemaExpr.cpp lib/Sema/SemaLookup.cpp test/CXX/temp/temp.names/p2.cpp test/SemaObjCXX/ivar-struct.mm

Douglas Gregor dgregor at apple.com
Thu May 20 13:58:57 PDT 2010


Author: dgregor
Date: Thu May 20 15:58:56 2010
New Revision: 104277

URL: http://llvm.org/viewvc/llvm-project?rev=104277&view=rev
Log:
Reinstate r104117, Chandler Carruth's change that "[provides] a naming
class for UnresolvedLookupExprs, even when occuring on template
names" along with a fix for an Objective-C++ crasher it introduced.

Added:
    cfe/trunk/test/CXX/temp/temp.names/p2.cpp
      - copied, changed from r104149, cfe/trunk/test/CXX/temp/temp.names/p2.cpp
    cfe/trunk/test/SemaObjCXX/ivar-struct.mm
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=104277&r1=104276&r2=104277&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu May 20 15:58:56 2010
@@ -1079,17 +1079,12 @@
   // Perform the required lookup.
   LookupResult R(*this, Name, NameLoc, LookupOrdinaryName);
   if (TemplateArgs) {
-    // Just re-use the lookup done by isTemplateName.
-    DecomposeTemplateName(R, Id);
-
-    // Re-derive the naming class.
-    if (SS.isSet()) {
-      NestedNameSpecifier *Qualifier
-        = static_cast<NestedNameSpecifier *>(SS.getScopeRep());
-      if (const Type *Ty = Qualifier->getAsType())
-        if (CXXRecordDecl *NamingClass = Ty->getAsCXXRecordDecl())
-          R.setNamingClass(NamingClass);
-    }
+    // 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);
   } else {
     bool IvarLookupFollowUp = (!SS.isSet() && II && getCurMethodDecl());
     LookupParsedName(R, S, &SS, !IvarLookupFollowUp);

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=104277&r1=104276&r2=104277&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Thu May 20 15:58:56 2010
@@ -665,6 +665,8 @@
   //
   DeclContext *OutsideOfTemplateParamDC = 0;
   for (; S && !isNamespaceOrTranslationUnitScope(S); S = S->getParent()) {
+    DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity());
+
     // Check whether the IdResolver has anything in this scope.
     bool Found = false;
     for (; I != IEnd && S->isDeclScope(DeclPtrTy::make(*I)); ++I) {
@@ -675,10 +677,12 @@
     }
     if (Found) {
       R.resolveKind();
+      if (S->isClassScope())
+        if (CXXRecordDecl *Record = dyn_cast_or_null<CXXRecordDecl>(Ctx))
+          R.setNamingClass(Record);
       return true;
     }
 
-    DeclContext *Ctx = static_cast<DeclContext*>(S->getEntity());
     if (!Ctx && S->isTemplateParamScope() && OutsideOfTemplateParamDC &&
         S->getParent() && !S->getParent()->isTemplateParamScope()) {
       // We've just searched the last template parameter scope and

Copied: cfe/trunk/test/CXX/temp/temp.names/p2.cpp (from r104149, cfe/trunk/test/CXX/temp/temp.names/p2.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.names/p2.cpp?p2=cfe/trunk/test/CXX/temp/temp.names/p2.cpp&p1=cfe/trunk/test/CXX/temp/temp.names/p2.cpp&r1=104149&r2=104277&rev=104277&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.names/p2.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.names/p2.cpp Thu May 20 15:58:56 2010
@@ -1,7 +1,7 @@
 // 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
+// explicit template arguments, we don't lose the context of the name lookup
 // because of the required early lookup to determine if it names a template.
 namespace PR7163 {
   template <typename R, typename P> void h(R (*func)(P)) {}

Added: cfe/trunk/test/SemaObjCXX/ivar-struct.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/ivar-struct.mm?rev=104277&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/ivar-struct.mm (added)
+++ cfe/trunk/test/SemaObjCXX/ivar-struct.mm Thu May 20 15:58:56 2010
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+ at interface A {
+  struct X {
+    int x, y;
+  } X;
+}
+ at end





More information about the cfe-commits mailing list