]> granicus.if.org Git - clang/commitdiff
Instantiate class template specializations during ADL.
authorJohn McCall <rjmccall@apple.com>
Fri, 24 Aug 2012 20:38:34 +0000 (20:38 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 24 Aug 2012 20:38:34 +0000 (20:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162586 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Sema/SemaLookup.cpp
lib/Sema/SemaOverload.cpp
test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp

index f4ca2f8634bf0c719e2596e2f3578336e3abb245..600d6299bc538074083bbb8b2cfd327444b6da07 100644 (file)
@@ -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);
 
index dad196b410c496384e979d63d7f604a6b5098ea7..80a50e0c791523fa839b517227deae99c38b75df 100644 (file)
@@ -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)
index 5e31e41ec33475a8d300856f5afac8dc105e6d0d..ea0f4b6937372a487e3cb7c9c183f008787ccc79 100644 (file)
@@ -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'. 
index f5ad68b75bdf16da0b785b9b56f7dad2c4f71a02..df9a2cd14cd4187170fc2c259c6fbd74a0c35d35 100644 (file)
@@ -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);
+  }
+}