backport: re PR c++/81258 (ICE on C++1z code with invalid decomposition declaration: in cp_finish_decl, at cp/decl.c:6760)

Backported from mainline
	2017-07-04  Jakub Jelinek  <jakub@redhat.com>

	PR c++/81258
	* parser.c (cp_parser_decomposition_declaration): Diagnose invalid
	forms of structured binding initializers.

	* g++.dg/cpp1z/decomp21.C (foo): Adjust expected diagnostics.
	* g++.dg/cpp1z/decomp30.C: New test.

From-SVN: r250286
This commit is contained in:
Jakub Jelinek 2017-07-17 21:39:23 +02:00 committed by Jakub Jelinek
parent fc28766c1a
commit 96a0e28758
5 changed files with 39 additions and 1 deletions

View File

@ -1,3 +1,12 @@
2017-07-17 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
2017-07-04 Jakub Jelinek <jakub@redhat.com>
PR c++/81258
* parser.c (cp_parser_decomposition_declaration): Diagnose invalid
forms of structured binding initializers.
2017-07-06 Jason Merrill <jason@redhat.com>
PR c++/81204 - parse error with dependent template-name

View File

@ -13045,6 +13045,16 @@ cp_parser_decomposition_declaration (cp_parser *parser,
*init_loc = cp_lexer_peek_token (parser->lexer)->location;
tree initializer = cp_parser_initializer (parser, &is_direct_init,
&non_constant_p);
if (initializer == NULL_TREE
|| (TREE_CODE (initializer) == TREE_LIST
&& TREE_CHAIN (initializer))
|| (TREE_CODE (initializer) == CONSTRUCTOR
&& CONSTRUCTOR_NELTS (initializer) != 1))
{
error_at (loc, "invalid initializer for structured binding "
"declaration");
initializer = error_mark_node;
}
if (decl != error_mark_node)
{

View File

@ -1,6 +1,12 @@
2017-07-17 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
2017-07-04 Jakub Jelinek <jakub@redhat.com>
PR c++/81258
* g++.dg/cpp1z/decomp21.C (foo): Adjust expected diagnostics.
* g++.dg/cpp1z/decomp30.C: New test.
2017-06-30 Jakub Jelinek <jakub@redhat.com>
PR target/81225

View File

@ -12,5 +12,6 @@ foo ()
auto [ n, o, p ] { a };
auto [ q, r, t ] ( s );
auto [ u, v, w ] ( s, ); // { dg-error "expected primary-expression before '.' token" }
auto [ x, y, z ] ( a ); // { dg-error "expression list treated as compound expression in initializer" "" { target *-*-* } .-1 }
// { dg-error "invalid initializer for structured binding declaration" "" { target *-*-* } .-1 }
auto [ x, y, z ] ( a );
}

View File

@ -0,0 +1,12 @@
// PR c++/81258
// { dg-options -std=c++1z }
int a[2];
auto [b, c] (a);
auto [d, e] { a };
auto [f, g] = a;
auto [h, i] ( a, a ); // { dg-error "invalid initializer for structured binding declaration" }
auto [j, k] { a, a }; // { dg-error "invalid initializer for structured binding declaration" }
auto [l, m] = { a }; // { dg-error "deducing from brace-enclosed initializer list requires" }
auto [n, o] {}; // { dg-error "invalid initializer for structured binding declaration" }
auto [p, q] (); // { dg-error "invalid initializer for structured binding declaration" }