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

Package: cc-mode;

Reported by: Mohammed Sadiq <sadiq <at> sadiqpk.org>

Date: Sun, 5 Feb 2017 02:52:02 UTC

Severity: normal

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


Message #22 received at 25623-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Mohammed Sadiq <sadiq <at> sadiqpk.org>
Cc: 25623-done <at> debbugs.gnu.org
Subject: Re: bug#25623: CC Mode 5.32.99 (C/l); `c-defun-name' returns wrong
 result for filescope enums, structs and unions
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 <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.

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




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.