[cfe-commits] r102489 - in /cfe/trunk: lib/Sema/SemaTemplateDeduction.cpp test/SemaTemplate/friend-template.cpp

Douglas Gregor dgregor at apple.com
Tue Apr 27 21:52:24 PDT 2010


Author: dgregor
Date: Tue Apr 27 23:52:24 2010
New Revision: 102489

URL: http://llvm.org/viewvc/llvm-project?rev=102489&view=rev
Log:
When instantiating a function template specialization following
template argument deduction, use the lexical declaration context as
the owner for friend function templates. Fixes 2 failures in
Boost.Graph.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/test/SemaTemplate/friend-template.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=102489&r1=102488&r2=102489&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Apr 27 23:52:24 2010
@@ -1417,9 +1417,11 @@
 
   // 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;

Modified: cfe/trunk/test/SemaTemplate/friend-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/friend-template.cpp?rev=102489&r1=102488&r2=102489&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/friend-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/friend-template.cpp Tue Apr 27 23:52:24 2010
@@ -127,3 +127,18 @@
   };
 }
 
+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);
+  }
+}





More information about the cfe-commits mailing list