Author: Owen Pan Date: 2024-07-11T19:36:42-07:00 New Revision: dcf6b7a8ea9a9be04dd66d20e4a7c55cd0f50a11
URL: https://github.com/llvm/llvm-project/commit/dcf6b7a8ea9a9be04dd66d20e4a7c55cd0f50a11 DIFF: https://github.com/llvm/llvm-project/commit/dcf6b7a8ea9a9be04dd66d20e4a7c55cd0f50a11.diff LOG: [clang-format] Fix a bug in TCAS_Leave using tabs for indentation (#98427) Fixes #92530. Added: Modified: clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/FormatTestComments.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 50531aee9d597..a31874a7c3195 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 3e75707a9faec..8f84d59cbb2e2 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) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits