From 44c73848d5d5bd34c05582dc8398a20bea7cd971 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 1 Sep 2009 17:53:10 +0000 Subject: [PATCH] Implement proper substitution for OverloadedFunctionDecls, but substituting each of the functions in the overload set git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80692 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiate.cpp | 8 -------- lib/Sema/SemaTemplateInstantiateDecl.cpp | 22 +++++++++++++++++++--- test/SemaTemplate/instantiate-expr-2.cpp | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index b1cc328a2d..c03f2e19aa 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -465,14 +465,6 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) { E->getSourceRange().getBegin())); } - if (OverloadedFunctionDecl *Ovl = dyn_cast(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(); diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 99b237d04e..0179160835 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1347,7 +1347,22 @@ DeclContext *Sema::FindInstantiatedContext(DeclContext* DC) { /// X::::KnownValue) to its instantiation /// (X::::KnownValue). InstantiateCurrentDeclRef() performs /// this mapping from within the instantiation of X. -NamedDecl * Sema::FindInstantiatedDecl(NamedDecl *D) { +NamedDecl *Sema::FindInstantiatedDecl(NamedDecl *D) { + if (OverloadedFunctionDecl *Ovl = dyn_cast(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(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 diff --git a/test/SemaTemplate/instantiate-expr-2.cpp b/test/SemaTemplate/instantiate-expr-2.cpp index 5351701cdc..146e63c5bb 100644 --- a/test/SemaTemplate/instantiate-expr-2.cpp +++ b/test/SemaTemplate/instantiate-expr-2.cpp @@ -160,3 +160,21 @@ namespace N9 { template struct B; } + +namespace N10 { + template + class A { + struct X { }; + + public: + ~A() { + f(reinterpret_cast(0), reinterpret_cast(0)); + } + + private: + void f(X *); + void f(X *, X *); + }; + + template class A; +} -- 2.50.1