public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hans-Peter Nilsson <hp@bitrange.com>
To: Jason Merrill <jason@redhat.com>
Cc: Marek Polacek <polacek@redhat.com>, GCC Mailing List <gcc@gcc.gnu.org>
Subject: Re: lambda coding style
Date: Fri, 19 Jan 2024 21:22:19 -0500 (EST)	[thread overview]
Message-ID: <alpine.BSF.2.20.16.2401192100320.22314@arjuna.pair.com> (raw)
In-Reply-To: <8ec9a379-0b69-4a3c-b105-57ff0e37464b@redhat.com>

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

  parent reply	other threads:[~2024-01-20  2:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10 19:58 Jason Merrill
2024-01-10 20:47 ` I am causing valgrind errors Robert Dubner
2024-01-10 20:51   ` Jakub Jelinek
2024-01-10 21:17     ` Robert Dubner
2024-01-10 20:59 ` lambda coding style Marek Polacek
2024-01-10 21:24   ` Jason Merrill
2024-01-10 21:41     ` Marek Polacek
2024-01-11  2:34       ` Jason Merrill
2024-01-11  5:30         ` waffl3x
2024-01-20  2:22     ` Hans-Peter Nilsson [this message]
2024-01-11 17:45 ` Tom Tromey
2024-01-11 17:48 ` Martin Jambor
     [not found] ` <65328.124011112484300622@us-mta-617.us.mimecast.lan>
2024-01-11 19:25   ` Jason Merrill
2024-01-12 11:06     ` Martin Jambor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.BSF.2.20.16.2401192100320.22314@arjuna.pair.com \
    --to=hp@bitrange.com \
    --cc=gcc@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=polacek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).