GNU bug report logs - #73182
CC Mode 5.35.2 (C++//l); 'enum' and 'enum class' appear to not get parsed correctly for indentation

Previous Next

Package: cc-mode;

Reported by: Arsen Arsenović <arsen <at> aarsen.me>

Date: Wed, 11 Sep 2024 18:53:01 UTC

Severity: normal

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

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Alan Mackenzie <acm <at> muc.de>
To: Arsen Arsenović <arsen <at> aarsen.me>
Cc: acm <at> muc.de, 73182 <at> debbugs.gnu.org
Subject: bug#73182: CC Mode 5.35.2 (C++//l); 'enum' and 'enum class' appear to not get parsed correctly for indentation
Date: Mon, 23 Sep 2024 21:31:02 +0000
Hello, Arsen.

On Wed, Sep 18, 2024 at 18:59:45 +0200, Arsen Arsenović wrote:
> Hi Alan,

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

[ .... ]

> > Thanks.  I've just written a little AWK script to count occurrences of
> > the "standard" indentation (the opening brace directly under enum in
> > column 0) and "non-standard" indentation (the opening brace indented
> > under enum in column 0).  The results have surprised me somewhat.

> Ah!  Great idea.  Thanks for collecting empirical data.  :-)

> > In "my" version of gcc-13.3.1, there are 947 standard indentations and
> > 81 non-standard.  Even in the Emacs sources (.c, .h, .m, and .cc) we
> > have 79 standard to 149 non-standard.  That's ~35% of enums looking
> > like they've been indented by private CC Mode styles, or by hand.

> Huh, that's interesting.  I expected more skew towards current
> behaviour.

So did I.

> > So my reservations from ten years ago about possible chaos were
> > misplaced; this chaos has already happened.

[ .... ]

> >> As an alternative to fixing this bug so that the token is recognized as
> >> a struct, we could have a new token for enum that does get indented
> >> correctly OOTB and that affected projects adjust to avoid trouble in
> >> their codebases.

> > That is one possibility, yes.  It seems clear that parsing enum
> > constructs as brace-lists is suboptimal, but I feel that parsing them as
> > structs, although easy, would be taking things just too far.  So I think
> > new symbols enum-open, etc., are the best way to go, even though this is
> > quite a lot of work (e.g. amending the CC Mode manual, the test suite,
> > ....).

> > So, I will fix this bug.

I have implemented the above, with new sytactic symbols enum-open,
enum-close, enum-intro, and enum-entry.  I have also enhanced the manual
and the test suite accordingly.  The patch is currently ~1250 lines long.

In the next day or two I will remove all my change annotations, and write
a commit message.  It should be completed and committed soon.

> Thank you again!

> Have a lovely day.
> -- 
> Arsen Arsenović

-- 
Alan Mackenzie (Nuremberg, Germany).




This bug report was last modified 298 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.