diff options
author | John McCall <rjmccall@apple.com> | 2012-08-24 20:38:34 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2012-08-24 20:38:34 +0000 |
commit | 42f48fbdf31a7e8c516ba5eed486ff53966459fc (patch) | |
tree | c62ca4acdb24ee23fd104223d8ce3521a88a244b | |
parent | a6e28f27c668775e3927b9c0be0a17636fed16fc (diff) |
Instantiate class template specializations during ADL.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162586 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Sema/Sema.h | 3 | ||||
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 20 | ||||
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 2 | ||||
-rw-r--r-- | test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp | 24 |
4 files changed, 40 insertions, 9 deletions
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index f4ca2f8634..600d6299bc 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -2186,7 +2186,8 @@ public: bool EnteringContext = false, const ObjCObjectPointerType *OPT = 0); - void FindAssociatedClassesAndNamespaces(llvm::ArrayRef<Expr *> Args, + void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, + llvm::ArrayRef<Expr *> Args, AssociatedNamespaceSet &AssociatedNamespaces, AssociatedClassSet &AssociatedClasses); diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index dad196b410..80a50e0c79 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1725,15 +1725,17 @@ bool Sema::DiagnoseAmbiguousLookup(LookupResult &Result) { namespace { struct AssociatedLookup { - AssociatedLookup(Sema &S, + AssociatedLookup(Sema &S, SourceLocation InstantiationLoc, Sema::AssociatedNamespaceSet &Namespaces, Sema::AssociatedClassSet &Classes) - : S(S), Namespaces(Namespaces), Classes(Classes) { + : S(S), Namespaces(Namespaces), Classes(Classes), + InstantiationLoc(InstantiationLoc) { } Sema &S; Sema::AssociatedNamespaceSet &Namespaces; Sema::AssociatedClassSet &Classes; + SourceLocation InstantiationLoc; }; } @@ -1864,8 +1866,10 @@ addAssociatedClassesAndNamespaces(AssociatedLookup &Result, // Only recurse into base classes for complete types. if (!Class->hasDefinition()) { - // FIXME: we might need to instantiate templates here - return; + QualType type = Result.S.Context.getTypeDeclType(Class); + if (Result.S.RequireCompleteType(Result.InstantiationLoc, type, + /*no diagnostic*/ 0)) + return; } // Add direct and indirect base classes along with their associated @@ -2069,13 +2073,15 @@ addAssociatedClassesAndNamespaces(AssociatedLookup &Result, QualType Ty) { /// namespaces searched by argument-dependent lookup /// (C++ [basic.lookup.argdep]) for a given set of arguments. void -Sema::FindAssociatedClassesAndNamespaces(llvm::ArrayRef<Expr *> Args, +Sema::FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, + llvm::ArrayRef<Expr *> Args, AssociatedNamespaceSet &AssociatedNamespaces, AssociatedClassSet &AssociatedClasses) { AssociatedNamespaces.clear(); AssociatedClasses.clear(); - AssociatedLookup Result(*this, AssociatedNamespaces, AssociatedClasses); + AssociatedLookup Result(*this, InstantiationLoc, + AssociatedNamespaces, AssociatedClasses); // C++ [basic.lookup.koenig]p2: // For each argument type T in the function call, there is a set @@ -2648,7 +2654,7 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, bool Operator, // arguments we have. AssociatedNamespaceSet AssociatedNamespaces; AssociatedClassSet AssociatedClasses; - FindAssociatedClassesAndNamespaces(Args, + FindAssociatedClassesAndNamespaces(Loc, Args, AssociatedNamespaces, AssociatedClasses); if (StdNamespaceIsAssociated && StdNamespace) diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 5e31e41ec3..ea0f4b6937 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -9509,7 +9509,7 @@ DiagnoseTwoPhaseLookup(Sema &SemaRef, SourceLocation FnLoc, // declaring the function there instead. Sema::AssociatedNamespaceSet AssociatedNamespaces; Sema::AssociatedClassSet AssociatedClasses; - SemaRef.FindAssociatedClassesAndNamespaces(Args, + SemaRef.FindAssociatedClassesAndNamespaces(FnLoc, Args, AssociatedNamespaces, AssociatedClasses); // Never suggest declaring a function within namespace 'std'. diff --git a/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp b/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp index f5ad68b75b..df9a2cd14c 100644 --- a/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp +++ b/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp @@ -108,3 +108,27 @@ namespace test6 { test6_function(args); } } + +// PR13682: we might need to instantiate class temploids. +namespace test7 { + namespace inner { + class A {}; + void test7_function(A &); + } + template <class T> class B : public inner::A {}; + + void test(B<int> &ref) { + test7_function(ref); + } +} + +// Like test7, but ensure we don't complain if the type is properly +// incomplete. +namespace test8 { + template <class T> class B; + void test8_function(B<int> &); + + void test(B<int> &ref) { + test8_function(ref); + } +} |