Subject: bug#25623: CC Mode 5.32.99 (C/l); `c-defun-name' returns wrong result for filescope enums, structs and unions

From: Mohammed Sadiq <[email-masked]>
Date: Mon, 24 Apr 2017 09:14:27 +0530 (IST)

> On April 24, 2017 at 2:31 AM Alan Mackenzie <[email-masked]> wrote:
> > 
> > enum
> >  {
> >  A,
> >  B,|
> >  C,
> >  };
> > 
> > gives 'nil', which would better return 'enum' as it is common to have enums without
> > names associated.
> 
> I've thought about this. The problem is that "enum" is not a name - it
> is a keyword.

Yeah, right, but as "enum" and "struct" can't be used function names, users can use
c-defun-name to check if the point is in struct or enum too.

> 
> > int a[] = {'h', 'e', 'l', 'l', 'o', '\0'|};
> > 
> > gives "[" which I believe, should actually return 'nil' when defined at file scope.
> 
> It should indeed return nil. Please see the amended patch (below).

Your patch fixed the issue.

> 
> > typedef struct
> > {
> >  int a;
> >  int b;|
> > } nice;
> > 
> > returns "nice". It may be better to return "struct nice" as in "struct nice {...};" definition.
> 
> I considered that, too. Even returning "nice" is a bit bogus, here. For
> example, if we had "typedef struct { ... } nice, easy;" why should we
> return "nice" (which we do) rather than "easy"? I think here, strictly
> speaking, we should return nil, since "nice" is an identifier _after_ the
> main type definition, not part of it. But, then again, maybe here is not
> the place to be strict. ;-)
> 

If in both cases, returning simply "struct" would be more helpful to the users
than nil, imho. the same for enum

Thanks

> [code snipped]
> --
> Alan Mackenzie (Nuremberg, Germany).