Subject: bug#22486: CC Mode 5.33 (C++/l); Bad indentation in a hideous C++ struct

From: Alan Mackenzie <[email-masked]>
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
> ([email-masked])

-- 
Alan Mackenzie (Nuremberg, Germany).