[clang] [clang-format] Stop treating the new expression as a lambda (PR #223266)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 3 07:24:15 PDT 2026
================
@@ -3343,28 +3344,62 @@ void UnwrappedLineParser::parseNew() {
nextToken();
} while (!eof());
- }
+ } else if (Style.isJava()) {
+ // In Java, we can parse everything up to the parens, which aren't optional.
+ do {
+ // There should not be a ;, { or } before the new's open paren.
+ if (FormatTok->isOneOf(tok::semi, tok::l_brace, tok::r_brace))
+ return;
- if (!Style.isJava())
- return;
+ // Consume the parens.
+ if (FormatTok->is(tok::l_paren)) {
+ parseParens();
- // In Java, we can parse everything up to the parens, which aren't optional.
- do {
- // There should not be a ;, { or } before the new's open paren.
- if (FormatTok->isOneOf(tok::semi, tok::l_brace, tok::r_brace))
+ // If there is a class body of an anonymous class, consume that as
+ // child.
+ if (FormatTok->is(tok::l_brace))
+ parseChildBlock();
+ return;
+ }
+ nextToken();
+ } while (!eof());
+ } else if (Style.isCpp()) {
+ // The brace should not appear here in a new expression. It likely means
+ // that the line is incomplete or that new is not a keyword such as in
+ // Objective-C.
+ if (FormatTok->is(tok::l_brace))
return;
-
- // Consume the parens.
+ if (FormatTok->is(tok::l_paren))
----------------
sstwcw wrote:
I was thinking about code like this. Should the space be there?
```C++
#include <new>
void x() {
new (std::align_val_t(1)) (int);
new (std::align_val_t(1))(int);
}
```
https://github.com/llvm/llvm-project/pull/223266
More information about the cfe-commits
mailing list