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]

[C++ PATCH] Fix bug 1765


Jason,
this fixes bug 1765, which appeared after your revamp of the default
init code. We warn (with -W) about missing initializers on something like
{0}, and that interfered with building such a thing for default
initialization. The alternative to the CONSTRUCTOR flag in this patch
would be an extra arg to digest_init.

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-02-08  Nathan Sidwell  <nathan@codesourcery.com>

	* cp-tree.h (CONSTRUCTOR_DEFAULT_INIT_P): New macro.
	* init.c (build_default_init): Set it.
	* typeck2.c (process_init_constructor): Process it.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.570
diff -c -3 -p -r1.570 cp-tree.h
*** cp-tree.h	2001/02/05 11:45:14	1.570
--- cp-tree.h	2001/02/08 17:17:20
*************** Boston, MA 02111-1307, USA.  */
*** 45,50 ****
--- 45,51 ----
        BV_USE_VCALL_INDEX_P (in the BINFO_VIRTUALS TREE_LIST)
        PTRMEM_OK_P (in ADDR_EXPR, OFFSET_REF)
        PARMLIST_ELLIPSIS_P (in PARMLIST)
+       CONSTRUCTOR_DEFAULT_INIT_P (in CONSTRUCTOR)
     1: IDENTIFIER_VIRTUAL_P.
        TI_PENDING_TEMPLATE_FLAG.
        TEMPLATE_PARMS_FOR_INLINE.
*************** extern int flag_new_for_scope;
*** 2542,2547 ****
--- 2543,2552 ----
  #define EMPTY_CONSTRUCTOR_P(NODE) (TREE_CODE (NODE) == CONSTRUCTOR	   \
  				   && CONSTRUCTOR_ELTS (NODE) == NULL_TREE \
  				   && ! TREE_HAS_CONSTRUCTOR (NODE))
+ 
+ /* This constructor is allowed to perform default initialization of
+    unspecified members. */
+ #define CONSTRUCTOR_DEFAULT_INIT_P(NODE) TREE_LANG_FLAG_0 (NODE)
  
  /* Nonzero for _TYPE means that the _TYPE defines a destructor.  */
  #define TYPE_HAS_DESTRUCTOR(NODE) (TYPE_LANG_FLAG_2(NODE))
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/init.c,v
retrieving revision 1.231
diff -c -3 -p -r1.231 init.c
*** init.c	2001/02/05 11:45:15	1.231
--- init.c	2001/02/08 17:17:22
*************** build_default_init (type)
*** 225,230 ****
--- 225,231 ----
  	 rules in such a case are the same as for initialization with an
  	 empty brace-initialization list.  */
        init = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, NULL_TREE);
+       CONSTRUCTOR_DEFAULT_INIT_P (init) = 1;
      }
    else if (TREE_CODE (type) == REFERENCE_TYPE)
      /*   --if T is a reference type, no initialization is performed.  */
Index: cp/typeck2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck2.c,v
retrieving revision 1.96
diff -c -3 -p -r1.96 typeck2.c
*** typeck2.c	2001/01/16 17:57:34	1.96
--- typeck2.c	2001/02/08 17:17:23
*************** process_init_constructor (type, init, el
*** 810,821 ****
  		next1 = build_functional_cast (TREE_TYPE (field),
  					       NULL_TREE);
  	      else
! 		next1 = build (CONSTRUCTOR, NULL_TREE, NULL_TREE,
! 			       NULL_TREE);
  	      next1 = digest_init (TREE_TYPE (field), next1, 0);
  
  	      /* Warn when some struct elements are implicitly initialized.  */
! 	      if (extra_warnings)
  		cp_warning ("missing initializer for member `%D'", field);
  	    }
  	  else
--- 810,827 ----
  		next1 = build_functional_cast (TREE_TYPE (field),
  					       NULL_TREE);
  	      else
! 	        {
! 		  next1 = build (CONSTRUCTOR, NULL_TREE, NULL_TREE,
! 			         NULL_TREE);
!                   if (init)
!                     CONSTRUCTOR_DEFAULT_INIT_P (next1)
!                        = CONSTRUCTOR_DEFAULT_INIT_P (init);
!                 }
  	      next1 = digest_init (TREE_TYPE (field), next1, 0);
  
  	      /* Warn when some struct elements are implicitly initialized.  */
! 	      if (extra_warnings
! 	          && (!init || !CONSTRUCTOR_DEFAULT_INIT_P (init)))
  		cp_warning ("missing initializer for member `%D'", field);
  	    }
  	  else
*************** process_init_constructor (type, init, el
*** 831,837 ****
  
  	      /* Warn when some struct elements are implicitly initialized
  		 to zero.  */
! 	      if (extra_warnings)
  		cp_warning ("missing initializer for member `%D'", field);
  
  	      /* The default zero-initialization is fine for us; don't
--- 837,844 ----
  
  	      /* Warn when some struct elements are implicitly initialized
  		 to zero.  */
! 	      if (extra_warnings
! 	          && (!init || !CONSTRUCTOR_DEFAULT_INIT_P (init)))
  		cp_warning ("missing initializer for member `%D'", field);
  
  	      /* The default zero-initialization is fine for us; don't
// Special g++ Options: -W 
// Build don't link:
// 
// Copyright (C) 2000 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 6 Febs 2001 <nathan@codesourcery.com>

// Bug 1765. We gave bogus warning on default initializer.

struct X
{
  int i;
};

X *foo ()
{
  return new X ();  // gets bogus warning
}

X x = {};           // WARNING - missing initializer

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