[C++ PATCH] Handle CONSTRUCTOR in value_dependent_expression_p (PR c++/29570)

Jakub Jelinek jakub@redhat.com
Mon Nov 20 16:42:00 GMT 2006


Hi!

Since PR c++/27819 cp_finish_decl calls value_dependent_expression_p
on the initializer.  But when init is a CONSTRUCTOR,
value_dependent_expression_p returns false, doesn't even look into
it, even when the constructor contains value dependent expressions.
The following patch fixes this by handling CONSTRUCTOR in
value_dependent_expression_p.  Alternatively, cp_finish_decl
could call a special function which would handle CONSTRUCTOR case
(in that case recurse on each of the elements) and for all other
tree codes just return value_dependent_expression_p.

2006-11-20  Jakub Jelinek  <jakub@redhat.com>

	PR c++/29570
	* pt.c (value_dependent_expression_p): Handle CONSTRUCTOR.

	* g++.dg/template/static29.C: New test.

--- gcc/cp/pt.c.jj	2006-11-20 11:32:28.000000000 +0100
+++ gcc/cp/pt.c	2006-11-20 16:47:30.000000000 +0100
@@ -12892,6 +12892,16 @@ value_dependent_expression_p (tree expre
 	 such calls are value-dependent.  */
       return true;
 
+    case CONSTRUCTOR:
+      {
+	unsigned HOST_WIDE_INT idx;
+	tree value;
+	FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expression), idx, value)
+	  if (value_dependent_expression_p (value))
+	    return true;
+	return false;
+      }
+
     default:
       /* A constant expression is value-dependent if any subexpression is
 	 value-dependent.  */
--- gcc/testsuite/g++.dg/template/static29.C.jj	2006-11-20 17:06:27.000000000 +0100
+++ gcc/testsuite/g++.dg/template/static29.C	2006-11-20 17:06:23.000000000 +0100
@@ -0,0 +1,5 @@
+// PR c++/29570
+
+template<int> struct A { static const int i; };
+
+template<int N> const int A<N>::i = { A<N>::i };

	Jakub



More information about the Gcc-patches mailing list