Re: [C++ Patch] PR 51911 V2 ("G++ accepts new auto { list }")
... concretely, I tested successfully the below. Thanks, Paolo. Index: cp/parser.c === --- cp/parser.c (revision 227737) +++ cp/parser.c (working copy) @@ -7591,8 +7591,9 @@ cp_parser_new_expression (cp_parser* parser) type = cp_parser_new_type_id (parser, ); /* If the next token is a `(' or '{', then we have a new-initializer. */ - if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN) - || cp_lexer_next_token_is (parser->lexer, CPP_OPEN_BRACE)) + cp_token *token = cp_lexer_peek_token (parser->lexer); + if (token->type == CPP_OPEN_PAREN + || token->type == CPP_OPEN_BRACE) initializer = cp_parser_new_initializer (parser); else initializer = NULL; @@ -7601,6 +7602,21 @@ cp_parser_new_expression (cp_parser* parser) expression. */ if (cp_parser_non_integral_constant_expression (parser, NIC_NEW)) ret = error_mark_node; + /* 5.3.4/2: "If the auto type-specifier appears in the type-specifier-seq + of a new-type-id or type-id of a new-expression, the new-expression shall + contain a new-initializer of the form ( assignment-expression )". + Additionally, consistently with the spirit of DR 1467, we want to accept + 'new auto { 2 }' too. */ + else if (type_uses_auto (type) + && (vec_safe_length (initializer) != 1 + || (BRACE_ENCLOSED_INITIALIZER_P ((*initializer)[0]) + && CONSTRUCTOR_NELTS ((*initializer)[0]) != 1))) +{ + error_at (token->location, + "initialization of new-expression for type %" + "requires exactly one element"); + ret = error_mark_node; +} else { /* Create a representation of the new-expression. */ Index: testsuite/g++.dg/cpp0x/new-auto1.C === --- testsuite/g++.dg/cpp0x/new-auto1.C (revision 0) +++ testsuite/g++.dg/cpp0x/new-auto1.C (working copy) @@ -0,0 +1,10 @@ +// PR c++/51911 +// { dg-do compile { target c++11 } } + +#include + +auto foo1 = new auto { 3, 4, 5 }; // { dg-error "22:initialization of new-expression for type 'auto'" } +auto bar1 = new auto { 2 }; + +auto foo2 = new auto ( 3, 4, 5 ); // { dg-error "22:initialization of new-expression for type 'auto'" } +auto bar2 = new auto ( 2 );
Re: [C++ Patch] PR 51911 V2 ("G++ accepts new auto { list }")
OK. Jason
Re: [C++ Patch] PR 51911 V2 ("G++ accepts new auto { list }")
Hi, On 09/11/2015 10:05 PM, Jason Merrill wrote: On 09/11/2015 03:11 PM, Paolo Carlini wrote: this is a slightly reworked (simplified) version of a patch I sent a while ago. The issue is that we are not enforcing at all 5.3.4/2 in the parser, thus we end up rejecting the first test below with a misleading error message talking about list-initialization (and a wrong location), because we diagnose it too late like 'auto foo{3, 4, 5};', and simply accepting the second. Tested x86_64-linux. Hmm, I think we really ought to accept new auto { 2 } to be consistent with all the other recent changes to treat { elt } like (elt); this seems like a piece that was missed from DR 1467. Do you agree, Ville? I see, while waiting for Ville, maybe I can ask what we should do in case he agrees. The error message we currently emit for new auto { 3, 4, 5 } seems suboptimal in various ways: 51911.C:6:31: error: direct-list-initialization of ‘auto’ requires exactly one element [-fpermissive] auto foo = new auto { 3, 4, 5 }; ^ 51911.C:6:31: note: for deduction to ‘std::initializer_list’, use copy-list-initialization (i.e. add ‘=’ before the ‘{’) the caret is under the last '}' and the note doesn't make much sense (of course do_auto_deduction doesn't know we are handling a new). Thus I wonder if we should anyway have something in the parser and with which exact wording (just tweak what I sent earlier replacing 'exactly one parenthesized expression' with 'exactly one element'?!?) Thanks, Paolo.
Re: [C++ Patch] PR 51911 V2 ("G++ accepts new auto { list }")
On 11 September 2015 at 23:05, Jason Merrillwrote: > Hmm, I think we really ought to accept > > new auto { 2 } > > to be consistent with all the other recent changes to treat { elt } like > (elt); this seems like a piece that was missed from DR 1467. Do you agree, > Ville? Yes. I thought we already accept it.
Re: [C++ Patch] PR 51911 V2 ("G++ accepts new auto { list }")
On 09/11/2015 03:11 PM, Paolo Carlini wrote: this is a slightly reworked (simplified) version of a patch I sent a while ago. The issue is that we are not enforcing at all 5.3.4/2 in the parser, thus we end up rejecting the first test below with a misleading error message talking about list-initialization (and a wrong location), because we diagnose it too late like 'auto foo{3, 4, 5};', and simply accepting the second. Tested x86_64-linux. Hmm, I think we really ought to accept new auto { 2 } to be consistent with all the other recent changes to treat { elt } like (elt); this seems like a piece that was missed from DR 1467. Do you agree, Ville? Jason