Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -1995,6 +1995,11 @@ return false; if (Left.is(TT_RegexLiteral)) return false; + + // `[]() -> T *{` needs a space inserted before the left brace. + if (Left.is(TT_PointerOrReference) && Right.is(tok::l_brace)) + return true; + return spaceRequiredBetween(Line, Left, Right); } Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -10581,5 +10581,9 @@ verifyNoCrash("#define a\\\n /**/}"); } +TEST_F(FormatTest, IncludeSpaceBeforeLambdaBody) { + verifyFormat("int *p = []() -> int * { return nullptr; }();"); +} + } // end namespace tooling } // end namespace clang