clang-format: Break before braces for lambda functions and extern blocks

Viewed 5882

I have a lambda function formatted like this:

auto cb = [](std::string const& _param)
{
    std::cout << _param;
};

I would like to keep the opening brace on a new line, but clang-format always places it at the end of the first line. Is it possible to configure clang-format to follow the style above?

The relevant part of my current configuration looks like this:

BraceWrapping:                         
  AfterClass:      true   
  AfterControlStatement: true
  AfterEnum:       true
  AfterFunction:   true          
  AfterNamespace:  true                
  AfterStruct:     true
  AfterUnion:      true
  BeforeCatch:     true
  BeforeElse:      true   
  IndentBraces:    true
BreakBeforeBraces: Allman

I would also like to do the same for extern blocks:

extern "C"
{
  // ...
}
2 Answers

This appears to be addressed with BeforeLambdaBody introduced in clang-format 11.

Related