public inbox for gcc-cvs-wwwdocs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@sourceware.org>
To: gcc-cvs-wwwdocs@gcc.gnu.org
Subject: gcc-wwwdocs branch master updated. 26e513cbcd050538bc40b8c53186024bdc2b413a
Date: Tue, 16 Jan 2024 05:48:18 +0000 (GMT)	[thread overview]
Message-ID: <20240116054818.239453858D1E@sourceware.org> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3750 bytes --]

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gcc-wwwdocs".

The branch, master has been updated
       via  26e513cbcd050538bc40b8c53186024bdc2b413a (commit)
      from  111b7b2cbf7269a060f9692a55353dfdf6fc0849 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 26e513cbcd050538bc40b8c53186024bdc2b413a
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jan 11 16:10:43 2024 -0500

    codingconventions: add lambda guidelines

diff --git a/htdocs/codingconventions.html b/htdocs/codingconventions.html
index f5a356a8..78ef472e 100644
--- a/htdocs/codingconventions.html
+++ b/htdocs/codingconventions.html
@@ -76,6 +76,7 @@ the conventions separately from any other changes to the code.</p>
         <li><a href="#Template_Form">Templates</a></li>
         <li><a href="#ExternC">Extern "C"</a></li>
         <li><a href="#Namespace_Form">Namespaces</a></li>
+        <li><a href="#Lambda_Form">Lambdas</a></li>
         </ul>
     </li>
     </ul>
@@ -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.
 </p>
 
+<h4 id="Lambda_Form">Lambdas</h4>
+
+<p>There should be a space between the lambda-introducer and the parameter
+  list, if any.</p>
+<p>Lambdas that do not outlive their enclosing function should
+  typically use <code>[&]</code> implicit capture.</p>
+
+<blockquote><pre><code>auto l = [&] (tree arg) { ... };
+</code></pre></blockquote>
+
+<p>If a lambda does not fit on one line, the left brace should be indented like
+the body of a for-statement.</p>
+
+<blockquote><pre><code>auto l = [&] (tree arg)
+  {
+    ...
+  };
+</code></pre></blockquote>
+
+<p>This also applies if the lambda is the last argument, and only lambda
+argument, to a function.</p>
+
+<blockquote><pre><code>std::for_each (start, end, [&] (tree arg)
+  {
+    ...
+  });
+</code></pre></blockquote>
+
+To get the above behavior from
+<a href="https://www.gnu.org/software/emacs/manual/html_mono/ccmode.html">
+  GNU Emacs CC Mode</a>, you can add this to your <code>.emacs</code>:
+
+<blockquote><pre><code>(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)))
+</code></pre></blockquote>
+
+<p>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 <code>l</code> examples above.  If you do pass them directly, they should
+be indented like other parameters.
+
+<blockquote><pre><code>my_algo (start, end,
+	 [&] (tree arg)
+           {
+             thing one...
+           },
+	 [&] (tree arg)
+           {
+             thing two...
+           });
+</code></pre></blockquote>
+
+<p>See also the
+  <a href="https://sourceware.org/gdb/wiki/Internals%20GDB-C-Coding-Standards#Indentation_of_lambdas_as_parameters">
+    GDB coding standards</a>.</p>
+
 <h2 id="python">Python Language Conventions</h2>
 
 <p>Python scripts should follow <a href="https://peps.python.org/pep-0008/">PEP 8 – Style Guide for Python Code</a>

-----------------------------------------------------------------------

Summary of changes:
 htdocs/codingconventions.html | 60 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)


hooks/post-receive
-- 
gcc-wwwdocs

                 reply	other threads:[~2024-01-16  5:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240116054818.239453858D1E@sourceware.org \
    --to=jason@sourceware.org \
    --cc=gcc-cvs-wwwdocs@gcc.gnu.org \
    /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).