lambda coding style

Jason Merrill jason@redhat.com
Wed Jan 10 19:58:03 GMT 2024


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;
   };

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;
   });

Any other opinions?

Jason



More information about the Gcc mailing list