Skip to content

Commit ca40320

Browse files
author
git apple-llvm automerger
committed
Merge commit 'fcb91597e2e9' from llvm.org/release/21.x into stable/21.x
2 parents 3f6ae15 + fcb9159 commit ca40320

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,16 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
628628
// name.
629629
!Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
630630
CurrentState.BreakBeforeParameter) {
631-
for (const auto *Tok = &Previous; Tok; Tok = Tok->Previous)
632-
if (Tok->FirstAfterPPLine || Tok->is(TT_LineComment))
631+
for (const auto *Tok = &Previous; Tok; Tok = Tok->Previous) {
632+
if (Tok->is(TT_LineComment))
633633
return false;
634+
if (Tok->is(TT_TemplateCloser)) {
635+
Tok = Tok->MatchingParen;
636+
assert(Tok);
637+
}
638+
if (Tok->FirstAfterPPLine)
639+
return false;
640+
}
634641

635642
return true;
636643
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8596,14 +8596,22 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
85968596
verifyFormat("extern \"C\" //\n"
85978597
" void f();");
85988598

8599-
FormatStyle Style = getLLVMStyle();
8599+
auto Style = getLLVMStyle();
86008600
Style.PointerAlignment = FormatStyle::PAS_Left;
86018601
verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
86028602
" aaaaaaaaaaaaaaaaaaaaaaaaa* const aaaaaaaaaaaa) {}",
86038603
Style);
86048604
verifyFormat("void aaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*\n"
86058605
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}",
86068606
Style);
8607+
8608+
Style = getLLVMStyleWithColumns(45);
8609+
Style.PenaltyReturnTypeOnItsOwnLine = 400;
8610+
verifyFormat("template <bool abool, // a comment\n"
8611+
" bool anotherbool>\n"
8612+
"static inline std::pair<size_t, MyCustomType>\n"
8613+
"myfunc(const char *buf, const char *&err);",
8614+
Style);
86078615
}
86088616

86098617
TEST_F(FormatTest, DontBreakBeforeQualifiedOperator) {

0 commit comments

Comments
 (0)