[clang] Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 created https://github.com/llvm/llvm-project/pull/108241 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. Fixes #74320 Signed-off-by: Brad House >From e2091a7c50301c4a1e5c2eacb65a23bc0175e81a Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH] 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 --- clang/docs/ClangFormatStyleOptions.rst | 105 + clang/include/clang/Format/Format.h| 15 +++ clang/lib/Format/Format.cpp| 31 -- clang/lib/Format/WhitespaceManager.cpp | 2 +- clang/unittests/Format/ConfigParseTest.cpp | 24 +++-- clang/unittests/Format/FormatTest.cpp | 23 - 6 files changed, 184 insertions(+), 16 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..c862d57a19b954 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -409,6 +409,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -551,6 +566,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -693,6 +723,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -836,6 +881,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -1098,6 +1158,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 edited https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 89d238800f0287f29f95165e05530d3f5e397245 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH] 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 --- clang/docs/ClangFormatStyleOptions.rst | 105 + clang/include/clang/Format/Format.h| 15 +++ clang/lib/Format/Format.cpp| 31 -- clang/lib/Format/WhitespaceManager.cpp | 2 +- clang/unittests/Format/ConfigParseTest.cpp | 18 ++-- clang/unittests/Format/FormatTest.cpp | 22 - 6 files changed, 177 insertions(+), 16 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..c862d57a19b954 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -409,6 +409,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -551,6 +566,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -693,6 +723,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -836,6 +881,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -1098,6 +1158,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -1238,6 +1313,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + *
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
bradh352 wrote: I just corrected the formatting... https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 00cbf31807ca8d8e1c0c86c6a691c47835522fe9 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH 1/6] 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 --- clang/docs/ClangFormatStyleOptions.rst | 112 + clang/include/clang/Format/Format.h| 16 +++ 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, 179 insertions(+), 10 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..042c5f1b5f15b0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -392,6 +392,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -534,6 +550,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -676,6 +708,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -819,6 +867,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1081,6 +1145,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1221,6 +1301,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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 ``AlignConsecu
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -302,47 +302,46 @@ TEST(ConfigParseTest, ParsesConfiguration) { Style.FIELD.Enabled = true; \ CHECK_PARSE( \ #FIELD ": None", FIELD, \ -FormatStyle::AlignConsecutiveStyle( \ -{/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ - /*AcrossComments=*/false, /*AlignCompound=*/false, \ - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ +FormatStyle::AlignConsecutiveStyle({})); \ 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( \ #FIELD ": false", FIELD, \ -FormatStyle::AlignConsecutiveStyle( \ -{/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ - /*AcrossComments=*/false, /*AlignCompound=*/false, \ - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \ +FormatStyle::AlignConsecutiveStyle({})); \ 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); \ CHECK_PARSE_NESTED_BOOL(FIELD, AcrossEmptyLines); \ CHECK_PARSE_NESTED_BOOL(FIELD, AcrossComments); \ CHECK_PARSE_NESTED_BOOL(FIELD, AlignCompound); \ CHECK_PARSE_NESTED_BOOL(FIELD, PadOperators); \ +CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionDeclarations); \ bradh352 wrote: done https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
bradh352 wrote: > You can run `ninja clang-format-check-format` and/or `git clang-format HEAD~` > before `git push`. whoops, sorry about that https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 00cbf31807ca8d8e1c0c86c6a691c47835522fe9 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH 1/3] 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 --- clang/docs/ClangFormatStyleOptions.rst | 112 + clang/include/clang/Format/Format.h| 16 +++ 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, 179 insertions(+), 10 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..042c5f1b5f15b0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -392,6 +392,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -534,6 +550,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -676,6 +708,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -819,6 +867,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1081,6 +1145,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1221,6 +1301,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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 ``AlignConsecu
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -48,46 +48,62 @@ template <> struct MappingTraits { FormatStyle::AlignConsecutiveStyle( {/*Enabled=*/false, /*AcrossEmptyLines=*/false, /*AcrossComments=*/false, /*AlignCompound=*/false, - /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); + /*AlignFunctionDeclarations=*/true, bradh352 wrote: done https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -48,46 +48,62 @@ template <> struct MappingTraits { 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, bradh352 wrote: done https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -305,37 +305,43 @@ 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( \ #FIELD ": false", FIELD, \ FormatStyle::AlignConsecutiveStyle( \ {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionDeclarations=*/true, \ bradh352 wrote: done https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -305,37 +305,43 @@ 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( \ #FIELD ": false", FIELD, \ 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); \ bradh352 wrote: done https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -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", bradh352 wrote: done https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -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); bradh352 wrote: done https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -305,37 +305,43 @@ TEST(ConfigParseTest, ParsesConfiguration) { FormatStyle::AlignConsecutiveStyle( \ {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \ /*AcrossComments=*/false, /*AlignCompound=*/false, \ + /*AlignFunctionDeclarations=*/true, \ bradh352 wrote: done https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 00cbf31807ca8d8e1c0c86c6a691c47835522fe9 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH 1/4] 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 --- clang/docs/ClangFormatStyleOptions.rst | 112 + clang/include/clang/Format/Format.h| 16 +++ 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, 179 insertions(+), 10 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..042c5f1b5f15b0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -392,6 +392,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -534,6 +550,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -676,6 +708,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -819,6 +867,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1081,6 +1145,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1221,6 +1301,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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 ``AlignConsecu
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
bradh352 wrote: > Please update `clang/docs/ReleaseNotes.rst`. done https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 00cbf31807ca8d8e1c0c86c6a691c47835522fe9 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH 1/4] 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 --- clang/docs/ClangFormatStyleOptions.rst | 112 + clang/include/clang/Format/Format.h| 16 +++ 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, 179 insertions(+), 10 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..042c5f1b5f15b0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -392,6 +392,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -534,6 +550,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -676,6 +708,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -819,6 +867,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1081,6 +1145,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1221,6 +1301,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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 ``AlignConsecu
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 00cbf31807ca8d8e1c0c86c6a691c47835522fe9 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH 1/5] 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 --- clang/docs/ClangFormatStyleOptions.rst | 112 + clang/include/clang/Format/Format.h| 16 +++ 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, 179 insertions(+), 10 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..042c5f1b5f15b0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -392,6 +392,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -534,6 +550,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -676,6 +708,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -819,6 +867,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1081,6 +1145,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1221,6 +1301,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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 ``AlignConsecu
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
bradh352 wrote: ping https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -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 bradh352 wrote: ok, so omit the \version is what you're saying ... but @mydeveloperday said it should be versioned. Is the version annotation in the wrong place perhaps? Or maybe its just unsupported to version a sub attribute. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -409,6 +409,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations bradh352 wrote: ah, gotcha https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 00cbf31807ca8d8e1c0c86c6a691c47835522fe9 Mon Sep 17 00:00:00 2001 From: Brad House 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 --- clang/docs/ClangFormatStyleOptions.rst | 112 + clang/include/clang/Format/Format.h| 16 +++ 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, 179 insertions(+), 10 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..042c5f1b5f15b0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -392,6 +392,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -534,6 +550,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -676,6 +708,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -819,6 +867,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1081,6 +1145,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1221,6 +1301,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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 ``AlignConsecu
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -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 bradh352 wrote: done, i see where you said sub options are not allowed to be versioned. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -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 bradh352 wrote: Delete what? All docs related to the new functionality? Or just the \version which was requested by @mydeveloperday ... I don't understand. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
bradh352 wrote: I'm honestly not sure how to fix the formatting in this. I'm not seeing anything wrong with my addition in Format.h, but maybe there's something I'm missing. I never touch ClangFormatStyleOptions.rst directly. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
bradh352 wrote: > By and large this looks ok, (as long as your rst change was generated using > the docs/tools/dump_format_style.py) Yes, it was generated via the script. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
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 Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH] 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 --- 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; + * ``bo
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 89d238800f0287f29f95165e05530d3f5e397245 Mon Sep 17 00:00:00 2001 From: Brad House 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 --- clang/docs/ClangFormatStyleOptions.rst | 105 + clang/include/clang/Format/Format.h| 15 +++ clang/lib/Format/Format.cpp| 31 -- clang/lib/Format/WhitespaceManager.cpp | 2 +- clang/unittests/Format/ConfigParseTest.cpp | 18 ++-- clang/unittests/Format/FormatTest.cpp | 22 - 6 files changed, 177 insertions(+), 16 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..c862d57a19b954 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -409,6 +409,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -551,6 +566,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -693,6 +723,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -836,6 +881,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -1098,6 +1158,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` 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 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. @@ -1238,6 +1313,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); +
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -409,6 +409,21 @@ the configuration (without a prefix: ``Auto``). int *p; int (*f)(); + * ``bool AlignFunctionDeclarations`` Only for ``AlignConsecutiveDeclarations``. Whether function declarations bradh352 wrote: I added version 20, let me know if I should use a different version https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -265,6 +279,7 @@ struct FormatStyle { AcrossComments == R.AcrossComments && AlignCompound == R.AlignCompound && AlignFunctionPointers == R.AlignFunctionPointers && + AlignFunctionDeclarations == R.AlignFunctionDeclarations && bradh352 wrote: sorry, missed that. Done. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
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 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 --- 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; + *
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
https://github.com/bradh352 updated https://github.com/llvm/llvm-project/pull/108241 >From 00cbf31807ca8d8e1c0c86c6a691c47835522fe9 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 11 Sep 2024 10:27:50 -0400 Subject: [PATCH] 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 --- clang/docs/ClangFormatStyleOptions.rst | 112 + clang/include/clang/Format/Format.h| 16 +++ 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, 179 insertions(+), 10 deletions(-) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index a427d7cd40fcdd..042c5f1b5f15b0 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -392,6 +392,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -534,6 +550,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -676,6 +708,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -819,6 +867,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1081,6 +1145,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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. @@ -1221,6 +1301,22 @@ the configuration (without a prefix: ``Auto``). a &= 2; bbb = 2; + * ``bool AlignFunctionDeclarations`` :versionbadge:`clang-format 20` + 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 ``AlignConsecutive
[clang] clang-format: Add AlignFunctionDeclarations attribute to AlignConsecutiveDeclarations (PR #108241)
@@ -1448,6 +1464,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.AlignConsecutiveAssignments.PadOperators = true; LLVMStyle.AlignConsecutiveBitFields = {}; LLVMStyle.AlignConsecutiveDeclarations = {}; + LLVMStyle.AlignConsecutiveDeclarations.AlignFunctionDeclarations = true; bradh352 wrote: right, so the default behavior previously was true. The new option technically just allows it to be set to false. So we're keeping the prior behavior by default. https://github.com/llvm/llvm-project/pull/108241 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits