From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Mailing List <gcc@gcc.gnu.org>
Subject: Re: lambda coding style
Date: Wed, 10 Jan 2024 16:24:42 -0500 [thread overview]
Message-ID: <8ec9a379-0b69-4a3c-b105-57ff0e37464b@redhat.com> (raw)
In-Reply-To: <ZZ8FMYDzLiDg9maL@redhat.com>
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 [?
I think we don't want the { to go below the [ in general; that was the
old emacs default behavior, and it produced lambda bodies with excessive
indentation.
With my adjustment above, emacs indents the { two spaces from the &&,
which seems a bit arbitrary but reasonable.
Jason
next prev parent reply other threads:[~2024-01-10 21:24 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 [this message]
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
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=8ec9a379-0b69-4a3c-b105-57ff0e37464b@redhat.com \
--to=jason@redhat.com \
--cc=gcc@gcc.gnu.org \
--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).