Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3310,6 +3310,10 @@ } } + // Lambda with trailing return type 'auto': []() -> auto { return T; } + if (Left.is(tok::kw_auto) && Right.getType() == TT_LambdaLBrace) + return true; + // auto{x} auto(x) if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace)) return false; Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -2108,6 +2108,7 @@ case tok::l_square: parseSquare(); break; + case tok::kw_auto: case tok::kw_class: case tok::kw_template: case tok::kw_typename: Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23550,6 +23550,13 @@ verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle); } +TEST_F(FormatTest, LambdaWithTrailingAutoInBracedList) { + FormatStyle Style = getLLVMStyle(); + verifyFormat("auto list = {[]() -> auto { return Val; }};", Style); + verifyFormat("auto list = {[]() -> auto * { return Ptr; }};", Style); + verifyFormat("auto list = {[]() -> auto & { return Ref; }};", Style); +} + TEST_F(FormatTest, SpacesInConditionalStatement) { FormatStyle Spaces = getLLVMStyle(); Spaces.IfMacros.clear();