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

From: Alan Mackenzie <[email-masked]>
Date: Wed, 12 Jul 2017 20:24:53 +0000

Hello, Mohammed.

On Mon, Apr 24, 2017 at 09:14:27 +0530, Mohammed Sadiq wrote:

> > 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.

I put on my (hopefully benevolent) dictator's hat and decided to stick
with my reasoning, here.

> > > 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.

Thanks.  I've committed the patch and closed the bug.

> > > 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

I'm afraid I used my dictator's hat here, too.

Anyway, the bug is, at long last, closed.

> Thanks

-- 
Alan Mackenzie (Nuremberg, Germany).