]> granicus.if.org Git - clang/commitdiff
Implement proper substitution for OverloadedFunctionDecls, but substituting each...
authorDouglas Gregor <dgregor@apple.com>
Tue, 1 Sep 2009 17:53:10 +0000 (17:53 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 1 Sep 2009 17:53:10 +0000 (17:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80692 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiate.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-expr-2.cpp

index b1cc328a2d43137d65467fbadef3bee114b3bd70..c03f2e19aab2ccbf993aba637ab400a1b4e4a7df 100644 (file)
@@ -465,14 +465,6 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
                                               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();
index 99b237d04e45c249f3fb0ff6d23365d0598917e5..0179160835ce990ffb03aca0d270b28884cc1fab 100644 (file)
@@ -1347,7 +1347,22 @@ DeclContext *Sema::FindInstantiatedContext(DeclContext* DC) {
 /// 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 @@ NamedDecl * Sema::FindInstantiatedDecl(NamedDecl *D) {
     }
 
   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
index 5351701cdcdc2da2958c9521844341b2e72c0201..146e63c5bb00c46589aba95cc19ba546b95cedf1 100644 (file)
@@ -160,3 +160,21 @@ namespace N9 {
   
   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>;
+}