diff options
author | Joseph Myers <joseph@codesourcery.com> | 2009-02-06 20:12:10 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2009-02-06 20:12:10 +0000 |
commit | 1de2c900e018849ddc8b3b4e682d05fb3b697fbe (patch) | |
tree | 3b7774a90eed648f1e7bacbb2a0a05aaea2a1422 /gcc/c-decl.c | |
parent | e901811a8be42e9c292324550c84be46d4f27e4c (diff) | |
download | gcc-1de2c900e018849ddc8b3b4e682d05fb3b697fbe.zip gcc-1de2c900e018849ddc8b3b4e682d05fb3b697fbe.tar.gz gcc-1de2c900e018849ddc8b3b4e682d05fb3b697fbe.tar.bz2 |
re PR c/36432 (“incompatible pointer type” with pointer to array as a struct member)
PR c/36432
* c-decl.c (grokdeclarator): Don't treat [] declarators in fields
as indicating flexible array members unless the field itself is
being declarared as the incomplete array.
testsuite:
* gcc.dg/c90-flex-array-2.c, gcc.dg/c99-flex-array-6.c: New tests.
From-SVN: r143989
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r-- | gcc/c-decl.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 35a9c4b..9fadad3 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4389,6 +4389,7 @@ grokdeclarator (const struct c_declarator *declarator, } else if (decl_context == FIELD) { + bool flexible_array_member = false; if (array_parm_vla_unspec_p) /* Field names can in fact have function prototype scope so [*] is disallowed here through making @@ -4396,13 +4397,23 @@ grokdeclarator (const struct c_declarator *declarator, something other than a declaration with function prototype scope. */ size_varies = 1; - else if (pedantic && !flag_isoc99 && !in_system_header) + else + { + const struct c_declarator *t = declarator; + while (t->kind == cdk_attrs) + t = t->declarator; + flexible_array_member = (t->kind == cdk_id); + } + if (flexible_array_member + && pedantic && !flag_isoc99 && !in_system_header) pedwarn (input_location, OPT_pedantic, "ISO C90 does not support flexible array members"); /* ISO C99 Flexible array members are effectively identical to GCC's zero-length array extension. */ - itype = build_range_type (sizetype, size_zero_node, NULL_TREE); + if (flexible_array_member || array_parm_vla_unspec_p) + itype = build_range_type (sizetype, size_zero_node, + NULL_TREE); } else if (decl_context == PARM) { |