https://github.com/zeule created https://github.com/llvm/llvm-project/pull/189218
None >From d9a3df4c368001e1de7936c43da1be39a9a32385 Mon Sep 17 00:00:00 2001 From: Eugene Shalygin <[email protected]> Date: Fri, 27 Mar 2026 17:02:04 +0100 Subject: [PATCH] [clang-format] fix aligning inheritance lists with UT_AlignWithSpaces --- clang/lib/Format/ContinuationIndenter.cpp | 12 ++++++++++++ clang/unittests/Format/FormatTest.cpp | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index a388b74920e0b..8201706275776 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1237,6 +1237,18 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, Style.ContinuationIndentWidth; } } + if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma) { + if (Previous.isOneOf(TT_InheritanceComma, tok::comma) && + Current.isOneOf(tok::kw_private, tok::kw_protected, tok::kw_public)) { + CurrentState.IsAligned = true; + } + } + if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeColon) { + if (Previous.isOneOf(TT_InheritanceComma, tok::comma) && + Current.isOneOf(tok::kw_private, tok::kw_protected, tok::kw_public)) { + CurrentState.IsAligned = true; + } + } if ((PreviousNonComment && PreviousNonComment->isOneOf(tok::comma, tok::semi) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 3d55a814e6027..bf087387b1d2b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8433,6 +8433,18 @@ TEST_F(FormatTest, BreakConstructorInitializersAfterColon) { " : public aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" " public bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb {};", Style); + FormatStyle Tab = getLLVMStyleWithColumns(42); + Tab.IndentWidth = 4; + Tab.TabWidth = 4; + Tab.UseTab = FormatStyle::UT_AlignWithSpaces; + verifyFormat("class Foo : public aaaaaaaaa,\n" + " public bbbbbbbbb\n", + Tab); + verifyFormat("struct S {\n" + "\tclass Foo : public aaaaaaaaa,\n" + "\t public bbbbbbbbb {};\n" + "};", + Tab); } TEST_F(FormatTest, BreakConstructorInitializersAfterComma) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
