This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Bug 1631
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ PATCH] Bug 1631
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Thu, 18 Jan 2001 10:09:01 +0000
- CC: jason at redhat dot com
- Organization: Codesourcery LLC
Hi,
this patch fixes a problem with the new build_default_init on enumeral types.
When we do zero-initialization we should convert zero to the scalar type
[8.5/5], this effects enumerators which don't do that by default. Perhaps
we should convert for all types though?
built & tested on i686-pc-linux-gnu, ok?
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-01-17 Nathan Sidwell <nathan@codesourcery.com>
* typeck.c (build_modify_expr): Say `initialization' for
INIT_EXPRs.
* init.c (build_default_init): Convert to enumeral type, if
needed.
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.333
diff -c -3 -p -r1.333 typeck.c
*** typeck.c 2001/01/12 09:47:22 1.333
--- typeck.c 2001/01/17 16:10:44
*************** build_modify_expr (lhs, modifycode, rhs)
*** 5821,5827 ****
if (modifycode == INIT_EXPR)
{
newrhs = convert_for_initialization (lhs, lhstype, newrhs, LOOKUP_NORMAL,
! "assignment", NULL_TREE, 0);
if (current_function_decl &&
lhs == DECL_RESULT (current_function_decl))
{
--- 5821,5827 ----
if (modifycode == INIT_EXPR)
{
newrhs = convert_for_initialization (lhs, lhstype, newrhs, LOOKUP_NORMAL,
! "initialization", NULL_TREE, 0);
if (current_function_decl &&
lhs == DECL_RESULT (current_function_decl))
{
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/init.c,v
retrieving revision 1.226
diff -c -3 -p -r1.226 init.c
*** init.c 2001/01/10 23:06:28 1.226
--- init.c 2001/01/17 16:10:47
*************** build_default_init (type)
*** 232,238 ****
/* --if T is a reference type, no initialization is performed. */
return NULL_TREE;
else
! init = integer_zero_node;
init = digest_init (type, init, 0);
return init;
--- 232,244 ----
/* --if T is a reference type, no initialization is performed. */
return NULL_TREE;
else
! {
! init = integer_zero_node;
!
! if (TREE_CODE (type) == ENUMERAL_TYPE)
! /* We must make enumeral types the right type. */
! init = fold (build1 (NOP_EXPR, type, init));
! }
init = digest_init (type, init, 0);
return init;
// Build don't link:
// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 17 Jan 2001 <nathan@codesourcery.com>
// Bug 1631. Default initialization of enumeral types did not convert to the
// enumeral type.
enum X { alpha, beta };
void f(void *ptr)
{
X y = X ();
X y1 (0); // ERROR - cannot convert
X y2 = X (0);
X *x = new X ();
X *x2 = new X (0); // ERROR - cannot convert
}