re PR c++/53211 (range-based 'for' expression of type 'const int []' has incomplete...
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 18 Jun 2013 22:20:10 +0000 (22:20 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 18 Jun 2013 22:20:10 +0000 (22:20 +0000)
/cp
2013-06-18  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/53211
* pt.c (type_dependent_expression_p): Handle an array of unknown
bound depending on a variadic parameter.
* parser.c (cp_parser_range_for): Revert PR56794 changes.

/testsuite
2013-06-18  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/53211
* g++.dg/cpp0x/decltype55.C: New.

From-SVN: r200178

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

index 1b58ba00f4b59cae7f118121eb1d34e734f2db26..7e25e5253745b0881d96bb067eaaf88521b9525e 100644 (file)
@@ -1,3 +1,10 @@
+2013-06-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/53211
+       * pt.c (type_dependent_expression_p): Handle an array of unknown
+       bound depending on a variadic parameter.
+       * parser.c (cp_parser_range_for): Revert PR56794 changes.
+
 2013-06-17  Richard Biener  <rguenther@suse.de>
 
        * cp-tree.h (ANON_AGGRNAME_FORMAT, ANON_AGGRNAME_P): Move to tree.h.
index d844d1553a024a8beffd15505bc3b8196f59687b..904ae0b8003406077f352e989be950e13b95b879 100644 (file)
@@ -9750,10 +9750,7 @@ 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 (range_expr != error_mark_node
-         && !type_dependent_expression_p (range_expr)
-         /* The length of an array might be dependent.  */
-         && COMPLETE_TYPE_P (complete_type (TREE_TYPE (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);
index 3602fcd2dd8fadc60095f152143dcaef9ae809f1..25cbf3100cf1172df557c1f1ce2e0c79e1c519f3 100644 (file)
@@ -20079,6 +20079,29 @@ type_dependent_expression_p (tree expression)
       && VAR_HAD_UNKNOWN_BOUND (expression))
     return true;
 
+  /* An array of unknown bound depending on a variadic parameter, eg:
+
+     template<typename... Args>
+       void foo (Args... args)
+       {
+         int arr[] = { args... };
+       }
+
+     template<int... vals>
+       void bar ()
+       {
+         int arr[] = { vals... };
+       }
+
+     If the array has no length and has an initializer, it must be that
+     we couldn't determine its length in cp_complete_array_type because
+     it is dependent.  */
+  if (VAR_P (expression)
+      && TREE_CODE (TREE_TYPE (expression)) == ARRAY_TYPE
+      && !TYPE_DOMAIN (TREE_TYPE (expression))
+      && DECL_INITIAL (expression))
+   return true;
+
   if (TREE_TYPE (expression) == unknown_type_node)
     {
       if (TREE_CODE (expression) == ADDR_EXPR)
index 743ae6c4fe4ae86b3b06c1abc0b22c6c0c20dfaf..53b844f62da99f55b2b353f628ad57c9125c0f9a 100644 (file)
@@ -1,3 +1,8 @@
+2013-06-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/53211
+       * g++.dg/cpp0x/decltype55.C: New.
+
 2013-06-18  Marek Polacek  <polacek@redhat.com>
 
        * gcc.dg/c90-fordecl-1.c: Adjust expected message.
        * c-c++-common/cilk-plus/AN/sec_reduce_ind_same_value.c: New test.
 
 2013-06-17  Balaji V. Iyer  <balaji.v.iyer@intel.com>
-       
+
        * c-c++-common/cilk-plus/AN/array_test1.c: Make this an execution test.
        Also changed the returns from error as distinct values so that it is
        easier to debug.
-       
+
 2013-06-17  Sofiane Naci  <sofiane.naci@arm.com>
 
        * gcc.target/aarch64/scalar_intrinsics.c: Update.
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype55.C b/gcc/testsuite/g++.dg/cpp0x/decltype55.C
new file mode 100644 (file)
index 0000000..95427fc
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/53211
+// { dg-do compile { target c++11 } }
+
+template<typename A, typename B>
+  struct is_same { static const bool value = false; };
+
+template<typename A>
+  struct is_same<A, A> { static const bool value = true; };
+
+template<typename... Args>
+void func(Args... args)
+{
+  int arr[] = { args... };
+  static_assert (is_same<decltype(arr), int[sizeof...(Args)]>::value, "");
+}
+
+int main()
+{
+  func(1, 2, 3, 4);
+}