From: Giovanni Bajo Date: Tue, 1 Jun 2004 10:22:11 +0000 (+0000) Subject: re PR c++/14932 (cannot use offsetof to get offsets of array elements in g++ 3.4... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=07166901ad64e6c3d8c85ee1d54613bd662ff603;p=gcc.git re PR c++/14932 (cannot use offsetof to get offsets of array elements in g++ 3.4.0 prerelease) PR c++/14932 * parser.c (cp_parser_postfix_expression): Allow subscript operator in offsetof. PR c++/14932 * g++.dg/parse/offsetof4.C: New test. From-SVN: r82538 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4549203275b..850f211c77b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-06-01 Giovanni Bajo + + PR c++/14932 + * parser.c (cp_parser_postfix_expression): Allow subscript + operator in offsetof. + 2004-05-31 Mark Mitchell PR c++/15701 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index f98de0c93c9..fa050125d91 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3781,9 +3781,11 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p) = 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")) + 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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0c34a57a740..02e066d3795 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-06-01 Giovanni Bajo + + PR c++/14932 + * g++.dg/parse/offsetof4.C: New test. + 2004-06-01 Nicola Pero PR objc/7993 diff --git a/gcc/testsuite/g++.dg/parse/offsetof4.C b/gcc/testsuite/g++.dg/parse/offsetof4.C new file mode 100644 index 00000000000..ba051480d1d --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/offsetof4.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// Contributed by Bill Helfinstine +// PR c++/14932: Allow subscript operator in offsetof + +#include + +struct A +{ + int bar; + int foo[22]; +}; + +const int off = offsetof(A, foo[12]);