Patchwork [C++] PR 53624

login
register
mail settings
Submitter Paolo Carlini
Date July 30, 2012, 10:26 p.m.
Message ID <50170A22.7050200@oracle.com>
Download mbox | patch
Permalink /patch/174115/
State New
Headers show

Comments

Paolo Carlini - July 30, 2012, 10:26 p.m.
Hi,

On 07/30/2012 10:10 PM, Jason Merrill wrote:
> On 07/28/2012 11:28 AM, Paolo Carlini wrote:
>> 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.
>
> It seems to me that the problem here is that the template parameters 
> in question are for an enclosing scope, not the temploid under 
> consideration.
Indeed, this is the problem.
>   We shouldn't be doing the default argument ordering check (or the 
> parameter pack order check) at all for non-primary templates.
Good, thanks. I didn't realize that we can use is_primary. Thus for 
example the below passes testing: is it Ok or we can implement the 
general idea in a different way?

Thanks!
Paolo.

////////////////////////
Jason Merrill - July 30, 2012, 10:42 p.m.
On 07/30/2012 06:26 PM, Paolo Carlini wrote:
> +  if ((cxx_dialect == cxx98)
> +      || (TREE_CODE (decl) != FUNCTION_DECL && is_primary))

We shouldn't do this check for non-primary templates in C++98 mode, either.

Jason

Patch

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 189981)
+++ cp/pt.c	(working copy)
@@ -4267,7 +4267,8 @@  check_default_tmpl_args (tree decl, tree parms, in
 
   /* Core issue 226 (C++0x only): the following only applies to class
      templates.  */
-  if ((cxx_dialect == cxx98) || TREE_CODE (decl) != FUNCTION_DECL)
+  if ((cxx_dialect == cxx98)
+      || (TREE_CODE (decl) != FUNCTION_DECL && is_primary))
     {
       /* [temp.param]