]> granicus.if.org Git - clang/commitdiff
Implement DR21
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 25 Jun 2013 22:08:55 +0000 (22:08 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 25 Jun 2013 22:08:55 +0000 (22:08 +0000)
A default template-argument shall not be specified in a friend template
declaration.

Interestingly, we properly handled default template arguments on friend
class members but not on just friend classes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184882 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Sema/SemaTemplate.cpp
test/CXX/drs/dr0xx.cpp
www/cxx_dr_status.html

index 82de36908cd9152dd1fd2ad537770d4ab20cdbbb..6d8c790580986023f4e68ee9a0de07ff9d559316 100644 (file)
@@ -4938,6 +4938,7 @@ public:
     TPC_ClassTemplate,
     TPC_FunctionTemplate,
     TPC_ClassTemplateMember,
+    TPC_FriendClassTemplate,
     TPC_FriendFunctionTemplate,
     TPC_FriendFunctionTemplateDefinition,
     TPC_TypeAliasTemplate
index 88b24a1702c39fa8342ca7af58a3a29cdb2c8384..6c0658f05fbad271f8ecc3de352f37482dfcfaad 100644 (file)
@@ -1033,13 +1033,14 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
   // template declaration. Skip this check for a friend in a dependent
   // context, because the template parameter list might be dependent.
   if (!(TUK == TUK_Friend && CurContext->isDependentContext()) &&
-      CheckTemplateParameterList(TemplateParams,
-            PrevClassTemplate? PrevClassTemplate->getTemplateParameters() : 0,
-                                 (SS.isSet() && SemanticContext &&
-                                  SemanticContext->isRecord() &&
-                                  SemanticContext->isDependentContext())
-                                   ? TPC_ClassTemplateMember
-                                   : TPC_ClassTemplate))
+      CheckTemplateParameterList(
+          TemplateParams,
+          PrevClassTemplate ? PrevClassTemplate->getTemplateParameters() : 0,
+          (SS.isSet() && SemanticContext && SemanticContext->isRecord() &&
+           SemanticContext->isDependentContext())
+              ? TPC_ClassTemplateMember
+              : TUK == TUK_Friend ? TPC_FriendClassTemplate
+                                  : TPC_ClassTemplate))
     Invalid = true;
 
   if (SS.isSet()) {
@@ -1187,6 +1188,7 @@ static bool DiagnoseDefaultTemplateArgument(Sema &S,
       << DefArgRange;
     return true;
 
+  case Sema::TPC_FriendClassTemplate:
   case Sema::TPC_FriendFunctionTemplate:
     // C++ [temp.param]p9:
     //   A default template-argument shall not be specified in a
index c51e8c82e490e8f43313ab8429f5ecd7cf30e3e3..e00264102ebaf4e3154863b81358cb2000115cdf 100644 (file)
@@ -223,12 +223,11 @@ namespace dr20 { // dr20: yes
   X x = f(); // expected-error {{private}}
 }
 
-namespace dr21 { // dr21: no
+namespace dr21 { // dr21: yes
   template<typename T> struct A;
   struct X {
-    // FIXME: We should reject these, per [temp.param]p9.
-    template<typename T = int> friend struct A;
-    template<typename T = int> friend struct B;
+    template<typename T = int> friend struct A; // expected-error {{default template argument not permitted on a friend template}}
+    template<typename T = int> friend struct B; // expected-error {{default template argument not permitted on a friend template}}
   };
 }
 
index eda94fb38a91136f875a27d97c11c2a602c2f768..dd8c7d233fb2ec51ee6bfdb2f6db46129ea0cdd6 100644 (file)
     <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#21">21</a></td>
     <td>TC1</td>
     <td>Can a default argument for a template parameter appear in a friend declaration?</td>
-    <td class="none" align="center">No</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr>
     <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#22">22</a></td>