denis-fatkulin created this revision. denis-fatkulin added reviewers: HazardyKnusperkeks, curdeius. denis-fatkulin added a project: clang-format. Herald added a project: All. denis-fatkulin requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
There's no a space symbol between trailing return type `auto` and left brace `{`. The simpliest examles of code to reproduce the issue: []() -> auto {} and auto foo() -> auto {} Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D130417 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23550,6 +23550,12 @@ verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle); } +TEST_F(FormatTest, TrailingReturnTypeAuto) { + FormatStyle Style = getLLVMStyle(); + verifyFormat("[]() -> auto { return Val; }", Style); + verifyFormat("auto foo() -> auto { return Val; }", Style); +} + TEST_F(FormatTest, SpacesInConditionalStatement) { FormatStyle Spaces = getLLVMStyle(); Spaces.IfMacros.clear(); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3310,6 +3310,11 @@ } } + // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {} + if (Left.is(tok::kw_auto) && + Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace)) + return true; + // auto{x} auto(x) if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace)) return false;
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -23550,6 +23550,12 @@ verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle); } +TEST_F(FormatTest, TrailingReturnTypeAuto) { + FormatStyle Style = getLLVMStyle(); + verifyFormat("[]() -> auto { return Val; }", Style); + verifyFormat("auto foo() -> auto { return Val; }", Style); +} + TEST_F(FormatTest, SpacesInConditionalStatement) { FormatStyle Spaces = getLLVMStyle(); Spaces.IfMacros.clear(); Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3310,6 +3310,11 @@ } } + // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {} + if (Left.is(tok::kw_auto) && + Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace)) + return true; + // auto{x} auto(x) if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace)) return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits