diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2015-09-14 15:25:00 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2015-09-14 15:25:00 +0000 |
commit | 5a0f3af487a4a9d1cd763e91f4221388d7bfed89 (patch) | |
tree | 69e5aa6ae826f63b0db2ae3e060b5297610042ce /gcc | |
parent | f6ba5bb293414a4114a8147b3e7fd38169aacccd (diff) | |
download | gcc-5a0f3af487a4a9d1cd763e91f4221388d7bfed89.zip gcc-5a0f3af487a4a9d1cd763e91f4221388d7bfed89.tar.gz gcc-5a0f3af487a4a9d1cd763e91f4221388d7bfed89.tar.bz2 |
re PR c++/51911 ([C++11] G++ accepts new auto { list })
/cp
2015-09-14 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/51911
* parser.c (cp_parser_new_expression): Enforce 5.3.4/2 (as amended
per the spirit of DR 1467).
/testsuite
2015-09-14 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/51911
* g++.dg/cpp0x/new-auto1.C: New.
From-SVN: r227753
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/new-auto1.C | 10 |
4 files changed, 39 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4101a2e..76e3b91 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-09-14 Paolo Carlini <paolo.carlini@oracle.com> + + PR c++/51911 + * parser.c (cp_parser_new_expression): Enforce 5.3.4/2 (as amended + per the spirit of DR 1467). + 2015-09-11 Mark Wielaard <mjw@redhat.com> PR c/28901 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 64eb5ea..3a68dd7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7591,8 +7591,9 @@ cp_parser_new_expression (cp_parser* parser) type = cp_parser_new_type_id (parser, &nelts); /* 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 %<auto%> " + "requires exactly one element"); + ret = error_mark_node; + } else { /* Create a representation of the new-expression. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a285ee2..0e0f904 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-09-14 Paolo Carlini <paolo.carlini@oracle.com> + + PR c++/51911 + * g++.dg/cpp0x/new-auto1.C: New. + 2015-09-11 Mark Wielaard <mjw@redhat.com> PR c/28901 diff --git a/gcc/testsuite/g++.dg/cpp0x/new-auto1.C b/gcc/testsuite/g++.dg/cpp0x/new-auto1.C new file mode 100644 index 0000000..be09f94 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/new-auto1.C @@ -0,0 +1,10 @@ +// PR c++/51911 +// { dg-do compile { target c++11 } } + +#include <initializer_list> + +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 ); |