GNU bug report logs - #22486
CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct

Previous Next

Package: cc-mode;

Reported by: Michael Welsh Duggan <mwd <at> md5i.com>

Date: Thu, 28 Jan 2016 20:38: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: Michael Welsh Duggan <mwd <at> md5i.com>
Cc: 22486 <at> debbugs.gnu.org
Subject: bug#22486: CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct
Date: Fri, 5 Feb 2016 17:16:37 +0000
Hello, Michael.

On Thu, Jan 28, 2016 at 03:37:07PM -0500, Michael Welsh Duggan wrote:
> In the following C++ snippet:

> template <typename Arg, typename... Args>
> struct ArgListMatcher<Arg, Args...> :
>     ArgListMatcher<MakeIndices<CountRef<Arg>::value>,
>                    MakeIndices<sizeof...(Args) - CountRef<Arg>::value, CountRef<Arg>::value>,
>                        Arg, Args...>    <============================
> {
>   using Parent = ArgListMatcher<
>     MakeIndices<CountRef<Arg>::value>,
>     MakeIndices<sizeof...(Args) + 1 - CountRef<Arg>::value,
>                 CountRef<Arg>::value>, Arg, Args...>;
>   using Parent::ArgListMatcher;
> };

> Starting with "template" as the first line, the lines' contexts are
> listed as:

> syntax: ((topmost-intro 1)), indent: 0
> syntax: ((topmost-intro-cont 1)), indent: 0
> syntax: ((inher-intro 1)), indent: 4
> syntax: ((template-args-cont 1 99)), indent: 19
> syntax: ((member-init-intro 154)), indent: 23  <=====================
> syntax: ((defun-open 1)), indent: 0

> All of these seem reasonable save for member-init-intro, which I
> expected to be template-args-cont.

Yes.

Also noticeable here is that some of the <...> pairs are not marked with
paren syntax by CC Mode.  Further analysis shows that these are the pairs
with arithmetic operators (- and +) inside them.

If the - operator in line 4 is replaced by a comma, then line 5 gets
correctly recognised as template-args-cont.  (No, I'm not suggesting this
as a workaround.  :-)

CC Mode currently uses the presence of things like + and - and other
things which "can't [couldn't] be inside templates" as a heuristic to
distingish template delimiters from less-than and greater-than.  [On a
personal note, it seems like the designers of C++ are lacking taste; they
just don't know where to stop.  C++'s syntax is ambiguous and highly
context dependent.  It seems like those designers are determined that
only editors attached to a compiler's syntax tree are to be practical for
C++.]

Would it, perhaps, be feasible to detect the ... operator as an
indication that +, -, (?etc.) are permissible inside template delimiters?
Is it true that ... only exists inside either a variadic parameter list
or template delimiters?

[ .... ]

> -- 
> Michael Welsh Duggan
> (md5i <at> md5i.com)

-- 
Alan Mackenzie (Nuremberg, Germany).




This bug report was last modified 9 years and 98 days ago.

Previous Next


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