This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 12218 and 12696
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 16 Dec 2003 21:21:07 -0800
- Subject: C++ PATCH: PR 12218 and 12696
- Reply-to: mark at codesourcery dot com
This patch fixes two C++ PRs.
The first was a situation where we were trying to dynamically
initialize a read-only pointer-to-member. We've gradually been
teaching varasm.c that it can initialize things of OFFSET_TYPE;
hopefully we've found all the problems now.
The second case was an error-recovery problem; when seeing a problem
with a brace-enclosed initializer we now do not try to process the
rest of the initializer, if it seems that we may well have lost our
place in the initialization. That prevents a bad error cascade.
Tested on i686-pc-linux-gnu, applied on the mainline.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2003-12-16 Mark Mitchell <mark@codesourcery.com>
PR c++/12218
* varasm.c (initializer_constant_valid_p): Allow a conversion from
an integral constant to an OFFSET_TYPE.
2003-12-16 Mark Mitchell <mark@codesourcery.com>
PR c++/12696
* decl.c (reshape_init): Recover quickly from errors.
2003-12-16 Mark Mitchell <mark@codesourcery.com>
PR c++/12218
* g++.dg/init/pm3.C: New test.
PR c++/12696
* g++.dg/init/error1.C: New test.
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.399
diff -c -5 -p -r1.399 varasm.c
*** varasm.c 6 Dec 2003 15:41:24 -0000 1.399
--- varasm.c 17 Dec 2003 03:22:36 -0000
*************** initializer_constant_valid_p (tree value
*** 3590,3600 ****
return initializer_constant_valid_p (TREE_OPERAND (value, 0),
endtype);
/* Likewise conversions from int to pointers, but also allow
conversions from 0. */
! if (POINTER_TYPE_P (TREE_TYPE (value))
&& INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
{
if (integer_zerop (TREE_OPERAND (value, 0)))
return null_pointer_node;
else if (TYPE_PRECISION (TREE_TYPE (value))
--- 3590,3601 ----
return initializer_constant_valid_p (TREE_OPERAND (value, 0),
endtype);
/* Likewise conversions from int to pointers, but also allow
conversions from 0. */
! if ((POINTER_TYPE_P (TREE_TYPE (value))
! || TREE_CODE (TREE_TYPE (value)) == OFFSET_TYPE)
&& INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
{
if (integer_zerop (TREE_OPERAND (value, 0)))
return null_pointer_node;
else if (TYPE_PRECISION (TREE_TYPE (value))
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1161
diff -c -5 -p -r1.1161 decl.c
*** cp/decl.c 15 Dec 2003 14:19:01 -0000 1.1161
--- cp/decl.c 17 Dec 2003 03:22:38 -0000
*************** reshape_init (tree type, tree *initp)
*** 4269,4280 ****
An initializer for an aggregate member that is an
empty class shall have the form of an empty
initializer-list {}. */
if (!brace_enclosed_p)
! error ("initializer for `%T' must be brace-enclosed",
! type);
}
else
{
/* Loop through the initializable fields, gathering
initializers. */
--- 4269,4283 ----
An initializer for an aggregate member that is an
empty class shall have the form of an empty
initializer-list {}. */
if (!brace_enclosed_p)
! {
! error ("initializer for `%T' must be brace-enclosed",
! type);
! return error_mark_node;
! }
}
else
{
/* Loop through the initializable fields, gathering
initializers. */
*************** reshape_init (tree type, tree *initp)
*** 4295,4304 ****
--- 4298,4309 ----
}
if (!field)
break;
field_init = reshape_init (TREE_TYPE (field), initp);
+ if (field_init == error_mark_node)
+ return error_mark_node;
TREE_CHAIN (field_init) = CONSTRUCTOR_ELTS (new_init);
CONSTRUCTOR_ELTS (new_init) = field_init;
/* [dcl.init.aggr]
When a union is initialized with a brace-enclosed
*************** reshape_init (tree type, tree *initp)
*** 4325,4334 ****
--- 4330,4341 ----
index = size_binop (PLUS_EXPR, index, size_one_node))
{
tree element_init;
element_init = reshape_init (TREE_TYPE (type), initp);
+ if (element_init == error_mark_node)
+ return error_mark_node;
TREE_CHAIN (element_init) = CONSTRUCTOR_ELTS (new_init);
CONSTRUCTOR_ELTS (new_init) = element_init;
if (TREE_PURPOSE (element_init))
index = TREE_PURPOSE (element_init);
}
Index: testsuite/g++.dg/init/pm3.C
===================================================================
RCS file: testsuite/g++.dg/init/pm3.C
diff -N testsuite/g++.dg/init/pm3.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/pm3.C 17 Dec 2003 03:22:41 -0000
***************
*** 0 ****
--- 1,10 ----
+ // PR c++/12218
+ // { dg-do run }
+
+ struct C { int i, j; };
+ typedef int C::*mPtr;
+ extern const mPtr should_be_0 = &C::i;
+ extern const mPtr should_be_4 = &C::j;
+
+ int main () {
+ }
Index: testsuite/g++.dg/init/error1.C
===================================================================
RCS file: testsuite/g++.dg/init/error1.C
diff -N testsuite/g++.dg/init/error1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/error1.C 17 Dec 2003 04:16:32 -0000
***************
*** 0 ****
--- 1,7 ----
+ // PR c++/12696
+
+ struct A {
+ static float b[10]; // { dg-error "" }
+ }
+
+ float A::b[] = {1,2,3}; // { dg-error "" }