diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 6b9fbfe0ebf53..d2a09802a1580 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1257,6 +1257,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) { } return CurrentState.Indent; } + if (Current.is(TT_TrailingReturnArrow) && + Previous.isOneOf(tok::kw_noexcept, tok::kw_mutable, tok::kw_constexpr, + tok::kw_consteval, tok::kw_static, TT_AttributeSquare)) { + return ContinuationIndent; + } if ((Current.isOneOf(tok::r_brace, tok::r_square) || (Current.is(tok::greater) && (Style.isProto() || Style.isTableGen()))) && State.Stack.size() > 1) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 4e427268fb82a..9bfb2fb728cd6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -22858,6 +22858,22 @@ TEST_F(FormatTest, FormatsLambdas) { " //\n" " });"); + FormatStyle LLVMStyle = getLLVMStyleWithColumns(60); + verifyFormat("very_long_function_name_yes_it_is_really_long(\n" + " [](auto n) noexcept [[back_attr]]\n" + " -> std::unordered_map {\n" + " really_do_something();\n" + " });", + LLVMStyle); + verifyFormat("very_long_function_name_yes_it_is_really_long(\n" + " [](auto n) constexpr\n" + " -> std::unordered_map {\n" + " really_do_something();\n" + " });", + LLVMStyle); + FormatStyle DoNotMerge = getLLVMStyle(); DoNotMerge.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None; verifyFormat("auto c = []() {\n"