Skip to content

Commit 9b3cabc

Browse files
committed
[clang-format] Treat new expressions as simple functions
ccae7b4 improved handling for nested calls, but this resulted in a lot of changes near `new` expressions. This patch tries to restore previous behavior around new expressions, by treating them as simple functions, which seem to align with the concept. Fixes #105133.
1 parent 7aa22f0 commit 9b3cabc

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

clang/lib/Format/ContinuationIndenter.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
848848
const auto IsSimpleFunction = [&](const FormatToken &Tok) {
849849
if (!Tok.FakeLParens.empty() && Tok.FakeLParens.back() > prec::Unknown)
850850
return false;
851+
if (Tok.is(tok::kw_new))
852+
return true;
851853
const auto *Previous = Tok.Previous;
852854
if (!Previous || (!Previous->isOneOf(TT_FunctionDeclarationLParen,
853855
TT_LambdaDefinitionLParen) &&

clang/unittests/Format/FormatTest.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -9292,6 +9292,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
92929292
" aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa)) &&\n"
92939293
" aaaaaaaaaaaaaaaa);",
92949294
Style);
9295+
verifyFormat(
9296+
"fooooooooooo(new BARRRRRRRRR(\n"
9297+
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXZZZZZZZZZZZZZZZZZZZZZZZZZ()));",
9298+
Style);
92959299

92969300
Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
92979301
Style.BinPackArguments = false;

0 commit comments

Comments
 (0)