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

John McCall rjmccall at apple.com
Mon Dec 14 15:19:40 PST 2009


Author: rjmccall
Date: Mon Dec 14 17:19:40 2009
New Revision: 91359

URL: http://llvm.org/viewvc/llvm-project?rev=91359&view=rev
Log:
Fix PR5716 by bandaging over the solution until we can come back to it.
I apologize for friend declarations.


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

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=91359&r1=91358&r2=91359&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon Dec 14 17:19:40 2009
@@ -627,7 +627,12 @@
   InstTemplate->setAccess(D->getAccess());
   assert(InstTemplate && 
          "VisitFunctionDecl/CXXMethodDecl didn't create a template!");
-  if (!InstTemplate->getInstantiatedFromMemberTemplate())
+
+  // Link the instantiation back to the pattern *unless* this is a
+  // non-definition friend declaration.
+  if (!InstTemplate->getInstantiatedFromMemberTemplate() &&
+      !(InstTemplate->getFriendObjectKind() &&
+        !D->getTemplatedDecl()->isThisDeclarationADefinition()))
     InstTemplate->setInstantiatedFromMemberTemplate(D);
   
   // Add non-friends into the owner.

Modified: cfe/trunk/test/SemaTemplate/friend-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/friend-template.cpp?rev=91359&r1=91358&r2=91359&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/friend-template.cpp (original)
+++ cfe/trunk/test/SemaTemplate/friend-template.cpp Mon Dec 14 17:19:40 2009
@@ -82,3 +82,18 @@
 
   X3<long> x3l; // FIXME: should cause an instantiation-time failure
 }
+
+// PR5716
+namespace test4 {
+  template<typename> struct A {
+    template<typename T> friend void f(const A<T>&);
+  };
+
+  template<typename T> void f(const A<T>&) {
+    int a[sizeof(T) ? -1 : -1]; // expected-error {{array size is negative}}
+  }
+
+  void f() {
+    f(A<int>()); // expected-note {{in instantiation of function template specialization}}
+  }
+}





More information about the cfe-commits mailing list