llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: mwdmwd <details> <summary>Changes</summary> ForIndentation can inherit continuation spaces as an extra tab when aligning to a continued expression after 029e5b017bfd. Use the alignment anchor's block indentation for this mode. Validation: built 029e5b017bfd and its parent, 5b1b0efbaa97, with only the new regression test added. The test passes on 5b1b0efbaa97 but fails on 029e5b017bfd. It also passes with the `WhitespaceManager` changes from this PR. Fixes #<!-- -->235551 Assisted-by: Codex --- Full diff: https://github.com/llvm/llvm-project/pull/235553.diff 2 Files Affected: - (modified) clang/lib/Format/WhitespaceManager.cpp (+6-3) - (modified) clang/unittests/Format/AlignmentTest.cpp (+25) ``````````diff diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 314400a7fd45e4..1d5aec62008238 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -28,12 +28,15 @@ static const FormatToken &getLineStart(const FormatToken &Tok) { return *Result; } -static unsigned indentLevelFor(const WhitespaceManager::Change &C) { +static unsigned indentLevelFor(const WhitespaceManager::Change &C, + FormatStyle::UseTabStyle UseTab) { if (!C.AlignedTo) return C.Tok->IndentLevel; const FormatToken &LineStart = getLineStart(*C.AlignedTo); - return std::max(LineStart.IndentLevel, LineStart.AppliedIndentLevel); + return UseTab == FormatStyle::UT_ForIndentation + ? LineStart.IndentLevel + : std::max(LineStart.IndentLevel, LineStart.AppliedIndentLevel); } bool WhitespaceManager::Change::IsBeforeInFile::operator()( @@ -1633,7 +1636,7 @@ void WhitespaceManager::generateChanges() { } // FIXME: This assert should hold if we computed the column correctly. // assert((int)C.StartOfTokenColumn >= C.Spaces); - unsigned IndentLevel = indentLevelFor(C); + unsigned IndentLevel = indentLevelFor(C, Style.UseTab); appendIndentText(ReplacementText, IndentLevel, std::max(0, C.Spaces), std::max((int)C.StartOfTokenColumn, C.Spaces) - std::max(0, C.Spaces), diff --git a/clang/unittests/Format/AlignmentTest.cpp b/clang/unittests/Format/AlignmentTest.cpp index fbc0cb4d825ea3..b8ceb217abcaa8 100644 --- a/clang/unittests/Format/AlignmentTest.cpp +++ b/clang/unittests/Format/AlignmentTest.cpp @@ -3630,6 +3630,31 @@ TEST_F(AlignmentTest, ContinuedAligned) { Style); } +TEST_F(AlignmentTest, ContinuedAlignedForIndentation) { + FormatStyle Style = getLLVMStyleWithColumns(30); + Style.UseTab = FormatStyle::UT_ForIndentation; + Style.TabWidth = Style.IndentWidth = 4; + + verifyFormat("void f() {\n" + "\tabcdef =\n" + "\t foo(111111, 222222,\n" + "\t 333333);\n" + "}", + Style); +} + +TEST_F(AlignmentTest, InlineBracedListForIndentation) { + FormatStyle Style = getLLVMStyleWithColumns(30); + Style.UseTab = FormatStyle::UT_ForIndentation; + Style.TabWidth = Style.IndentWidth = 4; + Style.Cpp11BracedListStyle = FormatStyle::BLS_Block; + verifyFormat("void f() {\n" + "\tint a[] = { 1, 2, 3, 4, 5,\n" + "\t 6, 7, 8, 9 };\n" + "}", + Style); +} + } // namespace } // namespace test } // namespace format `````````` </details> https://github.com/llvm/llvm-project/pull/235553 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
