Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3494,7 +3494,8 @@ } static bool isAllmanLambdaBrace(const FormatToken &Tok) { return (Tok.is(tok::l_brace) && Tok.is(BK_Block) && - !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral)); + !Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral) && + !Tok.Previous->Previous->is(tok::kw_namespace)); } static bool isAllmanBraceIncludedBreakableLambda( Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -2589,6 +2589,25 @@ Style)); } +TEST_F(FormatTest, FormatsCompactNamespacesLambdaRegression) { + // Make sure compact namespaces are not confused with lambdas + FormatStyle CompactNamespacesStyle{getLLVMStyle()}; + CompactNamespacesStyle.CompactNamespaces = true; + CompactNamespacesStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None; + CompactNamespacesStyle.BreakBeforeBraces = FormatStyle::BS_Custom; + CompactNamespacesStyle.BraceWrapping.BeforeLambdaBody = true; + verifyFormat("namespace out { namespace in {\n" + "}} // namespace out::in", + CompactNamespacesStyle); + EXPECT_EQ("namespace out { namespace in {\n" + "}} // namespace out::in", + format("namespace out {\n" + "namespace in {\n" + "} // namespace in\n" + "} // namespace out", + CompactNamespacesStyle)); +} + TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); verifyFormat("extern \"C\" {}");