[cfe-commits] r83980 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp www/cxx_status.html

Douglas Gregor dgregor at apple.com
Tue Oct 13 10:02:54 PDT 2009


Author: dgregor
Date: Tue Oct 13 12:02:54 2009
New Revision: 83980

URL: http://llvm.org/viewvc/llvm-project?rev=83980&view=rev
Log:
Diagnose attempts to add default function arguments to a
specialization. This completes C++ [temp.expl.spec]!

Added:
    cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp   (with props)
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=83980&r1=83979&r2=83980&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Oct 13 12:02:54 2009
@@ -973,6 +973,9 @@
   "%select{implicit|explicit}0 instantiation first required here">;
 def err_template_spec_friend : Error<
   "template specialization declaration cannot be a friend">;
+def err_template_spec_default_arg : Error<
+  "default argument not permitted on an explicit "
+  "%select{instantiation|specialization}0 of function %1">;
 
 // C++ class template specializations and out-of-line definitions
 def err_template_spec_needs_header : Error<

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=83980&r1=83979&r2=83980&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Oct 13 12:02:54 2009
@@ -296,6 +296,22 @@
           << NewParam->getDefaultArgRange();
         Diag(Old->getLocation(), diag::note_template_prev_declaration)
           << false;
+      } else if (New->getTemplateSpecializationKind()
+                   != TSK_ImplicitInstantiation &&
+                 New->getTemplateSpecializationKind() != TSK_Undeclared) {
+        // C++ [temp.expr.spec]p21:
+        //   Default function arguments shall not be specified in a declaration
+        //   or a definition for one of the following explicit specializations:
+        //     - the explicit specialization of a function template;
+        //     — the explicit specialization of a member function template;
+        //     — the explicit specialization of a member function of a class 
+        //       template where the class template specialization to which the
+        //       member function specialization belongs is implicitly 
+        //       instantiated.
+        Diag(NewParam->getLocation(), diag::err_template_spec_default_arg)
+          << (New->getTemplateSpecializationKind() ==TSK_ExplicitSpecialization)
+          << New->getDeclName()
+          << NewParam->getDefaultArgRange();
       } else if (New->getDeclContext()->isDependentContext()) {
         // C++ [dcl.fct.default]p6 (DR217):
         //   Default arguments for a member function of a class template shall 

Added: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp?rev=83980&view=auto

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp (added)
+++ cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp Tue Oct 13 12:02:54 2009
@@ -0,0 +1,30 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template<typename T>
+struct X {
+  void mf1(T);
+  template<typename U> void mf2(T, U); // expected-note{{previous}}
+};
+
+template<>
+void X<int>::mf1(int i = 17) // expected-error{{default}}
+{
+}
+
+template<> template<>
+void X<int>::mf2(int, int = 17) // expected-error{{default}}
+{ }
+
+template<> template<typename U> 
+void X<int>::mf2(int, U = U()) // expected-error{{default}}
+{
+}
+
+template<>
+struct X<float> {
+  void mf1(float);
+};
+
+void X<float>::mf1(float = 3.14f)  // okay
+{
+}

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp

------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/CXX/temp/temp.spec/temp.expl.spec/p21.cpp

------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cfe/trunk/www/cxx_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=83980&r1=83979&r2=83980&view=diff

==============================================================================
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Tue Oct 13 12:02:54 2009
@@ -2085,11 +2085,11 @@
 </tr>
 <tr>
   <td>    14.7.3 [temp.expl.spec]</td>
-  <td class="advanced" align="center"></td>
-  <td class="medium" align="center"></td>
-  <td class="medium" align="center"></td>
-  <td class="broken" align="center"></td>
-  <td>O</td>
+  <td class="complete" align="center">&#x2713;</td>
+  <td class="complete" align="center">&#x2713;</td>
+  <td class="complete" align="center">&#x2713;</td>
+  <td class="complete" align="center"></td>
+  <td></td>
 </tr>
 <tr>
   <td>  14.8 [temp.fct.spec]</td>





More information about the cfe-commits mailing list