This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] [PR14932] Allow subscript operator in offsetof
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: <gcc-patches at gcc dot gnu dot org>
- Cc: "Mark Mitchell" <mark at codesourcery dot com>
- Date: Tue, 1 Jun 2004 04:32:20 +0200
- Subject: [C++ PATCH] [PR14932] Allow subscript operator in offsetof
Hello Mark,
this is the straightforward fix for a small regression in the parser, where we
forgot to allow subscript operators within offsetof.
Testied on i686-pc-linux-gnu, OK for mainline and 3.4?
Giovanni Bajo
cp/
PR c++/14932
* parser.c (cp_parser_postfix_expression): Allow subscript
operator in offsetof.
testsuite/
PR c++/14932
* g++.dg/parse/offsetof4.C: New test.
Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.192
diff -c -3 -p -r1.192 parser.c
*** parser.c 13 May 2004 06:40:19 -0000 1.192
--- parser.c 1 Jun 2004 00:39:01 -0000
*************** cp_parser_postfix_expression (cp_parser
*** 3781,3789 ****
= grok_array_decl (postfix_expression, index);
idk = CP_ID_KIND_NONE;
/* Array references are not permitted in
! constant-expressions. */
! if (cp_parser_non_integral_constant_expression
! (parser, "an array reference"))
postfix_expression = error_mark_node;
}
break;
--- 3781,3791 ----
= grok_array_decl (postfix_expression, index);
idk = CP_ID_KIND_NONE;
/* Array references are not permitted in
! constant-expressions (but they are allowed
! in offsetof). */
! if (!parser->in_offsetof_p
! && cp_parser_non_integral_constant_expression
! (parser, "an array reference"))
postfix_expression = error_mark_node;
}
break;
// { dg-do compile }
// Contributed by Bill Helfinstine <bhelf at flitterfly dot whirpon dot com>
// PR c++/14932: Allow subscript operator in offsetof
#include <cstddef>
struct A
{
int bar;
int foo[22];
};
const int off = offsetof(A, foo[12]);