From 3fdb885199d6c52f584aefd9cc1bfa4b3380f97a Mon Sep 17 00:00:00 2001
From: Jason Merrill <jason@redhat.com>
Date: Fri, 24 Sep 2010 11:13:19 -0400
Subject: [PATCH] decl.c (compute_array_index_type): Remember type dependence
 of array bound.

	* decl.c (compute_array_index_type): Remember type dependence of
	array bound.
	* pt.c (dependent_type_p_r): Don't recompute it here.

From-SVN: r164598
---
 gcc/cp/ChangeLog |  4 ++++
 gcc/cp/decl.c    | 16 +++++++++++++---
 gcc/cp/pt.c      | 13 ++++---------
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index f457d0cf019d..0e2d2fb2326f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
 2010-09-24  Jason Merrill  <jason@redhat.com>
 
+	* decl.c (compute_array_index_type): Remember type dependence of
+	array bound.
+	* pt.c (dependent_type_p_r): Don't recompute it here.
+
 	* error.c (dump_expr) [CASE_CONVERT]: Print conversion between
 	reference and pointer to the same type as "*" or "&".
 
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3d1420a23ebe..6a444822c167 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7402,11 +7402,15 @@ compute_array_index_type (tree name, tree size)
       type = TREE_TYPE (size);
     }
 
+  /* A type is dependent if it is...an array type constructed from any
+     dependent type or whose size is specified by a constant expression
+     that is value-dependent.  */
   /* We can only call value_dependent_expression_p on integral constant
      expressions; the parser adds a dummy NOP_EXPR with TREE_SIDE_EFFECTS
      set if this isn't one.  */
   if (processing_template_decl
-      && (TREE_SIDE_EFFECTS (size) || value_dependent_expression_p (size)))
+      && (dependent_type_p (type)
+	  || TREE_SIDE_EFFECTS (size) || value_dependent_expression_p (size)))
     {
       /* We cannot do any checking for a SIZE that isn't known to be
 	 constant. Just build the index type and mark that it requires
@@ -7532,10 +7536,16 @@ compute_array_index_type (tree name, tree size)
     {
       tree t = build_index_type (itype);
       TYPE_CANONICAL (abi_1_itype) = TYPE_CANONICAL (t);
-      return abi_1_itype;
+      itype = abi_1_itype;
     }
   else
-    return build_index_type (itype);
+    itype = build_index_type (itype);
+
+  /* If the index type were dependent, we would have returned early, so
+     remember that it isn't.  */
+  TYPE_DEPENDENT_P (itype) = 0;
+  TYPE_DEPENDENT_P_VALID (itype) = 1;
+  return itype;
 }
 
 /* Returns the scope (if any) in which the entity declared by
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 5a90bdc6eadf..f5e09ee17572 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -17479,7 +17479,10 @@ dependent_type_p_r (tree type)
     }
   /* -- an array type constructed from any dependent type or whose
 	size is specified by a constant expression that is
-	value-dependent.  */
+	value-dependent.
+
+        We checked for type- and value-dependence of the bounds in
+        compute_array_index_type, so TYPE_DEPENDENT_P is already set.  */
   if (TREE_CODE (type) == ARRAY_TYPE)
     {
       if (TYPE_DOMAIN (type)
@@ -17487,14 +17490,6 @@ dependent_type_p_r (tree type)
 	return true;
       return dependent_type_p (TREE_TYPE (type));
     }
-  else if (TREE_CODE (type) == INTEGER_TYPE
-	   && !TREE_CONSTANT (TYPE_MAX_VALUE (type)))
-    {
-      /* If this is the TYPE_DOMAIN of an array type, consider it
-	 dependent.  We already checked for value-dependence in
-	 compute_array_index_type.  */
-      return type_dependent_expression_p (TYPE_MAX_VALUE (type));
-    }
 
   /* -- a template-id in which either the template name is a template
      parameter ...  */
-- 
GitLab