[cfe-commits] r80692 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/SemaTemplate/instantiate-expr-2.cpp

Douglas Gregor dgregor at apple.com
Tue Sep 1 10:53:10 PDT 2009


Author: dgregor
Date: Tue Sep  1 12:53:10 2009
New Revision: 80692

URL: http://llvm.org/viewvc/llvm-project?rev=80692&view=rev
Log:
Implement proper substitution for OverloadedFunctionDecls, but substituting each of the functions in the overload set

Modified:
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/SemaTemplate/instantiate-expr-2.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=80692&r1=80691&r2=80692&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Tue Sep  1 12:53:10 2009
@@ -465,14 +465,6 @@
                                               E->getSourceRange().getBegin()));
   }
   
-  if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) {
-    // FIXME: instantiate each decl in the overload set
-    return SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Ovl,
-                                                     SemaRef.Context.OverloadTy,
-                                                     E->getLocation(),
-                                                     false, false));
-  }
-  
   NamedDecl *InstD = SemaRef.FindInstantiatedDecl(D);
   if (!InstD)
     return SemaRef.ExprError();

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=80692&r1=80691&r2=80692&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Sep  1 12:53:10 2009
@@ -1347,7 +1347,22 @@
 /// X<T>::<Kind>::KnownValue) to its instantiation
 /// (X<int>::<Kind>::KnownValue). InstantiateCurrentDeclRef() performs
 /// this mapping from within the instantiation of X<int>.
-NamedDecl * Sema::FindInstantiatedDecl(NamedDecl *D) {
+NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D) {
+  if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(D)) {
+    // Transform all of the elements of the overloaded function set.
+    OverloadedFunctionDecl *Result 
+      = OverloadedFunctionDecl::Create(Context, CurContext, Ovl->getDeclName());
+    
+    for (OverloadedFunctionDecl::function_iterator F = Ovl->function_begin(),
+                                                FEnd = Ovl->function_end();
+         F != FEnd; ++F) {
+      Result->addOverload(
+                  AnyFunctionDecl::getFromNamedDecl(FindInstantiatedDecl(*F)));
+    }
+    
+    return Result;
+  }  
+  
   DeclContext *ParentDC = D->getDeclContext();
   if (isa<ParmVarDecl>(D) || ParentDC->isFunctionOrMethod()) {
     // D is a local of some kind. Look into the map of local
@@ -1378,8 +1393,9 @@
     }
 
   ParentDC = FindInstantiatedContext(ParentDC);
-  if (!ParentDC) return 0;
-
+  if (!ParentDC) 
+    return 0;
+  
   if (ParentDC != D->getDeclContext()) {
     // We performed some kind of instantiation in the parent context,
     // so now we need to look into the instantiated parent context to

Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-2.cpp?rev=80692&r1=80691&r2=80692&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-2.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-2.cpp Tue Sep  1 12:53:10 2009
@@ -160,3 +160,21 @@
   
   template struct B<int>;  
 }
+
+namespace N10 {
+  template <typename T>
+  class A {
+    struct X { };
+    
+  public:
+    ~A() {
+      f(reinterpret_cast<X *>(0), reinterpret_cast<X *>(0));
+    }
+    
+  private:
+    void f(X *);
+    void f(X *, X *);
+  };
+  
+  template class A<int>;
+}





More information about the cfe-commits mailing list