GNU bug report logs -
#25623
CC Mode 5.32.99 (C/l); `c-defun-name' returns wrong result for filescope enums, structs and unions
Previous Next
Full log
View this message in rfc822 format
> On April 24, 2017 at 2:31 AM Alan Mackenzie <acm <at> muc.de> 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).
This bug report was last modified 8 years and 31 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.