]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/86060 - ICE on range for with -std=c++98.
authorJason Merrill <jason@redhat.com>
Tue, 12 Jun 2018 19:53:02 +0000 (15:53 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 12 Jun 2018 19:53:02 +0000 (15:53 -0400)
* parser.c (cp_parser_init_statement): Don't clobber *decl after
pedwarn.

From-SVN: r261523

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

index 2a5f0e0985efbd25f8167f7462a594fa8d3bc580..12758978136ee2341f587f3875f97e5fff92981e 100644 (file)
@@ -1,3 +1,9 @@
+2018-06-12  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.
+
 2018-05-07  Jason Merrill  <jason@redhat.com>
 
        PR c++/85646 - lambda visibility.
index 9a65d94523280632b70d3feedf848dc3f18ab920..7ba1f5317131511887376d7dd17cc3a1a771b221 100644 (file)
@@ -12103,12 +12103,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>; }
index 6a50ec36c14175de8409b631598b061dfe346080..eaa5b4068800959be02026a061f9187839a8c6db 100644 (file)
@@ -5,6 +5,6 @@
 void test()
 {
     int a[] = {0,1,2};
-    for (int x : a)  // { dg-error "range-based 'for'" }
+    for (int x : a)  // { dg-error "range-based 'for'|forming reference" }
         ;
 }