Hi,

while triaging this PR (the original issue is already fixed) Jonathan added to the audit trail the attached testcase, which we are still mishandling. It seems to me that something is wrong in instantiation_dependent_expression_p: when finish_decltype_type is called the first time by the parser, and calls in turns instantiation_dependent_expression_p on the VAR_DECL arr, it returns *false*, whereas of course the type of arr, as far as the number of elements is concerned, depends on the actual variadic Args. Thus I tried the patchlet below, which works, but I'm not sure if it's papering over a deeper issue, or, in case the approach makes sense in general, whether the check should be tweaked somehow. It's what I have at the moment, anyway...

Thanks!
Paolo.

//////////////////////
Index: cp/pt.c
===================================================================
--- cp/pt.c     (revision 200151)
+++ cp/pt.c     (working copy)
@@ -20148,6 +20148,11 @@ instantiation_dependent_r (tree *tp, int *walk_sub
       return NULL_TREE;
 
     case VAR_DECL:
+      if (TREE_CODE (TREE_TYPE (*tp)) == ARRAY_TYPE
+         && !TYPE_DOMAIN (TREE_TYPE (*tp))
+         && DECL_INITIAL (*tp)
+         && type_dependent_expression_p (DECL_INITIAL (*tp)))
+       return *tp;
     case CONST_DECL:
       /* A constant with a dependent initializer is dependent.  */
       if (value_dependent_expression_p (*tp))
Index: testsuite/g++.dg/cpp0x/decltype55.C
===================================================================
--- testsuite/g++.dg/cpp0x/decltype55.C (revision 0)
+++ testsuite/g++.dg/cpp0x/decltype55.C (working copy)
@@ -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);
+}

Reply via email to