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]

Re: [C++ PATCH] Fix bug 1765


Jason Merrill wrote:
> 
> Rather than a new flag, you can just check TREE_HAS_CONSTRUCTOR; it is only
> set for user-written CONSTRUCTORs.
Ok, thanks for that. I've installed the attached.
built & tested on i686-pc-linux-gnu.

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

	* typeck2.c (process_init_constructor): Check
	TREE_HAS_CONSTRUCTOR before issuing missing init warning.

Index: cp/typeck2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck2.c,v
retrieving revision 1.97
diff -c -3 -p -r1.97 typeck2.c
*** typeck2.c	2001/02/08 15:54:37	1.97
--- typeck2.c	2001/02/12 11:10:57
*************** process_init_constructor (type, init, el
*** 814,825 ****
  		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
--- 814,831 ----
  		next1 = build_functional_cast (TREE_TYPE (field),
  					       NULL_TREE);
  	      else
! 	        {
! 		  next1 = build (CONSTRUCTOR, NULL_TREE, NULL_TREE,
! 			         NULL_TREE);
!                   if (init)
!                     TREE_HAS_CONSTRUCTOR (next1)
!                        = TREE_HAS_CONSTRUCTOR (init);
!                 }
  	      next1 = digest_init (TREE_TYPE (field), next1, 0);
  
  	      /* Warn when some struct elements are implicitly initialized.  */
! 	      if (extra_warnings
! 	          && (!init || TREE_HAS_CONSTRUCTOR (init)))
  		cp_warning ("missing initializer for member `%D'", field);
  	    }
  	  else
*************** process_init_constructor (type, init, el
*** 835,841 ****
  
  	      /* 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
--- 841,848 ----
  
  	      /* Warn when some struct elements are implicitly initialized
  		 to zero.  */
! 	      if (extra_warnings
! 	          && (!init || TREE_HAS_CONSTRUCTOR (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]