re PR c++/85194 (ICE with structured binding in broken for-loop)
authorJakub Jelinek <jakub@redhat.com>
Mon, 9 Apr 2018 19:48:48 +0000 (21:48 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 9 Apr 2018 19:48:48 +0000 (21:48 +0200)
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

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1z/decomp43.C [new file with mode: 0644]

index c375155..deac522 100644 (file)
@@ -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.
index 0ffa13d..9c8a886 100644 (file)
@@ -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
          {
index 414ff42..21914df 100644 (file)
@@ -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 (file)
index 0000000..ab917b4
--- /dev/null
@@ -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 }
+}