aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2024-07-11 19:36:42 -0700
committerGitHub <noreply@github.com>2024-07-11 19:36:42 -0700
commitdcf6b7a8ea9a9be04dd66d20e4a7c55cd0f50a11 (patch)
tree897ee34f71815673b6408e65704c755344eab633 /clang
parent56b73f2a73b082c7b6a17cad37799fc218436be1 (diff)
downloadllvm-dcf6b7a8ea9a9be04dd66d20e4a7c55cd0f50a11.zip
llvm-dcf6b7a8ea9a9be04dd66d20e4a7c55cd0f50a11.tar.gz
llvm-dcf6b7a8ea9a9be04dd66d20e4a7c55cd0f50a11.tar.bz2
[clang-format] Fix a bug in TCAS_Leave using tabs for indentation (#98427)
Fixes #92530.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp2
-rw-r--r--clang/unittests/Format/FormatTestComments.cpp17
2 files changed, 18 insertions, 1 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 50531ae..a31874a 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1116,7 +1116,7 @@ void WhitespaceManager::alignTrailingComments() {
// leave the comments.
if (RestoredLineLength >= Style.ColumnLimit && Style.ColumnLimit > 0)
break;
- C.Spaces = OriginalSpaces;
+ C.Spaces = C.NewlinesBefore > 0 ? C.Tok->OriginalColumn : OriginalSpaces;
continue;
}
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index 3e75707..8f84d59 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -3145,6 +3145,23 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) {
"int bar = 1234; // This is a very long comment\n"
" // which is wrapped arround.",
Style));
+
+ Style = getLLVMStyle();
+ Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Leave;
+ Style.TabWidth = 2;
+ Style.UseTab = FormatStyle::UT_ForIndentation;
+ verifyNoChange("{\n"
+ "\t// f\n"
+ "\tf();\n"
+ "\n"
+ "\t// g\n"
+ "\tg();\n"
+ "\t{\n"
+ "\t\t// h(); // h\n"
+ "\t\tfoo(); // foo\n"
+ "\t}\n"
+ "}",
+ Style);
}
TEST_F(FormatTestComments, DontAlignNamespaceComments) {