Author: Owen Pan Date: 2025-03-04T21:14:07-08:00 New Revision: 024362f413dbfcf8188003762c9cc299f274d76e
URL: https://github.com/llvm/llvm-project/commit/024362f413dbfcf8188003762c9cc299f274d76e DIFF: https://github.com/llvm/llvm-project/commit/024362f413dbfcf8188003762c9cc299f274d76e.diff LOG: [clang-format] Insert a space after kw_new by default (#129634) This effectively reverts dbc4d281bd6954362ccfc0747893ceaae842671b. Fix #54703 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 3a49650d95ba4..08539de405c67 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -4845,16 +4845,11 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return Style.SpaceBeforeParensOptions.AfterControlStatements || spaceRequiredBeforeParens(Right); } - if (Left.isOneOf(tok::kw_new, tok::kw_delete)) { - return ((!Line.MightBeFunctionDecl || !BeforeLeft) && - 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) || + 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 || spaceRequiredBeforeParens(Right); } } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f3948142da0c9..ae2eaf70de1c2 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -12100,6 +12100,7 @@ TEST_F(FormatTest, PointerAlignmentFallback) { } TEST_F(FormatTest, UnderstandsNewAndDelete) { + verifyFormat("A(void *p) : a(new (p) int) {}"); verifyFormat("void f() {\n" " A *a = new A;\n" " A *a = new (placement) A;\n" @@ -12122,7 +12123,8 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) { verifyFormat("void new(link p);\n" "void delete(link p);", "void new (link p);\n" - "void delete (link p);"); + "void delete (link p);", + getLLVMStyle(FormatStyle::LK_C)); verifyFormat("{\n" " p->new();\n" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits