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 c3751551517684b1a9141192977f9ca2246df750..deac522534b8633fa5a6732cc72ffa29c44b3672 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 0ffa13de5376d1252e30f273378497ae55c97cd0..9c8a886e8380ff5a1b0ab4006f5c4cf61fa6edac 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 414ff4285cfed4f50bd2d509362dd691bf8906ef..21914dff5045e64d1d757519f6cedad0dd619279 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 }
+}