]> granicus.if.org Git - clang/commitdiff
When instantiating a function template specialization following
authorDouglas Gregor <dgregor@apple.com>
Wed, 28 Apr 2010 04:52:24 +0000 (04:52 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 28 Apr 2010 04:52:24 +0000 (04:52 +0000)
template argument deduction, use the lexical declaration context as
the owner for friend function templates. Fixes 2 failures in
Boost.Graph.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102489 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateDeduction.cpp
test/SemaTemplate/friend-template.cpp

index 7154d62d6c4d0de85c5c3a2564e2a24371000147..0a2c5ae00e0af64587b2744ae61e9344b3cbc375 100644 (file)
@@ -1417,9 +1417,11 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate,
 
   // Substitute the deduced template arguments into the function template
   // declaration to produce the function template specialization.
+  DeclContext *Owner = FunctionTemplate->getDeclContext();
+  if (FunctionTemplate->getFriendObjectKind())
+    Owner = FunctionTemplate->getLexicalDeclContext();
   Specialization = cast_or_null<FunctionDecl>(
-                      SubstDecl(FunctionTemplate->getTemplatedDecl(),
-                                FunctionTemplate->getDeclContext(),
+                      SubstDecl(FunctionTemplate->getTemplatedDecl(), Owner,
                          MultiLevelTemplateArgumentList(*DeducedArgumentList)));
   if (!Specialization)
     return TDK_SubstitutionFailure;
index 6ee30aa7775a5733e5b5216667dd7ac93b689014..4b60a3db05d65cd4ae63bf2b5707dcc0352341b8 100644 (file)
@@ -127,3 +127,18 @@ namespace PR6022 {
   };
 }
 
+namespace FriendTemplateDefinition {
+  template<unsigned > struct int_c { };
+
+  template<typename T>
+  struct X {
+    template<unsigned N>
+    friend void f(X, int_c<N>) {
+      int value = N;
+    };
+  };
+
+  void test_X(X<int> x, int_c<5> i5) {
+    f(x, i5);
+  }
+}