This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
3.4 C++ PATCH: PR 19991
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 2 May 2005 07:47:48 -0700
- Subject: 3.4 C++ PATCH: PR 19991
- Reply-to: mark at codesourcery dot com
This patch backports the fix for PR c++/19991 to the 3.4 branch. The
only change is that the code modified used to be in
decl_constant_value instead of integral_constant_value.
Tested on x86_64-unknown-linux-gnu, applied to the 3.4 branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2005-05-01 Mark Mitchell <mark@codesourcery.com>
Backport:
2005-02-22 Mark Mitchell <mark@codesourcery.com>
PR c++/19991
* init.c (integral_constant_value): Iterate if the value of a decl
is itself a constant.
2005-05-01 Mark Mitchell <mark@codesourcery.com>
Backport:
2005-02-22 Mark Mitchell <mark@codesourcery.com>
PR c++/19991
* g++.dg/parse/constant7.C: New test.
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.356.2.17
diff -c -5 -p -r1.356.2.17 init.c
*** cp/init.c 9 Mar 2005 07:39:15 -0000 1.356.2.17
--- cp/init.c 2 May 2005 14:39:39 -0000
*************** decl_constant_value (tree decl)
*** 1621,1645 ****
return build (COND_EXPR,
TREE_TYPE (decl),
TREE_OPERAND (decl, 0), d1, d2);
}
! if (DECL_P (decl)
! && (/* Enumeration constants are constant. */
! TREE_CODE (decl) == CONST_DECL
! /* And so are variables with a 'const' type -- unless they
! are also 'volatile'. */
! || CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl)))
! && DECL_INITIAL (decl)
! && DECL_INITIAL (decl) != error_mark_node
! /* This is invalid if initial value is not constant.
! If it has either a function call, a memory reference,
! or a variable, then re-evaluating it could give different results. */
! && TREE_CONSTANT (DECL_INITIAL (decl))
! /* Check for cases where this is sub-optimal, even though valid. */
! && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
! return DECL_INITIAL (decl);
return decl;
}
/* Common subroutines of build_new and build_vec_delete. */
--- 1621,1647 ----
return build (COND_EXPR,
TREE_TYPE (decl),
TREE_OPERAND (decl, 0), d1, d2);
}
! while (DECL_P (decl)
! && (/* Enumeration constants are constant. */
! TREE_CODE (decl) == CONST_DECL
! /* And so are variables with a 'const' type -- unless they
! are also 'volatile'. */
! || CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl)))
! && DECL_INITIAL (decl)
! && DECL_INITIAL (decl) != error_mark_node
! /* This is invalid if initial value is not constant. If it
! has either a function call, a memory reference, or a
! variable, then re-evaluating it could give different
! results. */
! && TREE_CONSTANT (DECL_INITIAL (decl))
! /* Check for cases where this is sub-optimal, even though
! valid. */
! && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR)
! decl = DECL_INITIAL (decl);
return decl;
}
/* Common subroutines of build_new and build_vec_delete. */
Index: testsuite/g++.dg/parse/constant7.C
===================================================================
RCS file: testsuite/g++.dg/parse/constant7.C
diff -N testsuite/g++.dg/parse/constant7.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/constant7.C 2 May 2005 14:39:51 -0000
***************
*** 0 ****
--- 1,9 ----
+ // PR c++/19991
+
+ enum { e = 1 };
+
+ template<typename> struct A
+ {
+ static const int i = e;
+ char a[i];
+ };