From: Jakub Jelinek Date: Mon, 9 Apr 2018 19:48:48 +0000 (+0200) Subject: re PR c++/85194 (ICE with structured binding in broken for-loop) X-Git-Tag: upstream/12.2.0~32422 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6e4f1148ce233f2533d56ab20dc002dc1e9a83d7;p=platform%2Fupstream%2Fgcc.git re PR c++/85194 (ICE with structured binding in broken for-loop) PR c++/85194 * parser.c (cp_parser_simple_declaration): For structured bindings, if *maybe_range_for_decl is NULL after parsing it, set it to error_mark_node. * g++.dg/cpp1z/decomp43.C: New test. From-SVN: r259252 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c375155..deac522 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-04-09 Jakub Jelinek + + PR c++/85194 + * parser.c (cp_parser_simple_declaration): For structured bindings, + if *maybe_range_for_decl is NULL after parsing it, set it to + error_mark_node. + 2018-04-09 Jason Merrill PR c++/85256 - ICE capturing pointer to VLA. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 0ffa13d..9c8a886 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -12983,8 +12983,14 @@ cp_parser_simple_declaration (cp_parser* parser, /* The next token should be either a `,' or a `;'. */ cp_token *token = cp_lexer_peek_token (parser->lexer); /* If it's a `;', we are done. */ - if (token->type == CPP_SEMICOLON || maybe_range_for_decl) + if (token->type == CPP_SEMICOLON) goto finish; + else if (maybe_range_for_decl) + { + if (*maybe_range_for_decl == NULL_TREE) + *maybe_range_for_decl = error_mark_node; + goto finish; + } /* Anything else is an error. */ else { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 414ff42..21914df 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2018-04-09 Jakub Jelinek + PR c++/85194 + * g++.dg/cpp1z/decomp43.C: New test. + PR rtl-optimization/80463 * g++.dg/pr80463.C: Add -w to dg-options. diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp43.C b/gcc/testsuite/g++.dg/cpp1z/decomp43.C new file mode 100644 index 0000000..ab917b4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp43.C @@ -0,0 +1,14 @@ +// PR c++/85194 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +struct A { int i; }; + +A x[2]; + +void +foo () +{ + for (auto [i] = A () : x) // { dg-error "initializer in range-based 'for' loop" } + ; // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } +}