]> granicus.if.org Git - clang/commitdiff
When instantiating UnresolvedLookupExpr and UnresolvedMemberExpr
authorDouglas Gregor <dgregor@apple.com>
Tue, 27 Apr 2010 16:10:10 +0000 (16:10 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 27 Apr 2010 16:10:10 +0000 (16:10 +0000)
expressions, be sure to set the naming class of the LookupResult
structure. Fixes PR6947.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102434 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/TreeTransform.h
test/SemaTemplate/instantiate-method.cpp

index f80747b69f10491f599daaefe26eba19e0045124..2f36807659c5e80536ad5e9f3b6a2669ebeb601f 100644 (file)
@@ -5336,6 +5336,20 @@ TreeTransform<Derived>::TransformUnresolvedLookupExpr(
     
     SS.setScopeRep(Qualifier);
     SS.setRange(Old->getQualifierRange());
+    
+    // If this nested-name-specifier refers to a class type, that is the
+    // naming class.
+    if (const Type *NamedType = Qualifier->getAsType())
+      if (const RecordType *NamedRecord = NamedType->getAs<RecordType>())
+        R.setNamingClass(cast<CXXRecordDecl>(NamedRecord->getDecl()));
+  } else if (Old->getNamingClass()) {
+    CXXRecordDecl *NamingClass
+      = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
+                                                            Old->getNameLoc(),
+                                                        Old->getNamingClass()));
+    if (!NamingClass)
+      return SemaRef.ExprError();
+    R.setNamingClass(NamingClass);
   }
 
   // If we have no template arguments, it's a normal declaration name.
@@ -5721,6 +5735,7 @@ TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old)
     BaseType = getDerived().TransformType(Old->getBaseType());
   }
 
+  CXXRecordDecl *NamingClass = 0;
   NestedNameSpecifier *Qualifier = 0;
   if (Old->getQualifier()) {
     Qualifier
@@ -5728,6 +5743,12 @@ TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old)
                                                   Old->getQualifierRange());
     if (Qualifier == 0)
       return SemaRef.ExprError();
+    
+    // If this nested-name-specifier refers to a class type, that is the
+    // naming class.
+    if (const Type *NamedType = Qualifier->getAsType())
+      if (const RecordType *NamedRecord = NamedType->getAs<RecordType>())
+        NamingClass = cast<CXXRecordDecl>(NamedRecord->getDecl());
   }
 
   LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
@@ -5762,6 +5783,25 @@ TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old)
 
   R.resolveKind();
 
+  // Determine the naming class, if we haven't already.
+  if (!NamingClass) {
+    QualType T = BaseType;
+    if (const PointerType *PointerTy = T->getAs<PointerType>())
+      T = PointerTy->getPointeeType();
+    if (const RecordType *NamedRecord = T->getAs<RecordType>())
+      NamingClass = cast<CXXRecordDecl>(NamedRecord->getDecl());    
+  }
+  
+  if (!NamingClass && Old->getNamingClass()) {
+    NamingClass = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
+                                                          Old->getMemberLoc(),
+                                                        Old->getNamingClass()));
+    if (!NamingClass)
+      return SemaRef.ExprError();
+  }
+  if (NamingClass)
+    R.setNamingClass(NamingClass);
+  
   TemplateArgumentListInfo TransArgs;
   if (Old->hasExplicitTemplateArgs()) {
     TransArgs.setLAngleLoc(Old->getLAngleLoc());
index 3ef07d356d3e1ed6753fd6163450537a1f04aefd..c0325cfa6c4b066292af42002ed2e2ff9c031297 100644 (file)
@@ -127,3 +127,28 @@ namespace test1 {
   };
   template class B<int>;
 }
+
+namespace PR6947 {
+  template< class T > 
+  struct X {
+    int f0( )      
+    {
+      typedef void ( X::*impl_fun_ptr )( );
+      impl_fun_ptr pImpl = &X::template
+        f0_impl1<int>;
+    }
+  private:                  
+    int f1() {
+    }
+    template< class Processor>                  
+    void f0_impl1( )                 
+    {
+    }
+  };
+
+  char g0() {
+    X<int> pc;
+    pc.f0();
+  }
+
+}