diff options
author | John McCall <rjmccall@apple.com> | 2009-12-14 23:19:40 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2009-12-14 23:19:40 +0000 |
commit | e976ffe18ee60b81641423f42ff6feec2f5e3cb7 (patch) | |
tree | dedcd5ec43e1a67972b5c7f209dbf6d393b6bfc6 | |
parent | 42f8d001ce4b125b80bdf01008e35fd6eb405cb7 (diff) |
Fix PR5716 by bandaging over the solution until we can come back to it.
I apologize for friend declarations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91359 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 | ||||
-rw-r--r-- | test/SemaTemplate/friend-template.cpp | 15 |
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 9c4c38a134..8d74bd76ca 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -627,7 +627,12 @@ TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { 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. diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp index f4fd6b8899..98992f6f60 100644 --- a/test/SemaTemplate/friend-template.cpp +++ b/test/SemaTemplate/friend-template.cpp @@ -82,3 +82,18 @@ namespace test3 { 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}} + } +} |