diff options
author | Owen Pan <owenpiano@gmail.com> | 2024-01-31 20:20:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-31 20:20:26 -0800 |
commit | 908fd09a13b2e89a52282478544f7f70cf0a887f (patch) | |
tree | 9f76aad08ef9fab2d258d375ec654dc4578860e4 /clang/unittests/Format | |
parent | a8279a8bc541b6027087dd497daa63b6602b7f4b (diff) | |
download | llvm-908fd09a13b2e89a52282478544f7f70cf0a887f.zip llvm-908fd09a13b2e89a52282478544f7f70cf0a887f.tar.gz llvm-908fd09a13b2e89a52282478544f7f70cf0a887f.tar.bz2 |
[clang-format] Simplify the AfterPlacementOperator option (#79796)
Change AfterPlacementOperator to a boolean and deprecate SBPO_Never,
which meant never inserting a space except when after new/delete.
Fixes #78892.
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r-- | clang/unittests/Format/ConfigParseTest.cpp | 19 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 32 |
2 files changed, 15 insertions, 36 deletions
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index 2a8d793..6436581 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -231,6 +231,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) { AfterFunctionDefinitionName); CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterIfMacros); CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterOverloadedOperator); + CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, AfterPlacementOperator); CHECK_PARSE_NESTED_BOOL(SpaceBeforeParensOptions, BeforeNonEmptyParentheses); CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InCStyleCasts); CHECK_PARSE_NESTED_BOOL(SpacesInParensOptions, InConditionalStatements); @@ -609,24 +610,6 @@ TEST(ConfigParseTest, ParsesConfiguration) { SpaceBeforeParens, FormatStyle::SBPO_ControlStatementsExceptControlMacros); - Style.SpaceBeforeParens = FormatStyle::SBPO_Custom; - Style.SpaceBeforeParensOptions.AfterPlacementOperator = - FormatStyle::SpaceBeforeParensCustom::APO_Always; - CHECK_PARSE("SpaceBeforeParensOptions:\n" - " AfterPlacementOperator: Never", - SpaceBeforeParensOptions.AfterPlacementOperator, - FormatStyle::SpaceBeforeParensCustom::APO_Never); - - CHECK_PARSE("SpaceBeforeParensOptions:\n" - " AfterPlacementOperator: Always", - SpaceBeforeParensOptions.AfterPlacementOperator, - FormatStyle::SpaceBeforeParensCustom::APO_Always); - - CHECK_PARSE("SpaceBeforeParensOptions:\n" - " AfterPlacementOperator: Leave", - SpaceBeforeParensOptions.AfterPlacementOperator, - FormatStyle::SpaceBeforeParensCustom::APO_Leave); - // For backward compatibility: Style.SpacesInParens = FormatStyle::SIPO_Never; Style.SpacesInParensOptions = {}; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index e5e763e..a471e36 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -11347,35 +11347,31 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) { FormatStyle AfterPlacementOperator = getLLVMStyle(); AfterPlacementOperator.SpaceBeforeParens = FormatStyle::SBPO_Custom; - EXPECT_EQ( - AfterPlacementOperator.SpaceBeforeParensOptions.AfterPlacementOperator, - FormatStyle::SpaceBeforeParensCustom::APO_Leave); + EXPECT_TRUE( + AfterPlacementOperator.SpaceBeforeParensOptions.AfterPlacementOperator); verifyFormat("new (buf) int;", AfterPlacementOperator); - verifyFormat("new(buf) int;", AfterPlacementOperator); - - AfterPlacementOperator.SpaceBeforeParensOptions.AfterPlacementOperator = - FormatStyle::SpaceBeforeParensCustom::APO_Never; verifyFormat("struct A {\n" " int *a;\n" - " A(int *p) : a(new(p) int) {\n" - " new(p) int;\n" - " int *b = new(p) int;\n" - " int *c = new(p) int(3);\n" - " delete(b);\n" + " A(int *p) : a(new (p) int) {\n" + " new (p) int;\n" + " int *b = new (p) int;\n" + " int *c = new (p) int(3);\n" + " delete (b);\n" " }\n" "};", AfterPlacementOperator); verifyFormat("void operator new(void *foo) ATTRIB;", AfterPlacementOperator); AfterPlacementOperator.SpaceBeforeParensOptions.AfterPlacementOperator = - FormatStyle::SpaceBeforeParensCustom::APO_Always; + false; + verifyFormat("new(buf) int;", AfterPlacementOperator); verifyFormat("struct A {\n" " int *a;\n" - " A(int *p) : a(new (p) int) {\n" - " new (p) int;\n" - " int *b = new (p) int;\n" - " int *c = new (p) int(3);\n" - " delete (b);\n" + " A(int *p) : a(new(p) int) {\n" + " new(p) int;\n" + " int *b = new(p) int;\n" + " int *c = new(p) int(3);\n" + " delete(b);\n" " }\n" "};", AfterPlacementOperator); |