Skip to content

Commit d9593c1

Browse files
authored
[clang-format] Fix a bug in indenting lambda trailing arrows (#94560)
Closes #94181
1 parent 39f09e8 commit d9593c1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

clang/lib/Format/ContinuationIndenter.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,11 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
12571257
}
12581258
return CurrentState.Indent;
12591259
}
1260+
if (Current.is(TT_TrailingReturnArrow) &&
1261+
Previous.isOneOf(tok::kw_noexcept, tok::kw_mutable, tok::kw_constexpr,
1262+
tok::kw_consteval, tok::kw_static, TT_AttributeSquare)) {
1263+
return ContinuationIndent;
1264+
}
12601265
if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
12611266
(Current.is(tok::greater) && (Style.isProto() || Style.isTableGen()))) &&
12621267
State.Stack.size() > 1) {

clang/unittests/Format/FormatTest.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -22866,6 +22866,22 @@ TEST_F(FormatTest, FormatsLambdas) {
2286622866
" //\n"
2286722867
" });");
2286822868

22869+
FormatStyle LLVMStyle = getLLVMStyleWithColumns(60);
22870+
verifyFormat("very_long_function_name_yes_it_is_really_long(\n"
22871+
" [](auto n) noexcept [[back_attr]]\n"
22872+
" -> std::unordered_map<very_long_type_name_A,\n"
22873+
" very_long_type_name_B> {\n"
22874+
" really_do_something();\n"
22875+
" });",
22876+
LLVMStyle);
22877+
verifyFormat("very_long_function_name_yes_it_is_really_long(\n"
22878+
" [](auto n) constexpr\n"
22879+
" -> std::unordered_map<very_long_type_name_A,\n"
22880+
" very_long_type_name_B> {\n"
22881+
" really_do_something();\n"
22882+
" });",
22883+
LLVMStyle);
22884+
2286922885
FormatStyle DoNotMerge = getLLVMStyle();
2287022886
DoNotMerge.AllowShortLambdasOnASingleLine = FormatStyle::SLS_None;
2287122887
verifyFormat("auto c = []() {\n"

0 commit comments

Comments
 (0)