Hi,

as the testcase shows (merge of 53624 & 54104), in case of local types (possibly synthesized for a lambda) we check for the default template arguments of the synthesized template parameters according to the rules for *types* (instead of those for functions) and we spuriously reject. As far as I can see we should just return early in such cases, because we already checked upstream, thus I figured out logic that apparently works, but I'm not sure it's the most precise and concise we can have. Bootstrap and regression tests are fine, anyway.

Thanks,
Paolo.

//////////////////////////
/cp
2012-07-28  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/53624
        * pt.c (check_default_tmpl_args): Return early for local types.

/testsuite
2012-07-28  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/53624
        * testsuite/g++.dg/cpp0x/temp_default5.C: New.

Index: testsuite/g++.dg/cpp0x/temp_default5.C
===================================================================
--- testsuite/g++.dg/cpp0x/temp_default5.C      (revision 0)
+++ testsuite/g++.dg/cpp0x/temp_default5.C      (revision 0)
@@ -0,0 +1,13 @@
+// { dg-options "-std=c++11" }
+
+template <class Z = void, class T>
+void Foo(T)
+{
+  struct X {};
+}
+
+template <class T = int, typename U>
+void f(const U&)
+{
+  auto g = [] () {};
+}
Index: cp/pt.c
===================================================================
--- cp/pt.c     (revision 189925)
+++ cp/pt.c     (working copy)
@@ -4229,6 +4229,7 @@ check_default_tmpl_args (tree decl, tree parms, in
   const char *msg;
   int last_level_to_check;
   tree parm_level;
+  tree type = TREE_TYPE (decl);
   bool no_errors = true;
 
   /* [temp.param]
@@ -4244,6 +4245,10 @@ check_default_tmpl_args (tree decl, tree parms, in
        local scope.  */
     return true;
 
+  if (type && TREE_CODE (decl) != FUNCTION_DECL
+      && TREE_CODE (CP_TYPE_CONTEXT (type)) == FUNCTION_DECL)
+    return true;
+
   if (current_class_type
       && !TYPE_BEING_DEFINED (current_class_type)
       && DECL_LANG_SPECIFIC (decl)

Reply via email to