https://github.com/mwdmwd created https://github.com/llvm/llvm-project/pull/235553
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 >From f4e40d05ebe109db4b0fc0db79958148c5865004 Mon Sep 17 00:00:00 2001 From: Piotr Wojnarowski <[email protected]> Date: Mon, 26 Oct 2026 01:30:12 +0100 Subject: [PATCH] [clang-format] Fix tabs in aligned ForIndentation continuations 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. Cover the continued call and inline braced initializer alignment in tests so the fix retains the initializer improvement from the original commit. Assisted-by: Codex --- clang/lib/Format/WhitespaceManager.cpp | 9 ++++++--- clang/unittests/Format/AlignmentTest.cpp | 25 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) 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 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
