PR c++/86060 - ICE on range for with -std=c++98.
authorJason Merrill <jason@redhat.com>
Wed, 6 Jun 2018 17:47:48 +0000 (13:47 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 6 Jun 2018 17:47:48 +0000 (13:47 -0400)
* parser.c (cp_parser_init_statement): Don't clobber *decl after
pedwarn.

From-SVN: r261239

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp0x/range-for35.C [new file with mode: 0644]

index edfa797d20b6878e36565cd5023717046cae46e8..f03c9df3d52df6e25566097f132800a2457d67c0 100644 (file)
@@ -1,5 +1,9 @@
 2018-06-06  Jason Merrill  <jason@redhat.com>
 
+       PR c++/86060 - ICE on range for with -std=c++98.
+       * parser.c (cp_parser_init_statement): Don't clobber *decl after
+       pedwarn.
+
        PR c++/85710 - ICE with -Wmemset-elt-size.
        * semantics.c (finish_call_expr): Call warn_for_memset here.
        * parser.c (cp_parser_postfix_expression): Not here.
index 03aea2f11507fb74254f79211c5168f1a0eb6d0c..edb0ef8025ef431a8335289a6db9a4182b15fabc 100644 (file)
@@ -12384,12 +12384,9 @@ cp_parser_init_statement (cp_parser *parser, tree *decl)
          cp_lexer_consume_token (parser->lexer);
          is_range_for = true;
          if (cxx_dialect < cxx11)
-           {
-             pedwarn (cp_lexer_peek_token (parser->lexer)->location, 0,
-                      "range-based %<for%> loops only available with "
-                      "-std=c++11 or -std=gnu++11");
-             *decl = error_mark_node;
-           }
+           pedwarn (cp_lexer_peek_token (parser->lexer)->location, 0,
+                    "range-based %<for%> loops only available with "
+                    "-std=c++11 or -std=gnu++11");
        }
       else
        /* The ';' is not consumed yet because we told
diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for35.C b/gcc/testsuite/g++.dg/cpp0x/range-for35.C
new file mode 100644 (file)
index 0000000..c77a5af
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/86060
+// { dg-options -Wpedantic }
+
+template <typename T> void foo(T (&a)[8]) {
+  for (int i : a)              // { dg-warning "range-based" "" { target c++98_only } }
+    i;
+}
+void fn1() { foo<int>; }