https://github.com/kadircet created https://github.com/llvm/llvm-project/pull/105168
ccae7b461be339e717d02f99ac857cf0bc7d17f 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 https://github.com/llvm/llvm-project/issues/105133. From 9b3cabc74ef33f02a42d13f46539be3367ca73ad Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya <kadir...@google.com> Date: Tue, 20 Aug 2024 19:40:42 +0200 Subject: [PATCH] [clang-format] Treat new expressions as simple functions ccae7b461be339e717d02f99ac857cf0bc7d17f 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 https://github.com/llvm/llvm-project/issues/105133. --- clang/lib/Format/ContinuationIndenter.cpp | 2 ++ clang/unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 46dafad65863dc..8f65a1445dc3a5 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -848,6 +848,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, const auto IsSimpleFunction = [&](const FormatToken &Tok) { if (!Tok.FakeLParens.empty() && Tok.FakeLParens.back() > prec::Unknown) return false; + if (Tok.is(tok::kw_new)) + return true; const auto *Previous = Tok.Previous; if (!Previous || (!Previous->isOneOf(TT_FunctionDeclarationLParen, TT_LambdaDefinitionLParen) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 794ccab3704534..bdaacd065a45d1 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9292,6 +9292,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) { " aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa)) &&\n" " aaaaaaaaaaaaaaaa);", Style); + verifyFormat( + "fooooooooooo(new BARRRRRRRRR(\n" + " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXZZZZZZZZZZZZZZZZZZZZZZZZZ()));", + Style); Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent; Style.BinPackArguments = false; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits