[cfe-commits] r124855 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaTemplate.cpp test/CXX/temp/temp.param/p11-0x.cpp test/CXX/temp/temp.param/p9.cpp

Douglas Gregor dgregor at apple.com
Thu Feb 3 19:57:22 PST 2011


Author: dgregor
Date: Thu Feb  3 21:57:22 2011
New Revision: 124855

URL: http://llvm.org/viewvc/llvm-project?rev=124855&view=rev
Log:
When a function template's template parameter has a default argument,
it's okay for the following template parameters to not have default
arguments (since those template parameters can still be
deduced). Also, downgrade the error about default template arguments
in function templates to an extension warning, since this is a
harmless C++0x extension.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/CXX/temp/temp.param/p11-0x.cpp
    cfe/trunk/test/CXX/temp/temp.param/p9.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=124855&r1=124854&r2=124855&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Feb  3 21:57:22 2011
@@ -1476,9 +1476,9 @@
   "previous default template argument defined here">;
 def err_template_param_default_arg_missing : Error<
   "template parameter missing a default argument">;
-def err_template_parameter_default_in_function_template : Error<
-  "a template parameter of a function template cannot have a default argument "
-  "in C++98">;
+def ext_template_parameter_default_in_function_template : ExtWarn<
+  "default template arguments for a function template are a C++0x extension">,
+  InGroup<CXX0x>;
 def err_template_parameter_default_template_member : Error<
   "cannot add a default template argument to the definition of a member of a "
   "class template">;

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=124855&r1=124854&r2=124855&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Feb  3 21:57:22 2011
@@ -1052,7 +1052,7 @@
     // (This sentence is not in C++0x, per DR226).
     if (!S.getLangOptions().CPlusPlus0x)
       S.Diag(ParamLoc,
-             diag::err_template_parameter_default_in_function_template)
+             diag::ext_template_parameter_default_in_function_template)
         << DefArgRange;
     return false;
 
@@ -1315,7 +1315,7 @@
       Diag(NewDefaultLoc, diag::err_template_param_default_arg_redefinition);
       Diag(OldDefaultLoc, diag::note_template_param_prev_default_arg);
       Invalid = true;
-    } else if (MissingDefaultArg) {
+    } else if (MissingDefaultArg && TPC != TPC_FunctionTemplate) {
       // C++ [temp.param]p11:
       //   If a template-parameter of a class template has a default
       //   template-argument, each subsequent template-parameter shall either

Modified: cfe/trunk/test/CXX/temp/temp.param/p11-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.param/p11-0x.cpp?rev=124855&r1=124854&r2=124855&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.param/p11-0x.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.param/p11-0x.cpp Thu Feb  3 21:57:22 2011
@@ -46,3 +46,16 @@
 
 template<template<int> class... Meta, template<int> class M> 
 void f1tt(X1tt<M, Meta...>);
+
+namespace DefaultTemplateArgsInFunction {
+  template<typename T = int, typename U>  T &f0(U) { T *x = 0; return *x; }
+
+  void test_f0() {
+    int &ir0 = f0(3.14159);
+    int &ir1 = f0<int>(3.14159);
+    float &fr0 = f0<float>(3.14159);
+  }
+
+  template<> int &f0(int*);
+  template int &f0(double&);
+}

Modified: cfe/trunk/test/CXX/temp/temp.param/p9.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.param/p9.cpp?rev=124855&r1=124854&r2=124855&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.param/p9.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.param/p9.cpp Thu Feb  3 21:57:22 2011
@@ -2,9 +2,9 @@
 
 // A default template-argument shall not be specified in a function
 // template declaration or a function template definition
-template<typename T = int> // expected-error{{cannot have a default argument}}
+template<typename T = int> // expected-warning{{default template arguments for a function template are a C++0x extension}}
   void foo0(T); 
-template<typename T = int> // expected-error{{cannot have a default argument}} 
+template<typename T = int> // expected-warning{{default template arguments for a function template are a C++0x extension}} 
   void foo1(T) { } 
 
 // [...] nor in the template-parameter-list of the definition of a





More information about the cfe-commits mailing list