]> granicus.if.org Git - clang/commitdiff
A class template partial specialization cannot be a friend. Fixes PR8649.
authorDouglas Gregor <dgregor@apple.com>
Tue, 21 Dec 2010 08:14:57 +0000 (08:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 21 Dec 2010 08:14:57 +0000 (08:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122325 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaTemplate.cpp
test/SemaTemplate/friend-template.cpp

index b53fb416bee857a353200a6fd7042b8e461efa64..281d0e65bafc5cd880c8da967c711c57da75b81e 100644 (file)
@@ -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">;
index 923e7cc30f3c9bd2b5cb9ae62e8ce28b3f3e0225..ca2a43b72955928489237c16db252c9a2747d6fd 100644 (file)
@@ -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.
index 1d62804f68acc489505d0ad6f0e282fb6f871fb3..419ae93daab8e0cfaf8d2c55cbf271dbec5d4529 100644 (file)
@@ -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;
+}