r184882 - Implement DR21

David Majnemer david.majnemer at gmail.com
Tue Jun 25 15:08:55 PDT 2013


Author: majnemer
Date: Tue Jun 25 17:08:55 2013
New Revision: 184882

URL: http://llvm.org/viewvc/llvm-project?rev=184882&view=rev
Log:
Implement DR21

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.

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

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=184882&r1=184881&r2=184882&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Jun 25 17:08:55 2013
@@ -4938,6 +4938,7 @@ public:
     TPC_ClassTemplate,
     TPC_FunctionTemplate,
     TPC_ClassTemplateMember,
+    TPC_FriendClassTemplate,
     TPC_FriendFunctionTemplate,
     TPC_FriendFunctionTemplateDefinition,
     TPC_TypeAliasTemplate

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=184882&r1=184881&r2=184882&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Jun 25 17:08:55 2013
@@ -1033,13 +1033,14 @@ Sema::CheckClassTemplate(Scope *S, unsig
   // 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 DiagnoseDefaultTemplateArgum
       << 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

Modified: cfe/trunk/test/CXX/drs/dr0xx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr0xx.cpp?rev=184882&r1=184881&r2=184882&view=diff
==============================================================================
--- cfe/trunk/test/CXX/drs/dr0xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr0xx.cpp Tue Jun 25 17:08:55 2013
@@ -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}}
   };
 }
 

Modified: cfe/trunk/www/cxx_dr_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_dr_status.html?rev=184882&r1=184881&r2=184882&view=diff
==============================================================================
--- cfe/trunk/www/cxx_dr_status.html (original)
+++ cfe/trunk/www/cxx_dr_status.html Tue Jun 25 17:08:55 2013
@@ -164,7 +164,7 @@
     <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>





More information about the cfe-commits mailing list