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 for Re: change in behavior



Brendan --
  
  Here's the fix for the problem you reported.

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

1998-10-27  Mark Mitchell  <mark@markmitchell.com>

	* decl.c (grokdeclarator): Use type_quals, rather than constp,
	consistently.

Index: testsuite/g++.old-deja/g++.other/const2.C
===================================================================
RCS file: const2.C
diff -N const2.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- const2.C	Tue Oct 27 22:16:38 1998
***************
*** 0 ****
--- 1,5 ----
+ // Build don't link:
+ 
+ struct S {
+   static const char* cp = "abc"; // ERROR - initialization of non-const
+ };
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.247
diff -c -p -r1.247 decl.c
*** decl.c	1998/10/26 23:48:53	1.247
--- decl.c	1998/10/28 06:17:31
*************** grokdeclarator (declarator, declspecs, d
*** 9396,9402 ****
  	{
  	  /* It's common practice (and completely valid) to have a const
  	     be initialized and declared extern.  */
! 	  if (! constp)
  	    warning ("`%s' initialized and declared `extern'", name);
  	}
        else
--- 9396,9402 ----
  	{
  	  /* It's common practice (and completely valid) to have a const
  	     be initialized and declared extern.  */
! 	  if (!(type_quals & TYPE_QUAL_CONST))
  	    warning ("`%s' initialized and declared `extern'", name);
  	}
        else
*************** grokdeclarator (declarator, declspecs, d
*** 10651,10658 ****
  		       the rest of the compiler does not correctly
  		       handle the initialization unless the member is
  		       static so we make it static below.  */
! 		    cp_pedwarn ("ANSI C++ forbids initialization of %s `%D'",
! 				constp ? "const member" : "member", 
  				declarator);
  		    cp_pedwarn ("making `%D' static", declarator);
  		    staticp = 1;
--- 10651,10657 ----
  		       the rest of the compiler does not correctly
  		       handle the initialization unless the member is
  		       static so we make it static below.  */
! 		    cp_pedwarn ("ANSI C++ forbids initialization of member `%D'",
  				declarator);
  		    cp_pedwarn ("making `%D' static", declarator);
  		    staticp = 1;
*************** grokdeclarator (declarator, declspecs, d
*** 10677,10683 ****
  		       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) 
--- 10676,10682 ----
  		       ignore this declaration.  */
  		    return void_type_node;
  		  }
! 		else if (!(type_quals & TYPE_QUAL_CONST))
  		  cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
  			    declarator);
  		else if (pedantic && ! INTEGRAL_TYPE_P (type) 
*************** grokdeclarator (declarator, declspecs, d
*** 10808,10814 ****
  
  	/* An uninitialized decl with `extern' is a reference.  */
  	decl = grokvardecl (type, declarator, &specbits, 
! 			    initialized, constp, in_namespace);
  	bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
  			inlinep, friendp, raises != NULL_TREE);
  
--- 10807,10815 ----
  
  	/* An uninitialized decl with `extern' is a reference.  */
  	decl = grokvardecl (type, declarator, &specbits, 
! 			    initialized, 
! 			    (type_quals & TYPE_QUAL_CONST) != 0, 
! 			    in_namespace);
  	bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE,
  			inlinep, friendp, raises != NULL_TREE);
  


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