Hi,

On 10/04/2013 03:41 AM, Jason Merrill wrote:
Well, the permerror is saying that with -fpermissive we'll do the lookup again at instantiation time, so a testcase that declares begin/end between the template and the instantiation ought to work?
Ah, now I see! The best approximation we have of a positive test in this context.

Thus the below, lightly tested so far but the tests both pass and the patch itself isn't so different, besides type_dependent_expression_p.

Thanks!
Paolo.

////////////////////////
/cp
2013-10-04  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/58503
        * parser.c (cp_parser_perform_range_for_lookup): If eventually
        either *begin or *end is type-dependent, return NULL_TREE.
        (do_range_for_auto_deduction): If cp_parser_perform_range_for_lookup
        returns NULL_TREE, don't actually do_auto_deduction.

/testsuite
2013-10-04  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/58503
        * g++.dg/cpp0x/range-for26.C: New.
        * g++.dg/cpp0x/range-for27.C: New.
Index: cp/parser.c
===================================================================
--- cp/parser.c (revision 203197)
+++ cp/parser.c (working copy)
@@ -9960,11 +9960,15 @@ do_range_for_auto_deduction (tree decl, tree range
       range_temp = convert_from_reference (build_range_temp (range_expr));
       iter_type = (cp_parser_perform_range_for_lookup
                   (range_temp, &begin_dummy, &end_dummy));
-      iter_decl = build_decl (input_location, VAR_DECL, NULL_TREE, iter_type);
-      iter_decl = build_x_indirect_ref (input_location, iter_decl, RO_NULL,
-                                       tf_warning_or_error);
-      TREE_TYPE (decl) = do_auto_deduction (TREE_TYPE (decl),
-                                           iter_decl, auto_node);
+      if (iter_type)
+       {
+         iter_decl = build_decl (input_location, VAR_DECL, NULL_TREE,
+                                 iter_type);
+         iter_decl = build_x_indirect_ref (input_location, iter_decl, RO_NULL,
+                                           tf_warning_or_error);
+         TREE_TYPE (decl) = do_auto_deduction (TREE_TYPE (decl),
+                                               iter_decl, auto_node);
+       }
     }
 }
 
@@ -10171,6 +10175,11 @@ cp_parser_perform_range_for_lookup (tree range, tr
          *begin = *end = error_mark_node;
          return error_mark_node;
        }
+      else if (type_dependent_expression_p (*begin)
+              || type_dependent_expression_p (*end))
+       /* Can happen, when, eg, in a template context, Koenig lookup
+          can't resolve begin/end (c++/58503).  */
+       return NULL_TREE;
       else
        {
          tree iter_type = cv_unqualified (TREE_TYPE (*begin));
Index: testsuite/g++.dg/cpp0x/range-for26.C
===================================================================
--- testsuite/g++.dg/cpp0x/range-for26.C        (revision 0)
+++ testsuite/g++.dg/cpp0x/range-for26.C        (working copy)
@@ -0,0 +1,7 @@
+// PR c++/58503
+// { dg-require-effective-target c++11 }
+
+template<int> void foo()
+{
+  for (auto i : 0) {}  // { dg-error "there are no arguments" }
+}
Index: testsuite/g++.dg/cpp0x/range-for27.C
===================================================================
--- testsuite/g++.dg/cpp0x/range-for27.C        (revision 0)
+++ testsuite/g++.dg/cpp0x/range-for27.C        (working copy)
@@ -0,0 +1,15 @@
+// PR c++/58503
+// { dg-require-effective-target c++11 }
+// { dg-options "-fpermissive -w" }
+
+struct c { };
+
+template<int> void foo()
+{
+  for (auto i : c()) { }
+}
+
+c* begin(const c&);
+c* end(const c&);
+
+template void foo<1>(); 

Reply via email to