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]
Other format: [Raw text]

C++ PATCH: PR 13529


This patch fixes a buglet in my much-maligned implementation of
"offsetof".

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-01-04  Mark Mitchell  <mark@codesourcery.com>

	PR c++/13529
	* parser.c (cp_parser_postfix_expression): Allow "." to appear in
	an offsetof expression.

2004-01-04  Mark Mitchell  <mark@codesourcery.com>

	PR c++/13529
	* g++.dg/parse/offsetof3.C: New test.

Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.144
retrieving revision 1.145
diff -c -5 -p -r1.144 -r1.145
*** parser.c	4 Jan 2004 22:42:16 -0000	1.144
--- parser.c	5 Jan 2004 01:30:10 -0000	1.145
*************** cp_parser_postfix_expression (cp_parser 
*** 3907,3918 ****
  	       operator.  */
  	    parser->context->object_type = NULL_TREE;
  	    /* These operators may not appear in constant-expressions.  */
  	    if (parser->integral_constant_expression_p
  		/* The "->" operator is allowed in the implementation
! 		   of "offsetof".  */
! 		&& !(parser->in_offsetof_p && token_type == CPP_DEREF))
  	      {
  		if (!parser->allow_non_integral_constant_expression_p)
  		  postfix_expression 
  		    = (cp_parser_non_integral_constant_expression 
  		       (token_type == CPP_DEREF ? "'->'" : "`.'"));
--- 3907,3919 ----
  	       operator.  */
  	    parser->context->object_type = NULL_TREE;
  	    /* These operators may not appear in constant-expressions.  */
  	    if (parser->integral_constant_expression_p
  		/* The "->" operator is allowed in the implementation
! 		   of "offsetof".  The "." operator may appear in the
! 		   name of the member.  */
! 		&& !parser->in_offsetof_p)
  	      {
  		if (!parser->allow_non_integral_constant_expression_p)
  		  postfix_expression 
  		    = (cp_parser_non_integral_constant_expression 
  		       (token_type == CPP_DEREF ? "'->'" : "`.'"));
Index: testsuite/g++.dg/parse/offsetof3.C
===================================================================
RCS file: testsuite/g++.dg/parse/offsetof3.C
diff -N testsuite/g++.dg/parse/offsetof3.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/offsetof3.C	5 Jan 2004 01:49:35 -0000
***************
*** 0 ****
--- 1,11 ----
+ // PR c++/13529
+
+ #include <cstddef>
+ 
+ struct A { int i; };
+ struct B { A a; };
+ 
+ int main()
+ {
+   return offsetof(B,a.i) != 0;
+ }


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