Subject: Re: bug#72695: CC Mode 5.35.2 (C++//l); c++-mode misindents 'if constexpr' inside lambdas

From: Alan Mackenzie <[email-masked]>
Date: Thu, 26 Sep 2024 11:34:24 +0000

Hello, Arsen.

On Sat, Sep 21, 2024 at 21:32:36 +0200, Arsen Arsenović wrote:
> Hi Alan,

> Alan Mackenzie <[email-masked]> writes:
> > On Tue, Sep 10, 2024 at 01:02:50 +0200, Arsen Arsenović wrote:
> >> Alan Mackenzie <[email-masked]> writes:

[ .... ]

> > Thanks, I've now found the place in the C++ syntax where alignas can go
> > in a lambda construct.  It is the only specifier which may go in these
> > places, although any number of attributes are allowed.  (As a matter of
> > interest, attributes in CC Mode are treated as syntactic whitespace.)

> > [ .... ]

> >> >>   void
> >> >>   def ()
> >> >>   {
> >> >>     auto foo = [&,
> >> >>   	      a,
> >> >>   	      b = 123,
> >> >>   	      c,
> >> >>   	      ...d,
> >> >>   	      ...e = 123
> >> >>   	      ]
> >> >>       <typename T,
> >> >>        typename S>
> >> >>       //alignas (128)
> >> >>       [[gnu::noreturn]]
> >> >>       requires some_concept<T>
> >> >>       (int a,
> >> >>        int b,
> >> >>        int c)
> >> >>       consteval
> >> >>       constexpr
> >> >>       mutable
> >> >>       static
> >> >>       //noexcept(true)
> >> >>       [[gnu::packed]]
> >> >>       //alignas (128)
> >> >>       //->
> >> >>       //int
> >> >>       //requires (std::same_as <decltype (a), int>)
> >> >>         {
> >> >>       if constexpr (true)
> >> >>         ;
> >> >>     }
> >> >>   }

> > Question: Is that first (commented out) alignas correct where it is?  My
> > reading of the version of the standard suggests that the alignas (128)
> > should come _after_ the requires some_concept<T>, not before it.

Sorry to keep going on about this, but ....

> I think so, through the 2nd lambda-expression derivation:

I'm interpreting this as being the answer to "Is that first .... alignas
correct?", not a comment on my second sentence "My reading of ...., not
before it.".  If I'm mistaken there, then my next paragraph is without
effect, and I apologise.

>   lambda-introducer < template-parameter-list > requires-clause_opt
>     attribute-specifier-seq_opt lambda-declarator compound-statement

> ... where attribute-specifier-seq is:

>   attribute-specifier-seq_opt attribute-specifier

> ... and attribute-specifier is also possibly alignment-specifier.

> Maybe I am missing something, though?

..... My reading of that lambda-expression derivation is that the "alignas
(128)" is the atribute-specifier-seq_opt, and the "requires
some_concept<T>" is the requires-clause_opt.  Surely the first of these,
the "alignas" needs to come after the second, the "requires"?

Phew!

[ .... ]

> > Even it the patch is good, I'm not quite ready to commit it yet, since I
> > need to amend the test suite somewhat.

> I will test it at a later time tonight or tomorrow.  Sorry for the
> delay.

I got your other post where you reported on that the tests you did were
satisfactory.  Thanks for that!

I'm hoping to get the patch committed before the weekend.

> Thank you once again for your efforts!

> Have a lovely evening!
> -- 
> Arsen Arsenović

-- 
Alan Mackenzie (Nuremberg, Germany).