https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241
>From 6ec2e5423026599fd2d90356e71b08d787c1989c Mon Sep 17 00:00:00 2001 From: Brad House <b...@brad-house.com> Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH 1/2] Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations Enabling AlignConsecutiveDeclarations also aligns function prototypes or declarations. This is often unexpected as typically function prototypes, especially in public headers, don't use any padding. Setting AlignFunctionDeclarations to false will skip this alignment. It is by default set to true to keep compatibility with prior versions to not make unexpected changes. Signed-off-by: Brad House <b...@brad-house.com> --- clang/docs/ClangFormatStyleOptions.rst | 140 ++++++++++++++++++--- clang/include/clang/Format/Format.h | 18 ++- clang/lib/Format/Format.cpp | 31 +++-- clang/lib/Format/WhitespaceManager.cpp | 2 +- clang/unittests/Format/ConfigParseTest.cpp | 6 + clang/unittests/Format/FormatTest.cpp | 22 +++- 6 files changed, 194 insertions(+), 25 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..b0e5901c4e68a0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -392,7 +392,8 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -409,7 +410,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -429,6 +430,21 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; + * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + .. _AlignConsecutiveBitFields: @@ -534,7 +550,8 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -551,7 +568,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -571,6 +588,21 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; + * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + .. _AlignConsecutiveDeclarations: @@ -676,7 +708,8 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -693,7 +726,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -713,6 +746,21 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; + * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + .. _AlignConsecutiveMacros: @@ -819,7 +867,8 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -836,7 +885,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -856,6 +905,21 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; + * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + .. _AlignConsecutiveShortCaseStatements: @@ -1081,7 +1145,8 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -1098,7 +1163,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -1118,6 +1183,21 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; + * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + .. _AlignConsecutiveTableGenCondOperatorColons: @@ -1221,7 +1301,8 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -1238,7 +1319,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -1258,6 +1339,21 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; + * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + .. _AlignConsecutiveTableGenDefinitionColons: @@ -1361,7 +1457,8 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -1378,7 +1475,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -1398,6 +1495,21 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; + * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + .. _AlignEscapedNewlines: diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index d8b62c7652a0f6..7828207a81436b 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -240,7 +240,8 @@ struct FormatStyle { /// int *p; /// int (*f)(); /// \endcode - bool AlignFunctionPointers; + /// \version 20 + bool AlignFunctionDeclarations; /// Only for ``AlignConsecutiveAssignments``. Whether short assignment /// operators are left-padded to the same length as long ones in order to /// put all assignment operators to the right of the left hand side. @@ -259,11 +260,26 @@ struct FormatStyle { /// a = 2; /// bbb >>= 2; /// \endcode + bool AlignFunctionPointers; + /// Only for ``AlignConsecutiveDeclarations``. Whether function declarations + /// are aligned. + /// \code + /// true: + /// unsigned int f1(void); + /// void f2(void); + /// size_t f3(void); + /// + /// false: + /// unsigned int f1(void); + /// void f2(void); + /// size_t f3(void); + /// \endcode bool PadOperators; bool operator==(const AlignConsecutiveStyle &R) const { return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines && AcrossComments == R.AcrossComments && AlignCompound == R.AlignCompound && + AlignFunctionDeclarations == R.AlignFunctionDeclarations && AlignFunctionPointers == R.AlignFunctionPointers && PadOperators == R.PadOperators; } diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index d2463b892fbb96..9bd12dd6b4dc71 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -48,39 +48,53 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> { FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/false, /*AcrossEmptyLines=*/false, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); IO.enumCase(Value, "Consecutive", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/false, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); IO.enumCase(Value, "AcrossEmptyLines", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/true, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); IO.enumCase(Value, "AcrossComments", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/false, /*AcrossComments=*/true, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); IO.enumCase(Value, "AcrossEmptyLinesAndComments", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/true, /*AcrossComments=*/true, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); // For backward compatibility. IO.enumCase(Value, "true", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/true, /*AcrossEmptyLines=*/false, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/false, /*AcrossEmptyLines=*/false, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); } static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) { @@ -88,6 +102,8 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> { IO.mapOptional("AcrossEmptyLines", Value.AcrossEmptyLines); IO.mapOptional("AcrossComments", Value.AcrossComments); IO.mapOptional("AlignCompound", Value.AlignCompound); + IO.mapOptional("AlignFunctionDeclarations", + Value.AlignFunctionDeclarations); IO.mapOptional("AlignFunctionPointers", Value.AlignFunctionPointers); IO.mapOptional("PadOperators", Value.PadOperators); } @@ -1448,6 +1464,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.AlignConsecutiveAssignments.PadOperators = true; LLVMStyle.AlignConsecutiveBitFields = {}; LLVMStyle.AlignConsecutiveDeclarations = {}; + LLVMStyle.AlignConsecutiveDeclarations.AlignFunctionDeclarations = true; LLVMStyle.AlignConsecutiveMacros = {}; LLVMStyle.AlignConsecutiveShortCaseStatements = {}; LLVMStyle.AlignConsecutiveTableGenBreakingDAGArgColons = {}; diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index fd4a40a86082e2..b6b24672f6a39d 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -1020,7 +1020,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() { return true; } if (C.Tok->is(TT_FunctionDeclarationName)) - return true; + return Style.AlignConsecutiveDeclarations.AlignFunctionDeclarations; if (C.Tok->isNot(TT_StartOfName)) return false; if (C.Tok->Previous && diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index b8bdfaaa74e10e..938eac99114a36 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -305,24 +305,28 @@ TEST(ConfigParseTest, ParsesConfiguration) { FormatStyle::AlignConsecutiveStyle( \ {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionDeclarations=*/true, \ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ CHECK_PARSE( \ #FIELD ": Consecutive", FIELD, \ FormatStyle::AlignConsecutiveStyle( \ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \ /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionDeclarations=*/true, \ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ CHECK_PARSE( \ #FIELD ": AcrossEmptyLines", FIELD, \ FormatStyle::AlignConsecutiveStyle( \ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \ /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionDeclarations=*/true, \ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ CHECK_PARSE( \ #FIELD ": AcrossEmptyLinesAndComments", FIELD, \ FormatStyle::AlignConsecutiveStyle( \ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \ /*AcrossComments=*/true, /*AlignCompound=*/false, \ + /*AlignFunctionDeclarations=*/true, \ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ /* For backwards compability, false / true should still parse */ \ CHECK_PARSE( \ @@ -330,12 +334,14 @@ TEST(ConfigParseTest, ParsesConfiguration) { FormatStyle::AlignConsecutiveStyle( \ {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionDeclarations=*/true, \ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ CHECK_PARSE( \ #FIELD ": true", FIELD, \ FormatStyle::AlignConsecutiveStyle( \ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \ /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionDeclarations=*/true, \ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ \ CHECK_PARSE_NESTED_BOOL(FIELD, Enabled); \ diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 5ebf0d7068dd6c..22cecc01484693 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -20010,6 +20010,17 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { " return 0;\n" "}() };", BracedAlign); + + Alignment.AlignConsecutiveDeclarations.AlignFunctionDeclarations = false; + verifyFormat("unsigned int f1(void);\n" + "void f2(void);\n" + "size_t f3(void);\n", + Alignment); + Alignment.AlignConsecutiveDeclarations.AlignFunctionDeclarations = true; + verifyFormat("unsigned int f1(void);\n" + "void f2(void);\n" + "size_t f3(void);\n", + Alignment); } TEST_F(FormatTest, AlignConsecutiveShortCaseStatements) { @@ -20253,9 +20264,16 @@ TEST_F(FormatTest, AlignWithLineBreaks) { FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/false, /*AcrossEmptyLines=*/false, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/false, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/true})); EXPECT_EQ(Style.AlignConsecutiveDeclarations, - FormatStyle::AlignConsecutiveStyle({})); + FormatStyle::AlignConsecutiveStyle( + {/*Enabled=*/false, /*AcrossEmptyLines=*/false, + /*AcrossComments=*/false, /*AlignCompound=*/false, + /*AlignFunctionDeclarations=*/true, + /*AlignFunctionPointers=*/false, + /*PadOperators=*/false})); verifyFormat("void foo() {\n" " int myVar = 5;\n" " double x = 3.14;\n" >From 3a0f48355ae4d9de083c5825a84944ab74f3ed56 Mon Sep 17 00:00:00 2001 From: Brad House <b...@brad-house.com> Date: Wed, 18 Sep 2024 06:33:48 -0400 Subject: [PATCH 2/2] fix --- clang/docs/ClangFormatStyleOptions.rst | 238 ++++++++++++------------- clang/include/clang/Format/Format.h | 32 ++-- 2 files changed, 135 insertions(+), 135 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index b0e5901c4e68a0..042c5f1b5f15b0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -393,7 +393,22 @@ the configuration (without a prefix: ``Auto``). bbb = 2; * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` - Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -410,7 +425,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -430,21 +445,6 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; - * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations - are aligned. - - .. code-block:: c++ - - true: - unsigned int f1(void); - void f2(void); - size_t f3(void); - - false: - unsigned int f1(void); - void f2(void); - size_t f3(void); - .. _AlignConsecutiveBitFields: @@ -551,7 +551,22 @@ the configuration (without a prefix: ``Auto``). bbb = 2; * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` - Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -568,7 +583,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -588,21 +603,6 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; - * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations - are aligned. - - .. code-block:: c++ - - true: - unsigned int f1(void); - void f2(void); - size_t f3(void); - - false: - unsigned int f1(void); - void f2(void); - size_t f3(void); - .. _AlignConsecutiveDeclarations: @@ -709,7 +709,22 @@ the configuration (without a prefix: ``Auto``). bbb = 2; * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` - Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -726,7 +741,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -746,21 +761,6 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; - * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations - are aligned. - - .. code-block:: c++ - - true: - unsigned int f1(void); - void f2(void); - size_t f3(void); - - false: - unsigned int f1(void); - void f2(void); - size_t f3(void); - .. _AlignConsecutiveMacros: @@ -868,7 +868,22 @@ the configuration (without a prefix: ``Auto``). bbb = 2; * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` - Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -885,7 +900,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -905,21 +920,6 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; - * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations - are aligned. - - .. code-block:: c++ - - true: - unsigned int f1(void); - void f2(void); - size_t f3(void); - - false: - unsigned int f1(void); - void f2(void); - size_t f3(void); - .. _AlignConsecutiveShortCaseStatements: @@ -1146,7 +1146,22 @@ the configuration (without a prefix: ``Auto``). bbb = 2; * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` - Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -1163,7 +1178,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -1183,21 +1198,6 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; - * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations - are aligned. - - .. code-block:: c++ - - true: - unsigned int f1(void); - void f2(void); - size_t f3(void); - - false: - unsigned int f1(void); - void f2(void); - size_t f3(void); - .. _AlignConsecutiveTableGenCondOperatorColons: @@ -1302,7 +1302,22 @@ the configuration (without a prefix: ``Auto``). bbb = 2; * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` - Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -1319,7 +1334,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -1339,21 +1354,6 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; - * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations - are aligned. - - .. code-block:: c++ - - true: - unsigned int f1(void); - void f2(void); - size_t f3(void); - - false: - unsigned int f1(void); - void f2(void); - size_t f3(void); - .. _AlignConsecutiveTableGenDefinitionColons: @@ -1458,7 +1458,22 @@ the configuration (without a prefix: ``Auto``). bbb = 2; * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` - Only for ``AlignConsecutiveDeclarations``. Whether function pointers are + Only for ``AlignConsecutiveDeclarations``. Whether function declarations + are aligned. + + .. code-block:: c++ + + true: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + false: + unsigned int f1(void); + void f2(void); + size_t f3(void); + + * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveDeclarations``. Whether function pointers are aligned. .. code-block:: c++ @@ -1475,7 +1490,7 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); - * ``bool AlignFunctionPointers`` Only for ``AlignConsecutiveAssignments``. Whether short assignment + * ``bool PadOperators`` Only for ``AlignConsecutiveAssignments``. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side. @@ -1495,21 +1510,6 @@ the configuration (without a prefix: ``Auto``). a = 2; bbb >>= 2; - * ``bool PadOperators`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations - are aligned. - - .. code-block:: c++ - - true: - unsigned int f1(void); - void f2(void); - size_t f3(void); - - false: - unsigned int f1(void); - void f2(void); - size_t f3(void); - .. _AlignEscapedNewlines: diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 7828207a81436b..759a7dc7ce8165 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -225,6 +225,21 @@ struct FormatStyle { /// bbb = 2; /// \endcode bool AlignCompound; + /// Only for ``AlignConsecutiveDeclarations``. Whether function declarations + /// are aligned. + /// \code + /// true: + /// unsigned int f1(void); + /// void f2(void); + /// size_t f3(void); + /// + /// false: + /// unsigned int f1(void); + /// void f2(void); + /// size_t f3(void); + /// \endcode + /// \version 20 + bool AlignFunctionDeclarations; /// Only for ``AlignConsecutiveDeclarations``. Whether function pointers are /// aligned. /// \code @@ -240,8 +255,7 @@ struct FormatStyle { /// int *p; /// int (*f)(); /// \endcode - /// \version 20 - bool AlignFunctionDeclarations; + bool AlignFunctionPointers; /// Only for ``AlignConsecutiveAssignments``. Whether short assignment /// operators are left-padded to the same length as long ones in order to /// put all assignment operators to the right of the left hand side. @@ -260,20 +274,6 @@ struct FormatStyle { /// a = 2; /// bbb >>= 2; /// \endcode - bool AlignFunctionPointers; - /// Only for ``AlignConsecutiveDeclarations``. Whether function declarations - /// are aligned. - /// \code - /// true: - /// unsigned int f1(void); - /// void f2(void); - /// size_t f3(void); - /// - /// false: - /// unsigned int f1(void); - /// void f2(void); - /// size_t f3(void); - /// \endcode bool PadOperators; bool operator==(const AlignConsecutiveStyle &R) const { return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines && _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits