This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 8227
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 30 Nov 2002 20:53:56 -0800
- Subject: C++ PATCH: PR 8227
- Reply-to: mark at codesourcery dot com
This patch fixes PR 8227.
Tested on i686-pc-linux-gnu, applied on the mainline.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2002-11-30 Mark Mitchell <mark@codesourcery.com>
PR c++/8227
* decl.c (layout_var_decl): Deal gracefully with erroneous types.
(check_initializer): Validate the type of the initialized
variable, even if the initializer is absent.
* typeck.c (cp_type_quals): Deal gracefully with erroneous types.
2002-11-30 Mark Mitchell <mark@codesourcery.com>
PR c++/8227
* g++.dg/template/ctor2.C: New test.
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.960
diff -c -5 -p -r1.960 decl.c
*** cp/decl.c 27 Nov 2002 01:59:42 -0000 1.960
--- cp/decl.c 1 Dec 2002 04:51:03 -0000
*************** layout_var_decl (decl)
*** 7629,7638 ****
--- 7629,7639 ----
supposed to isntantiate yet. (And it's perfectly valid to say
`extern X x' for some incomplete type `X'.) */
if (!DECL_EXTERNAL (decl))
complete_type (type);
if (!DECL_SIZE (decl)
+ && TREE_TYPE (decl) != error_mark_node
&& (COMPLETE_TYPE_P (type)
|| (TREE_CODE (type) == ARRAY_TYPE
&& !TYPE_DOMAIN (type)
&& COMPLETE_TYPE_P (TREE_TYPE (type)))))
layout_decl (decl, 0);
*************** check_initializer (tree decl, tree init,
*** 7972,8008 ****
error_mark_node, to indicate that an as-of-yet unevaluated
initialization will occur. From now on, DECL_INITIAL reflects
the static initialization -- if any -- of DECL. */
DECL_INITIAL (decl) = NULL_TREE;
! /* Check the initializer. */
! if (init)
{
! /* Things that are going to be initialized need to have complete
! type. */
! TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
!
! if (type == error_mark_node)
! /* We will have already complained. */
! init = NULL_TREE;
! else if (COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
! {
! error ("variable-sized object `%D' may not be initialized", decl);
! init = NULL_TREE;
! }
! else if (TREE_CODE (type) == ARRAY_TYPE
! && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
! {
! error ("elements of array `%#D' have incomplete type", decl);
! init = NULL_TREE;
! }
! else if (TREE_CODE (type) != ARRAY_TYPE && !COMPLETE_TYPE_P (type))
! {
! error ("`%D' has incomplete type", decl);
! TREE_TYPE (decl) = error_mark_node;
! init = NULL_TREE;
! }
}
if (TREE_CODE (decl) == CONST_DECL)
{
my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
--- 7973,8006 ----
error_mark_node, to indicate that an as-of-yet unevaluated
initialization will occur. From now on, DECL_INITIAL reflects
the static initialization -- if any -- of DECL. */
DECL_INITIAL (decl) = NULL_TREE;
! /* Things that are going to be initialized need to have complete
! type. */
! TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
!
! if (type == error_mark_node)
! /* We will have already complained. */
! init = NULL_TREE;
! else if (init && COMPLETE_TYPE_P (type)
! && !TREE_CONSTANT (TYPE_SIZE (type)))
{
! error ("variable-sized object `%D' may not be initialized", decl);
! init = NULL_TREE;
! }
! else if (TREE_CODE (type) == ARRAY_TYPE
! && !COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
! {
! error ("elements of array `%#D' have incomplete type", decl);
! init = NULL_TREE;
! }
! else if (TREE_CODE (type) != ARRAY_TYPE && !COMPLETE_TYPE_P (type))
! {
! error ("`%D' has incomplete type", decl);
! TREE_TYPE (decl) = error_mark_node;
! init = NULL_TREE;
}
if (TREE_CODE (decl) == CONST_DECL)
{
my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148);
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.434
diff -c -5 -p -r1.434 typeck.c
*** cp/typeck.c 26 Nov 2002 17:40:56 -0000 1.434
--- cp/typeck.c 1 Dec 2002 04:51:10 -0000
*************** comp_ptr_ttypes_reinterpret (to, from)
*** 6463,6472 ****
--- 6463,6474 ----
int
cp_type_quals (type)
tree type;
{
type = strip_array_types (type);
+ if (type == error_mark_node)
+ return TYPE_UNQUALIFIED;
return TYPE_QUALS (type);
}
/* Returns nonzero if the TYPE contains a mutable member */
Index: testsuite/g++.dg/template/ctor2.C
===================================================================
RCS file: testsuite/g++.dg/template/ctor2.C
diff -N testsuite/g++.dg/template/ctor2.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/ctor2.C 1 Dec 2002 04:51:11 -0000
***************
*** 0 ****
--- 1,18 ----
+ // { dg-do run }
+
+ int i;
+
+ template <class T>
+ struct S
+ {
+ S () { i = 1; }
+ };
+
+ static S<int> s[1];
+
+ int main ()
+ {
+ if (!i)
+ return 1;
+ }
+