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: Unresolved issue


>>>>> "Jason" == Jason Merrill <jason@cygnus.com> writes:

>>>>> Mark Mitchell <mark@markmitchell.com> writes:

    >> A while back I asked your permission to remove the extension
    >> whereby non-integral static data members may be initialized
    >> in-class.  There are some cases where this causes us to crash
    >> at present, which have been reported by several people, and I
    >> don't see that this extension is very useful.  But, I think
    >> that before you got a chance to think about this, you got
    >> buried in a pile of meetings.  What do you think?

    Jason> I'd prefer to retain the ability to do this for, say,
    Jason> floats.  The simplest thing would be to just remove the
    Jason> (init) syntax for members from the parser.

Actually, that alone doesn't do the trick; the same crashes can result
with the `= init' syntax.

    Jason> Jason

The attached patch disables the extension for aggregate and reference
types, since they seem to be the ones that cause crashes, and are the
farthest from the standard usage.  We still allow float/double and
pointer initializations, unless -pedantic is used.

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

1998-08-23  Mark Mitchell  <mark@markmitchell.com>

	* decl.c (grokdeclarator): Complain about in-class initialization
	of aggregates and/or references.
	* pt.c (process_template_parm): Clear IS_AGGR_TYPE for
	TEMPLATE_TYPE_PARMs. 

Index: testsuite/g++.old-deja/g++.other/crash2.C
===================================================================
RCS file: crash2.C
diff -N crash2.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- crash2.C	Sun Aug 23 13:28:39 1998
***************
*** 0 ****
--- 1,9 ----
+ // Build don't link:
+ 
+ struct A {
+   int rep;
+   static const A a(0); // ERROR - initialization
+   static const A b = 3; // ERROR - initialization
+   static const A& c = 2; // ERROR - initialization
+   A(int x) : rep(x) {}
+ };
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.185
diff -c -p -r1.185 decl.c
*** decl.c	1998/08/23 12:47:00	1.185
--- decl.c	1998/08/23 20:29:22
*************** grokdeclarator (declarator, declspecs, d
*** 10431,10445 ****
  		   but not both.  If it appears in the class, the member is
  		   a member constant.  The file-scope definition is always
  		   required.  */
! 		if (! constp)
! 		  /* According to Mike Stump, we generate bad code for
! 		     this case, so we might as well always make it an
! 		     error.  */
  		  cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
  			    declarator);
! 		
! 		if (pedantic && ! INTEGRAL_TYPE_P (type) 
! 		    && !uses_template_parms (type))
  		  cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", declarator, type);
  	      }
  
--- 10431,10453 ----
  		   but not both.  If it appears in the class, the member is
  		   a member constant.  The file-scope definition is always
  		   required.  */
! 		if (IS_AGGR_TYPE (type)
! 		    || TREE_CODE (type) == REFERENCE_TYPE)
! 		  {
! 		    cp_error ("in-class initialization of static data member of non-integral type `%T'", 
! 			      type);
! 		    /* If we just return the declaration, crashes will
! 		       sometimes occur.  We therefore return
! 		       void_type_node, as if this was a friend
! 		       declaration, to cause callers to completely
! 		       ignore this declaration.  */
! 		    return void_type_node;
! 		  }
! 		else if (!constp)
  		  cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
  			    declarator);
! 		else if (pedantic && ! INTEGRAL_TYPE_P (type) 
! 			 && !uses_template_parms (type))
  		  cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", declarator, type);
  	      }
  
Index: cp/pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.182
diff -c -p -r1.182 pt.c
*** pt.c	1998/08/23 12:47:07	1.182
--- pt.c	1998/08/23 21:28:09
*************** process_template_parm (list, next)
*** 1590,1595 ****
--- 1590,1596 ----
        else
  	{
  	  t = make_lang_type (TEMPLATE_TYPE_PARM);
+ 	  IS_AGGR_TYPE (t) = 0;
  	  /* parm is either IDENTIFIER_NODE or NULL_TREE */
  	  decl = build_decl (TYPE_DECL, parm, t);
  	}


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