re PR c++/14932 (cannot use offsetof to get offsets of array elements in g++ 3.4...
authorGiovanni Bajo <giovannibajo@gcc.gnu.org>
Tue, 1 Jun 2004 10:22:11 +0000 (10:22 +0000)
committerGiovanni Bajo <giovannibajo@gcc.gnu.org>
Tue, 1 Jun 2004 10:22:11 +0000 (10:22 +0000)
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
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/offsetof4.C [new file with mode: 0644]

index 4549203275b081c2e8def2cfd7eda4480e092459..850f211c77b1b84c9b66ce7efd02ead9fcf50ded 100644 (file)
@@ -1,3 +1,9 @@
+2004-06-01  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       PR c++/14932
+       * parser.c (cp_parser_postfix_expression): Allow subscript
+       operator in offsetof.
+
 2004-05-31  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/15701
index f98de0c93c92b24cd387b1e1ce23bedd7d71b2ba..fa050125d9182e3fc80f5b6b46066b8186e2ffa1 100644 (file)
@@ -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;
index 0c34a57a740afe2c2f496d9ffdd9886a88cbdb53..02e066d3795355a5692a863734f5f0edcc251544 100644 (file)
@@ -1,3 +1,8 @@
+2004-06-01  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
+
+       PR c++/14932
+       * g++.dg/parse/offsetof4.C: New test.
+
 2004-06-01  Nicola Pero  <nicola@brainstorm.co.uk>
 
        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 (file)
index 0000000..ba05148
--- /dev/null
@@ -0,0 +1,13 @@
+// { 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]);