re PR c++/56794 (C++11 Error in range-based for with parameter pack array)
authorJason Merrill <jason@redhat.com>
Mon, 1 Apr 2013 21:18:05 +0000 (17:18 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 1 Apr 2013 21:18:05 +0000 (17:18 -0400)
PR c++/56794
* parser.c (cp_parser_range_for): Don't try to do auto deduction
in a template if the type of the range is incomplete.

From-SVN: r197324

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp0x/range-for24.C [new file with mode: 0644]

index ac22dc2344520f94cde05009949860d4bd2fa5bd..c7e140ed579f1d5a695a1647156719fdf2c121c9 100644 (file)
@@ -1,5 +1,9 @@
 2013-04-01  Jason Merrill  <jason@redhat.com>
 
+       PR c++/56794
+       * parser.c (cp_parser_range_for): Don't try to do auto deduction
+       in a template if the type of the range is incomplete.
+
        * call.c (add_function_candidate): Take the address of 'this' here.
        (build_over_call): And here.
        (build_new_method_call_1, build_op_call_1): Not here.
index f29e80db7c5306c3ad589c9f0a4c83b73bca99e0..05c03f45d27c658a24654efb0ca997e8f33ffa23 100644 (file)
@@ -9615,7 +9615,10 @@ cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl)
        range_expr = error_mark_node;
       stmt = begin_range_for_stmt (scope, init);
       finish_range_for_decl (stmt, range_decl, range_expr);
-      if (!type_dependent_expression_p (range_expr)
+      if (range_expr != error_mark_node
+         && !type_dependent_expression_p (range_expr)
+         /* The length of an array might be dependent.  */
+         && COMPLETE_TYPE_P (TREE_TYPE (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);
diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for24.C b/gcc/testsuite/g++.dg/cpp0x/range-for24.C
new file mode 100644 (file)
index 0000000..b4a5b18
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/56794
+// { dg-require-effective-target c++11 }
+
+template<int... values>
+static void Colors()
+{
+    static const int colors[] = { values... };
+
+    for(auto c: colors) { }
+}
+
+int main()
+{
+    Colors<0,1,2> ();
+}