fun with declarations and definitions
commitc121815ecdcefdb735e92fae6ba9eedca88fe289
authorAl Viro <viro@ZenIV.linux.org.uk>
Fri, 6 Feb 2009 05:36:55 +0000 (6 05:36 +0000)
committerChristopher Li <sparse@chrisli.org>
Fri, 17 Jul 2009 23:06:22 +0000 (17 23:06 +0000)
tree4200b409668c20feb8a1a8837aabe1e7e0fcea1b
parentf7d10fe6c183448a48e2c4dc8d805c3524ccab45
fun with declarations and definitions

On Thu, Feb 05, 2009 at 09:19:21PM +0000, Al Viro wrote:
> IOW, direct_declarator() (which doubles for direct-abstract-declarator) should
> have more than one-bit indication of which case we've got.  Right now it's
> done by "have we passed a non-NULL ident ** to store the identifier being
> declared"; that's not enough.  What we need is explicit 'is that a part of
> parameter declaration' flag; then the rule turns into
>  if (p && *p)
>  fn = 1; /* we'd seen identifier already, can't be nested */
>  else if match_op(next, ')')
>  fn = 1; /* empty list can't be direct-declarator or
>   * direct-abstract-declarator */
>  else
>  fn = (in_parameter && lookup_type(next));

Umm...  It's a bit more subtle (p goes NULL after the nested one is
handled), so we need to keep track of "don't allow nested declarator from
that point on" explicitly.  Patch follows:

Subject: [PATCH] Handle nested declarators vs. parameter lists correctly

Seeing a typedef name after ( means that we have a parameter-type-list
only if we are parsing a parameter declaration or a typename; otherwise
it might very well be a redeclaration (e.g. int (T); when T had been a
typedef in outer scope).

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Christopher Li <sparse@chrisli.org>
parse.c
validation/nested-declarator.c [new file with mode: 0644]