This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdbc4d281bd69: [clang-format] Do not insert space after
new/delete keywords in C function… (authored by penagos, committed by curdeius).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120374/new/
https://reviews.llvm.org/D120374
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9919,6 +9919,11 @@
verifyFormat("void operator new(void *foo) ATTRIB;");
verifyFormat("void operator delete[](void *foo) ATTRIB;");
verifyFormat("void operator delete(void *ptr) noexcept;");
+
+ EXPECT_EQ("void new(link p);\n"
+ "void delete(link p);\n",
+ format("void new (link p);\n"
+ "void delete (link p);\n"));
}
TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3299,11 +3299,15 @@
if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch))
return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
- if (Left.isOneOf(tok::kw_new, tok::kw_delete) ||
- (Left.is(tok::r_square) && Left.MatchingParen &&
- Left.MatchingParen->Previous &&
- Left.MatchingParen->Previous->is(tok::kw_delete)))
- return Style.SpaceBeforeParens != FormatStyle::SBPO_Never ||
+ if (Left.isOneOf(tok::kw_new, tok::kw_delete))
+ return ((!Line.MightBeFunctionDecl || !Left.Previous) &&
+ Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
+ spaceRequiredBeforeParens(Right);
+
+ if (Left.is(tok::r_square) && Left.MatchingParen &&
+ Left.MatchingParen->Previous &&
+ Left.MatchingParen->Previous->is(tok::kw_delete))
+ return (Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
spaceRequiredBeforeParens(Right);
}
if (Line.Type != LT_PreprocessorDirective &&
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9919,6 +9919,11 @@
verifyFormat("void operator new(void *foo) ATTRIB;");
verifyFormat("void operator delete[](void *foo) ATTRIB;");
verifyFormat("void operator delete(void *ptr) noexcept;");
+
+ EXPECT_EQ("void new(link p);\n"
+ "void delete(link p);\n",
+ format("void new (link p);\n"
+ "void delete (link p);\n"));
}
TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3299,11 +3299,15 @@
if (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch))
return Style.SpaceBeforeParensOptions.AfterControlStatements ||
spaceRequiredBeforeParens(Right);
- if (Left.isOneOf(tok::kw_new, tok::kw_delete) ||
- (Left.is(tok::r_square) && Left.MatchingParen &&
- Left.MatchingParen->Previous &&
- Left.MatchingParen->Previous->is(tok::kw_delete)))
- return Style.SpaceBeforeParens != FormatStyle::SBPO_Never ||
+ if (Left.isOneOf(tok::kw_new, tok::kw_delete))
+ return ((!Line.MightBeFunctionDecl || !Left.Previous) &&
+ Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
+ spaceRequiredBeforeParens(Right);
+
+ if (Left.is(tok::r_square) && Left.MatchingParen &&
+ Left.MatchingParen->Previous &&
+ Left.MatchingParen->Previous->is(tok::kw_delete))
+ return (Style.SpaceBeforeParens != FormatStyle::SBPO_Never) ||
spaceRequiredBeforeParens(Right);
}
if (Line.Type != LT_PreprocessorDirective &&
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits