Patchwork C++ PATCH for rejects-valid with C++11 range for

login
register
mail settings
Submitter Jason Merrill
Date Oct. 3, 2011, 4:29 a.m.
Message ID <4E893A43.3040003@redhat.com>
Download mbox | patch
Permalink /patch/117401/
State New
Headers show

Comments

Jason Merrill - Oct. 3, 2011, 4:29 a.m.
The range for code tries to do type deduction for the range for 
variables when the initializer isn't type dependent, but we don't do 
auto deduction from an initializer-list, so we shouldn't try to do that 
for range for, either; if we do we end up complaining about an 
incomplete type.

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

Patch

commit f65c4d83c5cdd2bff213e4a7cd90258a2e0f4969
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Oct 2 22:53:54 2011 -0400

    	* parser.c (cp_parser_range_for): Don't try to deduce from {}
    	in a template.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 83d7b71..cabe9aa 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -8688,7 +8688,9 @@  cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl)
     {
       stmt = begin_range_for_stmt (scope, init);
       finish_range_for_decl (stmt, range_decl, range_expr);
-      if (!type_dependent_expression_p (range_expr))
+      if (!type_dependent_expression_p (range_expr)
+	  /* do_auto_deduction doesn't mess with template init-lists.  */
+	  && !BRACE_ENCLOSED_INITIALIZER_P (range_expr))
 	do_range_for_auto_deduction (range_decl, range_expr);
     }
   else
diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for22.C b/gcc/testsuite/g++.dg/cpp0x/range-for22.C
new file mode 100644
index 0000000..5fef5e6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/range-for22.C
@@ -0,0 +1,5 @@ 
+// { dg-options -std=c++0x }
+
+template<int I> void f() {
+  for (auto i: {I} );
+}