Skip to content

Commit 024362f

Browse files
authored
[clang-format] Insert a space after kw_new by default (#129634)
This effectively reverts dbc4d28. Fix #54703
1 parent b488ce0 commit 024362f

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4845,16 +4845,11 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
48454845
return Style.SpaceBeforeParensOptions.AfterControlStatements ||
48464846
spaceRequiredBeforeParens(Right);
48474847
}
4848-
if (Left.isOneOf(tok::kw_new, tok::kw_delete)) {
4849-
return ((!Line.MightBeFunctionDecl || !BeforeLeft) &&
4850-
Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
4851-
spaceRequiredBeforeParens(Right);
4852-
}
4853-
4854-
if (Left.is(tok::r_square) && Left.MatchingParen &&
4855-
Left.MatchingParen->Previous &&
4856-
Left.MatchingParen->Previous->is(tok::kw_delete)) {
4857-
return (Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
4848+
if (Left.isOneOf(tok::kw_new, tok::kw_delete) ||
4849+
(Left.is(tok::r_square) && Left.MatchingParen &&
4850+
Left.MatchingParen->Previous &&
4851+
Left.MatchingParen->Previous->is(tok::kw_delete))) {
4852+
return Style.SpaceBeforeParens != FormatStyle::SBPO_Never ||
48584853
spaceRequiredBeforeParens(Right);
48594854
}
48604855
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12100,6 +12100,7 @@ TEST_F(FormatTest, PointerAlignmentFallback) {
1210012100
}
1210112101

1210212102
TEST_F(FormatTest, UnderstandsNewAndDelete) {
12103+
verifyFormat("A(void *p) : a(new (p) int) {}");
1210312104
verifyFormat("void f() {\n"
1210412105
" A *a = new A;\n"
1210512106
" A *a = new (placement) A;\n"
@@ -12122,7 +12123,8 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) {
1212212123
verifyFormat("void new(link p);\n"
1212312124
"void delete(link p);",
1212412125
"void new (link p);\n"
12125-
"void delete (link p);");
12126+
"void delete (link p);",
12127+
getLLVMStyle(FormatStyle::LK_C));
1212612128

1212712129
verifyFormat("{\n"
1212812130
" p->new();\n"

0 commit comments

Comments
 (0)