This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Mon, Nov 20, 2006 at 12:53:43PM -0800, Mark Mitchell wrote:
> Jakub Jelinek wrote:
> 
> > This is the [dcl.init]/13 case, scalar initialized with { val }
> > which is equivalent to val initializer.  And, val in this case
> > (A<N>::i) is constant expression.
> > Perhaps it is enough just to check for a single elt CONSTRUCTOR
> > in cp_finish_decl and see if it is value_dependent_expression_p.
> 
> Yes, I think that would be better.

Like this?
Ok for 4.1/4.2/4.3?

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

	PR c++/29570
	* decl.c (cp_finish_decl): Check for value dependent brace enclosed
	scalar initializer.

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

--- gcc/cp/decl.c.jj	2006-11-20 21:11:41.000000000 +0100
+++ gcc/cp/decl.c	2006-11-20 23:12:57.000000000 +0100
@@ -5058,7 +5058,14 @@ cp_finish_decl (tree decl, tree init, bo
 	  || !DECL_CLASS_SCOPE_P (decl)
 	  || !DECL_INTEGRAL_CONSTANT_VAR_P (decl)
 	  || type_dependent_p
-	  || value_dependent_expression_p (init))
+	  || value_dependent_expression_p (init)
+	     /* Check also if initializer is a value dependent
+		{ integral_constant_expression }.  */
+	  || (TREE_CODE (init) == CONSTRUCTOR
+	      && VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init)) == 1
+	      && value_dependent_expression_p
+		   (VEC_index (constructor_elt,
+			       CONSTRUCTOR_ELTS (init), 0)->value)))
 	{
 	  if (init)
 	    DECL_INITIAL (decl) = init;
--- gcc/testsuite/g++.dg/template/static29.C.jj	2006-11-20 22:46:35.000000000 +0100
+++ gcc/testsuite/g++.dg/template/static29.C	2006-11-20 22:46:35.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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]