diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-12-21 08:14:57 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-12-21 08:14:57 +0000 |
commit | b0ee93cf945744569b82b8a07361061f2963264a (patch) | |
tree | 0fcbac90b812cf485435eb987a0a63fbb73cc7a6 | |
parent | 3910cfd17fcd99ac80158e625fc63e4784d26435 (diff) |
A class template partial specialization cannot be a friend. Fixes PR8649.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122325 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 6 | ||||
-rw-r--r-- | test/SemaTemplate/friend-template.cpp | 9 |
3 files changed, 17 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index b53fb416be..281d0e65ba 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -474,6 +474,8 @@ def err_tagless_friend_type_template : Error< "friend type templates must use an elaborated type">; def err_no_matching_local_friend : Error< "no matching function found in local scope">; +def err_partial_specialization_friend : Error< + "partial specialization cannot be declared as a friend">; def err_abstract_type_in_decl : Error< "%select{return|parameter|variable|field}0 type %1 is an abstract class">; diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 923e7cc30f..ca2a43b729 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -4087,6 +4087,12 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, if (TemplateParams && TemplateParams->size() > 0) { isPartialSpecialization = true; + if (TUK == TUK_Friend) { + Diag(KWLoc, diag::err_partial_specialization_friend) + << SourceRange(LAngleLoc, RAngleLoc); + return true; + } + // C++ [temp.class.spec]p10: // The template parameter list of a specialization shall not // contain default template argument values. diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp index 1d62804f68..419ae93daa 100644 --- a/test/SemaTemplate/friend-template.cpp +++ b/test/SemaTemplate/friend-template.cpp @@ -207,3 +207,12 @@ namespace PR7013b { } } + +namespace PR8649 { + template<typename T, typename U, unsigned N> + struct X { + template<unsigned M> friend class X<T, U, M>; // expected-error{{partial specialization cannot be declared as a friend}} + }; + + X<int, float, 7> x; +} |