In clang-format 12, CompactNamespaces misformatted the code when AllowShortLambdasOnASingleLine is set to false and BraceWrapping.BeforeLambdaBody is true.
Input:
namespace out { namespace in { } } // namespace out::in
Expected output:
namespace out { namespace in { }} // namespace out::in
Output from v12:
namespace out { namespace in { } } // namespace out::in
Config triggering the issue:
--- AllowShortLambdasOnASingleLine: None BraceWrapping: BeforeLambdaBody : true BreakBeforeBraces: Custom CompactNamespaces: true ...
Seems there's a corner case when AllowShortLambdasOnASingleLine is false, and BraceWrapping.BeforeLambdaBody is true, that causes CompactNamespaces to stop working.
The cause was a misannotation of { opening brace after namespace as a lambda opening brace.
The regression was probably introduced with this commit.
Originally contributed by Ahmed Mahdy (@aybassiouny). Thank you!
Please add at least asserts for Tok.Previous and Tok.Previous->Previous.