From b66ec0c0324bb43f1fe462e7dc21fc14073d69e6 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 6 Jun 2018 13:47:48 -0400 Subject: [PATCH] PR c++/86060 - ICE on range for with -std=c++98. * parser.c (cp_parser_init_statement): Don't clobber *decl after pedwarn. From-SVN: r261239 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/parser.c | 9 +++------ gcc/testsuite/g++.dg/cpp0x/range-for35.C | 8 ++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/range-for35.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index edfa797d20b..f03c9df3d52 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2018-06-06 Jason Merrill + 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. 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 % 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 % 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 void foo(T (&a)[8]) { + for (int i : a) // { dg-warning "range-based" "" { target c++98_only } } + i; +} +void fn1() { foo; } -- 2.30.2