From 07166901ad64e6c3d8c85ee1d54613bd662ff603 Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Tue, 1 Jun 2004 10:22:11 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/parser.c | 8 +++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/parse/offsetof4.C | 13 +++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/parse/offsetof4.C 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]); -- 2.30.2