diff options
author | Gedare Bloom <gedare@rtems.org> | 2024-01-10 20:35:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 19:35:03 -0800 |
commit | b2c0c6f3f2741415d5257e16ca8d4083abe1b487 (patch) | |
tree | 7c0f6edae65c700444a533d4f2af8afc45db622d /clang/unittests/Format/ConfigParseTest.cpp | |
parent | cc77e33271371e6ea29569ba06db9cfd1aac022a (diff) | |
download | llvm-b2c0c6f3f2741415d5257e16ca8d4083abe1b487.zip llvm-b2c0c6f3f2741415d5257e16ca8d4083abe1b487.tar.gz llvm-b2c0c6f3f2741415d5257e16ca8d4083abe1b487.tar.bz2 |
[clang-format]: Split alignment of declarations around assignment (#69340)
Function pointers are detected as a type of declaration using
FunctionTypeLParen. They are aligned based on rules for
AlignConsecutiveDeclarations. When a function pointer is on the
right-hand side of an assignment, the alignment of the function pointer
can result in excessive whitespace padding due to the ordering of
alignment, as the alignment processes a line from left-to-right and
first aligns the declarations before and after the assignment operator,
and then aligns the assignment operator. Injection of whitespace by
alignment of declarations after the equal sign followed by alignment of
the equal sign results in the excessive whitespace.
Fixes #68079.
Diffstat (limited to 'clang/unittests/Format/ConfigParseTest.cpp')
-rw-r--r-- | clang/unittests/Format/ConfigParseTest.cpp | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index 0c9f68f..18ecba2 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -289,37 +289,43 @@ TEST(ConfigParseTest, ParsesConfiguration) { #define CHECK_ALIGN_CONSECUTIVE(FIELD) \ do { \ Style.FIELD.Enabled = true; \ - CHECK_PARSE(#FIELD ": None", FIELD, \ - FormatStyle::AlignConsecutiveStyle( \ - {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ - /*AcrossComments=*/false, /*AlignCompound=*/false, \ - /*PadOperators=*/true})); \ - CHECK_PARSE(#FIELD ": Consecutive", FIELD, \ - FormatStyle::AlignConsecutiveStyle( \ - {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \ - /*AcrossComments=*/false, /*AlignCompound=*/false, \ - /*PadOperators=*/true})); \ - CHECK_PARSE(#FIELD ": AcrossEmptyLines", FIELD, \ - FormatStyle::AlignConsecutiveStyle( \ - {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \ - /*AcrossComments=*/false, /*AlignCompound=*/false, \ - /*PadOperators=*/true})); \ - CHECK_PARSE(#FIELD ": AcrossEmptyLinesAndComments", FIELD, \ - FormatStyle::AlignConsecutiveStyle( \ - {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \ - /*AcrossComments=*/true, /*AlignCompound=*/false, \ - /*PadOperators=*/true})); \ + CHECK_PARSE( \ + #FIELD ": None", FIELD, \ + FormatStyle::AlignConsecutiveStyle( \ + {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ + /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ + CHECK_PARSE( \ + #FIELD ": Consecutive", FIELD, \ + FormatStyle::AlignConsecutiveStyle( \ + {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \ + /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ + CHECK_PARSE( \ + #FIELD ": AcrossEmptyLines", FIELD, \ + FormatStyle::AlignConsecutiveStyle( \ + {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \ + /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ + CHECK_PARSE( \ + #FIELD ": AcrossEmptyLinesAndComments", FIELD, \ + FormatStyle::AlignConsecutiveStyle( \ + {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \ + /*AcrossComments=*/true, /*AlignCompound=*/false, \ + /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ /* For backwards compability, false / true should still parse */ \ - CHECK_PARSE(#FIELD ": false", FIELD, \ - FormatStyle::AlignConsecutiveStyle( \ - {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ - /*AcrossComments=*/false, /*AlignCompound=*/false, \ - /*PadOperators=*/true})); \ - CHECK_PARSE(#FIELD ": true", FIELD, \ - FormatStyle::AlignConsecutiveStyle( \ - {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \ - /*AcrossComments=*/false, /*AlignCompound=*/false, \ - /*PadOperators=*/true})); \ + CHECK_PARSE( \ + #FIELD ": false", FIELD, \ + FormatStyle::AlignConsecutiveStyle( \ + {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ + /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ + CHECK_PARSE( \ + #FIELD ": true", FIELD, \ + FormatStyle::AlignConsecutiveStyle( \ + {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \ + /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ \ CHECK_PARSE_NESTED_BOOL(FIELD, Enabled); \ CHECK_PARSE_NESTED_BOOL(FIELD, AcrossEmptyLines); \ |