From patchwork Thu Jan 11 21:33:10 2024
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Patchwork-Submitter: Jason Merrill
X-Patchwork-Id: 1885794
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@legolas.ozlabs.org
Authentication-Results: legolas.ozlabs.org;
dkim=pass (1024-bit key;
unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256
header.s=mimecast20190719 header.b=RaxlOirr;
dkim-atps=neutral
Authentication-Results: legolas.ozlabs.org;
spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org
(client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org;
envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org;
receiver=patchwork.ozlabs.org)
Received: from server2.sourceware.org (server2.sourceware.org
[IPv6:2620:52:3:1:0:246e:9693:128c])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384)
(No client certificate requested)
by legolas.ozlabs.org (Postfix) with ESMTPS id 4T9yb70XTnz1yPf
for ; Fri, 12 Jan 2024 08:33:39 +1100 (AEDT)
Received: from server2.sourceware.org (localhost [IPv6:::1])
by sourceware.org (Postfix) with ESMTP id 15E503857C71
for ; Thu, 11 Jan 2024 21:33:37 +0000 (GMT)
X-Original-To: gcc-patches@gcc.gnu.org
Delivered-To: gcc-patches@gcc.gnu.org
Received: from us-smtp-delivery-124.mimecast.com
(us-smtp-delivery-124.mimecast.com [170.10.133.124])
by sourceware.org (Postfix) with ESMTPS id C29163857736
for ; Thu, 11 Jan 2024 21:33:15 +0000 (GMT)
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C29163857736
Authentication-Results: sourceware.org;
dmarc=pass (p=none dis=none) header.from=redhat.com
Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C29163857736
Authentication-Results: server2.sourceware.org;
arc=none smtp.remote-ip=170.10.133.124
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705008797; cv=none;
b=wVwm1jgquYULu3iIJtZ+L3g9dUW/DGI/6tZCb6PcZjrzA028+ArLvFdIQU5X7KtpkxtTX1pWYOwc1ZVyWXZSzCAsqltSMggZly3dFSko7N092EQQ5Ad6HqbSedMX58A24FzGvSVwqT5Nu1OW9JCOAJkeSvj/7frcz5vRi1KJlFY=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1705008797; c=relaxed/simple;
bh=BISsXtHw2PFKNaV9NoKJUD1+BbWSmvWS2bZ7ZL0ECLc=;
h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version;
b=Yup1m7HytXH0dj62mx59cCfNqkyOPjmKJBOddQGB0k4BV4UWpVtfdpCBS6dX+ug8Xvf2/u+BBd/+xyZQbxV9ugmh1rJ0qixmOKjtreQhYMng1Ky+80ECGs+iGpngUYqSPFTPif5ETfLP1bywtpaQKa77nlY+dmR5Aya4opmJVIQ=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
s=mimecast20190719; t=1705008795;
h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
to:to:cc:cc:mime-version:mime-version:content-type:content-type:
content-transfer-encoding:content-transfer-encoding;
bh=IzSn3/JP196UK6r45DXKCOKnGxiThOSBVvs+6+fe53U=;
b=RaxlOirrCWM+gFtpR6ZZp6NRhW/8O10t66J28iJbQ9PIezeAjVfOBqWWTYGrtRT468hwCd
O7H5VIvxl/TRzqrtWzPWrKbyY3NWIW7qhPpjl/1tZfHVwKUrTkHIjPaPjhCg3+KtIaBqmG
13a2bkwTsNc2uCsI94ETDBBepunynKU=
Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com
[209.85.128.198]) by relay.mimecast.com with ESMTP with STARTTLS
(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
us-mta-556-_TB9OElWN6qJOVfuzujVMQ-1; Thu, 11 Jan 2024 16:33:14 -0500
X-MC-Unique: _TB9OElWN6qJOVfuzujVMQ-1
Received: by mail-yw1-f198.google.com with SMTP id
00721157ae682-5e8d2c6903dso108679857b3.0
for ; Thu, 11 Jan 2024 13:33:14 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1705008793; x=1705613593;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-message-state:from:to:cc:subject:date:message-id
:reply-to;
bh=IzSn3/JP196UK6r45DXKCOKnGxiThOSBVvs+6+fe53U=;
b=wYsKVYoeKoEGrqBnBBCCOLKMxMlCZfqMEZJQQ9FaBeRB9L3PT3lf5FLbR73onUwInF
Dr6TXgR1BQR0+AhAllDMq37FCG0XMFC7up87GeFTXj9gj0mk8wyEUekQrNoWaEls2CDD
lOkxdCDaFeFLCRAUCffqgP6y+enkJfDEbkOyvnEaHr2TOnTHV6ISG0R1mSqdrfZ9rfFg
yUGeWme7IPCjYn0mgt3Y+WoMfmfpCkY32NSL7yG0MIUSVTxMLHl04AsK0LNiFc4SHFUa
de/cDOb/ptPh80AA4+b6UU+GKWNA/78h7lQrX2L3Mh6QhJjLYtNBVhT2acWbhLgVh4QA
elQQ==
X-Gm-Message-State: AOJu0YxEustTvSlzXxk31APcLA98/7EsKlAnYA4wg7jK/1ddf5WaZszv
4vmz/WDVl+5ZZWSThGwgc9t7Qg0/nC4i0/4R9vWjBxNDA27tFQ4cyT6VMDtXuN5XMK1HOrAo4xt
3v+5ti4+9JAPddAt09oY7vdBcsmnJKU+Wx7oA3hOu5lsX1g+GMsBRGlb7WHNKjYrtTkaEs4Euif
h5THK03g==
X-Received: by 2002:a25:83c8:0:b0:dbe:328a:3d9b with SMTP id
v8-20020a2583c8000000b00dbe328a3d9bmr280357ybm.17.1705008793618;
Thu, 11 Jan 2024 13:33:13 -0800 (PST)
X-Google-Smtp-Source:
AGHT+IHiny6rJva0sKEr1CE61XZGpiFOZom05qIkFnNNxzigQlB24joeiXqrSve9FjnjrojV6+EwKw==
X-Received: by 2002:a25:83c8:0:b0:dbe:328a:3d9b with SMTP id
v8-20020a2583c8000000b00dbe328a3d9bmr280342ybm.17.1705008793183;
Thu, 11 Jan 2024 13:33:13 -0800 (PST)
Received: from jason.com
(130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com.
[130.44.146.16]) by smtp.gmail.com with ESMTPSA id
gc9-20020a05622a59c900b004181138e0c0sm776664qtb.31.2024.01.11.13.33.12
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 11 Jan 2024 13:33:12 -0800 (PST)
From: Jason Merrill
To: gcc-patches@gcc.gnu.org,
Gerald Pfeifer
Cc: Marek Polacek , waffl3x ,
Tom Tromey , Martin Jambor
Subject: [PATCH RFC] codingconventions: add lambda guidelines
Date: Thu, 11 Jan 2024 16:33:10 -0500
Message-Id: <20240111213310.1566285-1-jason@redhat.com>
X-Mailer: git-send-email 2.39.3
MIME-Version: 1.0
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH,
DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0,
KAM_SHORT,
RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,
SPF_NONE, TXREP,
T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: gcc-patches@gcc.gnu.org
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: Gcc-patches mailing list
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org
Now in patch form!
Any further comments?
---
htdocs/codingconventions.html | 60 +++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
base-commit: 62250c79a7483076f1b2b11496e4a1123c9df6a0
diff --git a/htdocs/codingconventions.html b/htdocs/codingconventions.html
index f5a356a8..2bbf6670 100644
--- a/htdocs/codingconventions.html
+++ b/htdocs/codingconventions.html
@@ -76,6 +76,7 @@ the conventions separately from any other changes to the code.
Templates
Extern "C"
Namespaces
+ Lambdas
@@ -1488,6 +1489,65 @@ with a right brace, optional closing comment, and a new line.
Definitions within the body of a namespace are not indented.
+
+
+There should be a space between the lambda-introducer and the parameter
+ list, if any.
+Lambdas that do not outlive their enclosing function should
+ typically use [&]
implicit capture.
+
+auto l = [&] (tree arg) { ... };
+
+
+If a lambda does not fit on one line, the left brace should be indented like
+the body of a for-statement.
+
+auto l = [&] (tree arg)
+ {
+ ...
+ };
+
+
+This also applies if the lambda is the last argument, and only lambda
+argument, to a function.
+
+std::for_each (start, end, [&] (tree arg)
+ {
+ ...
+ });
+
+
+To get the above behavior from
+
+ GNU Emacs CC Mode, you can add this to your .emacs
:
+
+(defun lambda-offset (elem)
+ "If the opening brace of a lambda is on a new line, indent it one step."
+ (if (assq 'inline-open c-syntactic-context) '+ 0))
+(add-hook 'c++-mode-hook
+ '(lambda () (c-set-offset 'inlambda 'lambda-offset)))
+
+
+If the multi-line lambda is not the last argument, or there are multiple
+lambda arguments, you are encouraged to make them local variables, as
+the l
examples above. If you do pass them directly, they should
+be indented like other parameters.
+
+
my_algo (start, end,
+ [&] (tree arg)
+ {
+ thing one...
+ },
+ [&] (tree arg)
+ {
+ thing two...
+ });
+
+
+See also the
+
+ GDB coding standards.
+
Python Language Conventions
Python scripts should follow PEP 8 – Style Guide for Python Code