On Wed, 10 Jan 2024, Jason Merrill via Gcc wrote:
> On 1/10/24 15:59, Marek Polacek wrote:
> > On Wed, Jan 10, 2024 at 02:58:03PM -0500, Jason Merrill via Gcc wrote:
> > > What formatting style do we want for non-trivial lambdas in GCC sources?
> > > I'm thinking the most consistent choice would be
> > >
> > > auto l = [&] (parms) // space between ] (
> > > { // brace on new line, indented two spaces
> > > return stuff;
> > > };
> >
> > Sure, why not. Consistency is what matters. Thus far we seem
> > to have been very inconsistent. ;)
> >
> > > By default, recent emacs lines up the { with the previous line, like an
> > > in-class function definition; I talked it into the above indentation with
> > >
> > > (defun lambda-offset (elem)
> > > (if (assq 'inline-open c-syntactic-context) '+ 0))
> > > (add-to-hook 'c++-mode-hook '(c-set-offset 'inlambda 'lambda-offset))
> > >
> > > I think we probably want the same formatting for lambdas in function
> > > argument lists, e.g.
> > >
> > > algorithm ([] (parms)
> > > {
> > > return foo;
> > > });
> >
> > And what about lambdas in conditions:
> >
> > if (foo ()
> > && [&] (params) mutable
> > {
> > return 42;
> > } ())
> >
> > should the { go just below [?
Also, what about trailing-type and mutable (above) when needing
a line-break?
(FTR: in technical terms, trailing-type is known as the
pointy-arrow-declaring-return-type thing :) the optional "->
type" between "(parms)" and "{ body }")
I suggest the obvious (to me): line up stuff after (params) with
the opening brace for body, when needing a line-break before
that item, and line-break *before* "->" .
brgds, H-P