-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-format] Treat new expressions as simple functions #105168
Conversation
@llvm/pr-subscribers-clang-format Author: kadir çetinkaya (kadircet) Changesccae7b4 improved handling for nested This patch tries to restore previous behavior around new expressions, by Fixes #105133. Full diff: https://github.com/llvm/llvm-project/pull/105168.diff 2 Files Affected:
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;
|
How does it look like without the new? |
|
9b3cabc
to
d0f1e70
Compare
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 llvm#105133.
d0f1e70
to
089699a
Compare
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 llvm#105133.
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.