aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-10-30 21:07:27 +0000
committerDouglas Gregor <dgregor@apple.com>2009-10-30 21:07:27 +0000
commite8c01bdb56549adcecd71ce39160eea54b2c51c8 (patch)
tree9a535880e0d0c7475165275aabf058fe913df760
parent7c15e71fb260629e58c25798f1040e5a3305f9f6 (diff)
Instantiate class template friends better; fixes PR5332.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85612 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaTemplateInstantiateDecl.cpp9
-rw-r--r--test/CXX/temp/temp.decls/temp.friend/p5.cpp2
-rw-r--r--test/SemaTemplate/friend-template.cpp10
3 files changed, 20 insertions, 1 deletions
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 0b54533175..f511eb15d2 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -425,12 +425,19 @@ Decl *TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
= ClassTemplateDecl::Create(SemaRef.Context, Owner, D->getLocation(),
D->getIdentifier(), InstParams, RecordInst, 0);
RecordInst->setDescribedClassTemplate(Inst);
- Inst->setAccess(D->getAccess());
+ if (D->getFriendObjectKind())
+ Inst->setObjectOfFriendDecl(true);
+ else
+ Inst->setAccess(D->getAccess());
Inst->setInstantiatedFromMemberTemplate(D);
// Trigger creation of the type for the instantiation.
SemaRef.Context.getTypeDeclType(RecordInst);
+ // We're done with friends now.
+ if (Inst->getFriendObjectKind())
+ return Inst;
+
Owner->addDecl(Inst);
// First, we sort the partial specializations by location, so
diff --git a/test/CXX/temp/temp.decls/temp.friend/p5.cpp b/test/CXX/temp/temp.decls/temp.friend/p5.cpp
index f1142a4129..74895c4906 100644
--- a/test/CXX/temp/temp.decls/temp.friend/p5.cpp
+++ b/test/CXX/temp/temp.decls/temp.friend/p5.cpp
@@ -9,3 +9,5 @@ class B {
template <class T> friend class A<T>::Member;
};
+A<int> a;
+B b;
diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp
index 761c13076d..dc277f4657 100644
--- a/test/SemaTemplate/friend-template.cpp
+++ b/test/SemaTemplate/friend-template.cpp
@@ -54,6 +54,7 @@ struct X1 {
template<typename U> void f2(U);
X1<int> x1i;
+X0<int*> x0ip;
template<> void f2(int);
@@ -62,3 +63,12 @@ template<> void f2(int);
template<typename U> void f3(U);
template<> void f3(int);
+
+// PR5332
+template <typename T>
+class Foo {
+ template <typename U>
+ friend class Foo;
+};
+
+Foo<int> foo;