[clang] 6e77ba6 - [clang-format] Fix weird handling of AfterColon
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 23 23:34:36 PDT 2023
Author: Björn Schäpers
Date: 2023-08-24T08:34:22+02:00
New Revision: 6e77ba6c1e4d2945a37169f6c7b3531ba39898b5
URL: https://github.com/llvm/llvm-project/commit/6e77ba6c1e4d2945a37169f6c7b3531ba39898b5
DIFF: https://github.com/llvm/llvm-project/commit/6e77ba6c1e4d2945a37169f6c7b3531ba39898b5.diff
LOG: [clang-format] Fix weird handling of AfterColon
Fixes #64895.
Differential Revision: https://reviews.llvm.org/D158505
Added:
Modified:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 12c12a8029a61a..3a6575d03ae18a 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1492,6 +1492,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
CurrentState.NestedBlockIndent = CurrentState.Indent;
if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack)
CurrentState.AvoidBinPacking = true;
+ else
+ CurrentState.BreakBeforeParameter = false;
}
if (Current.is(TT_InheritanceColon)) {
CurrentState.Indent =
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 900248684f1264..5fc0ed03a5aadb 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7950,6 +7950,11 @@ TEST_F(FormatTest, BreakConstructorInitializersAfterColon) {
verifyFormat("template <typename T>\n"
"Constructor() : Initializer(FitsOnTheLine) {}",
getStyleWithColumns(Style, 50));
+ verifyFormat(
+ "Class::Class(int some, int arguments, int loooooooooooooooooooong,\n"
+ " int mooooooooooooore) noexcept :\n"
+ " Super{some, arguments}, Member{5}, Member2{2} {}",
+ Style);
Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
verifyFormat(
"SomeClass::Constructor() :\n"
@@ -7986,10 +7991,10 @@ TEST_F(FormatTest, BreakConstructorInitializersAfterColon) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa),\n"
" aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {}",
Style);
- verifyFormat("Constructor(aaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) :\n"
- " aaaaaaaaaa(aaaaaa) {}",
- Style);
+ verifyFormat(
+ "Ctor(aaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) : aaaaaaaaaa(aaaaaa) {}",
+ Style);
verifyFormat("Constructor() :\n"
" aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa),\n"
More information about the cfe-commits
mailing list