+2009-01-12 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/32041
+ * c-parser.c (c_parser_postfix_expression): Allow `->' in
+ offsetof member-designator, handle it as `[0].'.
+
2009-01-12 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
* pa.c (pa_asm_output_mi_thunk): Use pc-relative branch to thunk
c_parser_consume_token (parser);
while (c_parser_next_token_is (parser, CPP_DOT)
|| c_parser_next_token_is (parser,
- CPP_OPEN_SQUARE))
+ CPP_OPEN_SQUARE)
+ || c_parser_next_token_is (parser,
+ CPP_DEREF))
{
- if (c_parser_next_token_is (parser, CPP_DOT))
+ if (c_parser_next_token_is (parser, CPP_DEREF))
+ {
+ loc = c_parser_peek_token (parser)->location;
+ offsetof_ref = build_array_ref (offsetof_ref,
+ integer_zero_node,
+ loc);
+ goto do_dot;
+ }
+ else if (c_parser_next_token_is (parser, CPP_DOT))
{
+ do_dot:
c_parser_consume_token (parser);
if (c_parser_next_token_is_not (parser,
CPP_NAME))
2009-01-12 Jakub Jelinek <jakub@redhat.com>
+ PR c/32041
+ * parser.c (cp_parser_builtin_offsetof): Allow `->' in
+ offsetof member-designator, handle it as `[0].'.
+
PR c++/38794
* decl.c (start_function): If grokdeclarator hasn't returned
FUNCTION_DECL nor error_mark_node, issue diagnostics.
/* C++ Parser.
Copyright (C) 2000, 2001, 2002, 2003, 2004,
- 2005, 2007, 2008 Free Software Foundation, Inc.
+ 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
Written by Mark Mitchell <mark@codesourcery.com>.
This file is part of GCC.
offsetof-member-designator:
id-expression
| offsetof-member-designator "." id-expression
- | offsetof-member-designator "[" expression "]" */
+ | offsetof-member-designator "[" expression "]"
+ | offsetof-member-designator "->" id-expression */
static tree
cp_parser_builtin_offsetof (cp_parser *parser)
expr = cp_parser_postfix_open_square_expression (parser, expr, true);
break;
+ case CPP_DEREF:
+ /* offsetof-member-designator "->" identifier */
+ expr = grok_array_decl (expr, integer_zero_node);
+ /* FALLTHRU */
+
case CPP_DOT:
/* offsetof-member-designator "." identifier */
cp_lexer_consume_token (parser->lexer);
- expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DOT, expr,
- true, &dummy,
+ expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DOT,
+ expr, true, &dummy,
token->location);
break;
+2009-01-12 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/32041
+ * gcc.dg/pr32041.c: New test.
+ * g++.dg/parse/offsetof9.C: New test.
+
2009-01-12 Daniel Jacobowitz <dan@codesourcery.com>
Nathan Froyd <froydnj@codesourcery.com>
--- /dev/null
+/* PR c/32041 */
+/* { dg-do run } */
+
+struct S
+{
+ int c;
+ struct { float f; } sa[2];
+};
+
+char a[__builtin_offsetof (S, sa->f)
+ == __builtin_offsetof (S, sa[0].f) ? 1 : -1];
+
+template <int N>
+struct T
+{
+ int c[N];
+ struct { float f; } sa[N];
+ static int foo () { return __builtin_offsetof (T, sa->f); }
+ static int bar () { return __builtin_offsetof (T, sa[0].f); }
+};
+
+char b[__builtin_offsetof (T<5>, sa->f)
+ == __builtin_offsetof (T<5>, sa[0].f) ? 1 : -1];
+
+int
+main ()
+{
+ if (T<1>::foo () != T<1>::bar ())
+ __builtin_abort ();
+ if (T<7>::foo () != T<7>::bar ())
+ __builtin_abort ();
+}
--- /dev/null
+/* PR c/32041 */
+/* { dg-do compile } */
+
+struct S
+{
+ int c;
+ struct { float f; } sa[2];
+};
+
+char a[__builtin_offsetof (struct S, sa->f)
+ == __builtin_offsetof (struct S, sa[0].f) ? 1 : -1];
+