aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-04-09 21:48:48 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2018-04-09 21:48:48 +0200
commit6e4f1148ce233f2533d56ab20dc002dc1e9a83d7 (patch)
treefaae88665bf0190c1852a3b6d54031e3d88922f6
parent78c3f9becd0e7d918806735d721961afd865d1df (diff)
downloadgcc-6e4f1148ce233f2533d56ab20dc002dc1e9a83d7.zip
gcc-6e4f1148ce233f2533d56ab20dc002dc1e9a83d7.tar.gz
gcc-6e4f1148ce233f2533d56ab20dc002dc1e9a83d7.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/parser.c8
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp43.C14
4 files changed, 31 insertions, 1 deletions
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 <jakub@redhat.com>
+
+ 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 <jason@redhat.com>
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 <jakub@redhat.com>
+ 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 }
+}