This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/86060, c++98 ICE with range for
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 6 Jun 2018 19:47:14 +0200
- Subject: C++ PATCH for c++/86060, c++98 ICE with range for
If we're going to allow it with a pedwarn, we shouldn't clobber the
decl with an error_mark_node.
Tested x86_64-pc-linux-gnu, applying to trunk and 8.
commit ee298d715781a806980f93348ba1b0afd62187db
Author: Jason Merrill <jason@redhat.com>
Date: Wed Jun 6 17:21:42 2018 +0200
PR c++/86060 - ICE on range for with -std=c++98.
* parser.c (cp_parser_init_statement): Don't clobber *decl after
pedwarn.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 03aea2f1150..edb0ef8025e 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -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
index 00000000000..c77a5af5a44
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/range-for35.C
@@ -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>; }