diff mbox

C++ PATCH to implement N3994 (range-based for: the next generation)

Message ID 53AC6302.70300@redhat.com
State New
Headers show

Commit Message

Jason Merrill June 26, 2014, 6:14 p.m. UTC
N3994 proposes that people writing a range-based for should be able to 
leave out the type and have it default to auto&&.  I expect the proposal 
to be voted into the working paper at the November standards meeting.

The second patch changes the existing range-for diagnostic from error to 
pedwarn, for consistency with other C++11 features.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 90ba192ca14292be71459b1ca8a85aadfe9832e1
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jun 26 13:26:35 2014 -0400

    	* parser.c (cp_parser_for_init_statement): Change range-for error
    	to pedwarn.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 426dca4..a7edd41 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -10647,9 +10647,9 @@  cp_parser_for_init_statement (cp_parser* parser, tree *decl)
 	  is_range_for = true;
 	  if (cxx_dialect < cxx11)
 	    {
-	      error_at (cp_lexer_peek_token (parser->lexer)->location,
-			"range-based %<for%> loops are not allowed "
-			"in C++98 mode");
+	      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;
 	    }
 	}
diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for9.C b/gcc/testsuite/g++.dg/cpp0x/range-for9.C
index c51cbf9..6a50ec3 100644
--- a/gcc/testsuite/g++.dg/cpp0x/range-for9.C
+++ b/gcc/testsuite/g++.dg/cpp0x/range-for9.C
@@ -1,7 +1,6 @@ 
 // Test for range-based for loop error in C++98 mode
 
-// { dg-do compile }
-// { dg-options "-std=c++98" }
+// { dg-do compile { target { ! c++11 } } }
 
 void test()
 {