GNU bug report logs - #72695
CC Mode 5.35.2 (C++//l); c++-mode misindents 'if constexpr' inside lambdas

Previous Next

Package: cc-mode;

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

Date: Sun, 18 Aug 2024 09:52:02 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, 72695 <at> debbugs.gnu.org
Subject: bug#72695: CC Mode 5.35.2 (C++//l); c++-mode misindents 'if constexpr' inside lambdas
Date: Sun, 18 Aug 2024 15:03:31 +0000
Hello, Arsen.

Thanks for the bug report!

On Sun, Aug 18, 2024 at 11:50:32 +0200, Arsen Arsenović via CC-Mode-help wrote:
> Package: cc-mode

> <#secure method=pgpmime mode=sign>
> Package: cc-mode
> Hi!

> CC-mode appears to misindent the following C++ snippet:

>   void f()
>   {
>     auto data_printer = [] <typename T>
>       (const T& data)
>       {
>         if constexpr (true)
>         {
>           if constexpr (std::same_as<T, std::string>)
>           std::println (" data: \"{}\"", data);
>           else
>             std::println (" data: {}", data);
>         }
>         else
>           std::println ("");
>       };
  
>     if constexpr (false)
>       {
>         foo ();
>       }
>   }

> This example is supposed to be formatted in accordance to the default
> GNU style, but the 'if constexpr' in the lambda expression are
> misindented.

Yes.

> This might be the case because the inline-open of the lambda gets
> mis-interpreted as statement-cont, so the statements in the body are
> indented as brace-list-intro and brace-entry-open rather than
> statement-block-intro and substatement-open.

It's definitely something to do with the lambda function.  If I comment
out Lines 3 and 4, the remainder of the function then indents correctly.
As you remark, at the moment some lines are being wrongly analysed as
brace-list constructs.

> WRT lambda indentation generally, CC-mode appears to format lambdas in
> GNU style so that their '{' aligns with their '[' (i.e. aligns their
> compound-statement with their lambda-introducer per ISO parlance).
> Maybe we should consider indenting them less. ....

OK.  I'll fix the "brace-list" indentation bug first, then come back to
this lambda indentation problem.

[ .... ]

> Anyway, thanks in advance!

> Have a most lovely day.

And yourself, too!

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).




This bug report was last modified 294 days ago.

Previous Next


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