Skip to content

Commit dcf6b7a

Browse files
authored
[clang-format] Fix a bug in TCAS_Leave using tabs for indentation (#98427)
Fixes #92530.
1 parent 56b73f2 commit dcf6b7a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ void WhitespaceManager::alignTrailingComments() {
11161116
// leave the comments.
11171117
if (RestoredLineLength >= Style.ColumnLimit && Style.ColumnLimit > 0)
11181118
break;
1119-
C.Spaces = OriginalSpaces;
1119+
C.Spaces = C.NewlinesBefore > 0 ? C.Tok->OriginalColumn : OriginalSpaces;
11201120
continue;
11211121
}
11221122

clang/unittests/Format/FormatTestComments.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,6 +3145,23 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) {
31453145
"int bar = 1234; // This is a very long comment\n"
31463146
" // which is wrapped arround.",
31473147
Style));
3148+
3149+
Style = getLLVMStyle();
3150+
Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Leave;
3151+
Style.TabWidth = 2;
3152+
Style.UseTab = FormatStyle::UT_ForIndentation;
3153+
verifyNoChange("{\n"
3154+
"\t// f\n"
3155+
"\tf();\n"
3156+
"\n"
3157+
"\t// g\n"
3158+
"\tg();\n"
3159+
"\t{\n"
3160+
"\t\t// h(); // h\n"
3161+
"\t\tfoo(); // foo\n"
3162+
"\t}\n"
3163+
"}",
3164+
Style);
31483165
}
31493166

31503167
TEST_F(FormatTestComments, DontAlignNamespaceComments) {

0 commit comments

Comments
 (0)