Skip to content

Commit f03bf8c

Browse files
authored
[clang-format] Don't change breaking before CtorInitializerColon (#119522)
Don't change breaking before CtorInitializerColon with `ColumnLimit: 0`. Fixes #119519.
1 parent 9b3d85f commit f03bf8c

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
461461
getColumnLimit(State) ||
462462
CurrentState.BreakBeforeParameter) &&
463463
(!Current.isTrailingComment() || Current.NewlinesBefore > 0) &&
464-
(Style.AllowShortFunctionsOnASingleLine != FormatStyle::SFS_All ||
465-
Style.BreakConstructorInitializers != FormatStyle::BCIS_BeforeColon ||
466-
Style.ColumnLimit != 0)) {
464+
(Style.BreakConstructorInitializers != FormatStyle::BCIS_BeforeColon ||
465+
Style.ColumnLimit > 0 || Current.NewlinesBefore > 0)) {
467466
return true;
468467
}
469468

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ class AnnotatingParser {
492492
ProbablyFunctionType && CurrentToken->Next &&
493493
(CurrentToken->Next->is(tok::l_paren) ||
494494
(CurrentToken->Next->is(tok::l_square) &&
495-
Line.MustBeDeclaration))) {
495+
(Line.MustBeDeclaration ||
496+
PrevNonComment->isTypeName(LangOpts))))) {
496497
OpeningParen.setType(OpeningParen.Next->is(tok::caret)
497498
? TT_ObjCBlockLParen
498499
: TT_FunctionTypeLParen);

clang/unittests/Format/FormatTest.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14503,10 +14503,13 @@ TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {
1450314503
FormatStyle DoNotMergeNoColumnLimit = NoColumnLimit;
1450414504
DoNotMergeNoColumnLimit.AllowShortFunctionsOnASingleLine =
1450514505
FormatStyle::SFS_None;
14506-
verifyFormat("A()\n"
14507-
" : b(0) {\n"
14506+
verifyFormat("A() : b(0) {\n"
1450814507
"}",
14509-
"A():b(0){}", DoNotMergeNoColumnLimit);
14508+
DoNotMergeNoColumnLimit);
14509+
verifyNoChange("A()\n"
14510+
" : b(0) {\n"
14511+
"}",
14512+
DoNotMergeNoColumnLimit);
1451014513
verifyFormat("A()\n"
1451114514
" : b(0) {\n"
1451214515
"}",

0 commit comments

Comments
 (0)