Patchwork C++ PATCH for c++/49983 (range-for/auto regression)

login
register
mail settings
Submitter Jason Merrill
Date Aug. 5, 2011, 7:19 p.m.
Message ID <4E3C423E.5020708@redhat.com>
Download mbox | patch
Permalink /patch/108716/
State New
Headers show

Comments

Jason Merrill - Aug. 5, 2011, 7:19 p.m.
We can only do range for deduction if the range expression is non-dependent.

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

Patch

commit 2515fd89aeb268d395242d6ef3137da7119fdce8
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Aug 5 10:16:58 2011 -0400

    	PR c++/49983
    	* parser.c (cp_parser_range_for): Only do auto deduction in
    	template if the range is non-dependent.

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 9b3e56d..84b8c60 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -8679,7 +8679,8 @@  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);
-      do_range_for_auto_deduction (range_decl, range_expr);
+      if (!type_dependent_expression_p (range_expr))
+	do_range_for_auto_deduction (range_decl, range_expr);
     }
   else
     {
diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for21.C b/gcc/testsuite/g++.dg/cpp0x/range-for21.C
new file mode 100644
index 0000000..07bb95f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/range-for21.C
@@ -0,0 +1,8 @@ 
+// PR c++/49983
+// { dg-options -std=c++0x }
+
+template <class T>
+void f(T t)
+{
+  for (auto v : t);
+}