public inbox for gcc-cvs-wwwdocs@sourceware.org
help / color / mirror / Atom feed
* gcc-wwwdocs branch master updated. 26e513cbcd050538bc40b8c53186024bdc2b413a
@ 2024-01-16  5:48 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2024-01-16  5:48 UTC (permalink / raw)
  To: gcc-cvs-wwwdocs

[-- 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-16  5:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16  5:48 gcc-wwwdocs branch master updated. 26e513cbcd050538bc40b8c53186024bdc2b413a Jason Merrill

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).