[clang] Add support for aligning BlockComments in declarations (PR #109497)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 20 16:55:02 PST 2024
https://github.com/JessehMSFT updated https://github.com/llvm/llvm-project/pull/109497
>From 38333491868dfad9c84719d9dd8fd872a2aa7584 Mon Sep 17 00:00:00 2001
From: Jesse Harvey <jesseh at microsoft.com>
Date: Fri, 20 Sep 2024 16:40:35 -0700
Subject: [PATCH 1/4] Add support for aligning BlockComments in declarations
---
clang/include/clang/Format/Format.h | 25 +++++++-
clang/lib/Format/Format.cpp | 22 ++++---
clang/lib/Format/WhitespaceManager.cpp | 11 +++-
clang/unittests/Format/ConfigParseTest.cpp | 73 +++++++++++-----------
clang/unittests/Format/FormatTest.cpp | 49 ++++++++++++++-
5 files changed, 134 insertions(+), 46 deletions(-)
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index d8b62c7652a0f6..f7b6bfffd61314 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -260,12 +260,35 @@ struct FormatStyle {
/// bbb >>= 2;
/// \endcode
bool PadOperators;
+ /// Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ /// are aligned in declarations.
+ /// \code
+ /// true:
+ /// someLongFunction(int /*a*/,
+ /// bool b,
+ /// const std::string& c)
+ ///
+ /// const bool ret = someLongFunction(4 /*a*/,
+ /// true /*b*/,
+ /// str /*c*/);
+ ///
+ /// false:
+ /// someLongFunction(int /*a*/,
+ /// bool b,
+ /// const std::string& c)
+ ///
+ /// const bool ret = someLongFunction(4 /*a*/,
+ /// true /*b*/,
+ /// str /*c*/);
+ /// \endcode
+ bool AlignBlockComments;
bool operator==(const AlignConsecutiveStyle &R) const {
return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
AcrossComments == R.AcrossComments &&
AlignCompound == R.AlignCompound &&
AlignFunctionPointers == R.AlignFunctionPointers &&
- PadOperators == R.PadOperators;
+ PadOperators == R.PadOperators &&
+ AlignBlockComments == R.AlignBlockComments;
}
bool operator!=(const AlignConsecutiveStyle &R) const {
return !(*this == R);
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d2463b892fbb96..ab8eadd0171aa6 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -48,39 +48,46 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true,
+ /*AlignBlockComments=*/false}));
IO.enumCase(Value, "Consecutive",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true,
+ /*AlignBlockComments=*/false}));
IO.enumCase(Value, "AcrossEmptyLines",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/true,
/*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true,
+ /*AlignBlockComments=*/false}));
IO.enumCase(Value, "AcrossComments",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/true, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true,
+ /*AlignBlockComments=*/false}));
IO.enumCase(Value, "AcrossEmptyLinesAndComments",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/true,
/*AcrossComments=*/true, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true,
+ /*AlignBlockComments=*/false}));
// For backward compatibility.
IO.enumCase(Value, "true",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true,
+ /*AlignBlockComments=*/false}));
IO.enumCase(Value, "false",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true,
+ /*AlignBlockComments=*/false}));
}
static void mapping(IO &IO, FormatStyle::AlignConsecutiveStyle &Value) {
@@ -90,6 +97,7 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
IO.mapOptional("AlignCompound", Value.AlignCompound);
IO.mapOptional("AlignFunctionPointers", Value.AlignFunctionPointers);
IO.mapOptional("PadOperators", Value.PadOperators);
+ IO.mapOptional("AlignBlockComments", Value.AlignBlockComments);
}
};
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index fd4a40a86082e2..62d1cfdcff3c27 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1005,6 +1005,12 @@ void WhitespaceManager::alignConsecutiveTableGenDefinitions() {
TT_InheritanceColon);
}
+static bool shouldAlignBlockComment(const FormatToken &Tok) {
+ return Tok.is(TT_BlockComment) && Tok.Previous &&
+ !Tok.Previous->isOneOf(TT_StartOfName, TT_BlockComment) && Tok.Next &&
+ Tok.Next->isOneOf(tok::comma, tok::r_paren, TT_BlockComment);
+}
+
void WhitespaceManager::alignConsecutiveDeclarations() {
if (!Style.AlignConsecutiveDeclarations.Enabled)
return;
@@ -1022,7 +1028,10 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
if (C.Tok->is(TT_FunctionDeclarationName))
return true;
if (C.Tok->isNot(TT_StartOfName))
- return false;
+ if (!Style.AlignConsecutiveDeclarations.AlignBlockComments ||
+ !shouldAlignBlockComment(*C.Tok)) {
+ return false;
+ }
if (C.Tok->Previous &&
C.Tok->Previous->is(TT_StatementAttributeLikeMacro))
return false;
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index b8bdfaaa74e10e..745d187dddce50 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -300,49 +300,50 @@ TEST(ConfigParseTest, ParsesConfiguration) {
#define CHECK_ALIGN_CONSECUTIVE(FIELD) \
do { \
Style.FIELD.Enabled = true; \
- CHECK_PARSE( \
- #FIELD ": None", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
- CHECK_PARSE( \
- #FIELD ": Consecutive", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
- CHECK_PARSE( \
- #FIELD ": AcrossEmptyLines", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
- CHECK_PARSE( \
- #FIELD ": AcrossEmptyLinesAndComments", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
- /*AcrossComments=*/true, /*AlignCompound=*/false, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE(#FIELD ": None", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
+ CHECK_PARSE(#FIELD ": Consecutive", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
+ CHECK_PARSE(#FIELD ": AcrossEmptyLines", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
+ CHECK_PARSE(#FIELD ": AcrossEmptyLinesAndComments", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
+ /*AcrossComments=*/true, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
/* 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})); \
- CHECK_PARSE( \
- #FIELD ": true", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE(#FIELD ": false", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/false, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
+ CHECK_PARSE(#FIELD ": true", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
\
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, AlignBlockComments); \
} while (false)
CHECK_ALIGN_CONSECUTIVE(AlignConsecutiveAssignments);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 53aa93a7a4fb01..2f03149609878a 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20018,6 +20018,52 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
BracedAlign);
}
+TEST_F(FormatTest, AlignConsecutiveDeclarationsBlockComments) {
+ FormatStyle Style = getLLVMStyleWithColumns(80);
+ Style.AlignConsecutiveDeclarations.Enabled = true;
+ Style.AlignConsecutiveDeclarations.AlignBlockComments = true;
+ Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.BinPackArguments = false;
+
+ verifyFormat(
+ "bool SomeLongMethodName(int longParameterNameA,\n"
+ " bool /*longParameterNameB*/,\n"
+ " const std::string &longParameterNameC);",
+ "bool SomeLongMethodName(int longParameterNameA,\n"
+ " bool /*longParameterNameB*/,\n"
+ " const std::string &longParameterNameC);",
+ Style);
+
+ verifyFormat(
+ "const bool ret = SomeLongMethodName(4 /*parameterNameA*/,\n"
+ " true /*longParameterNameB*/,\n"
+ " str /*longestParameterNameC*/);",
+ "const bool ret = SomeLongMethodName(4 /*parameterNameA*/,\n"
+ " true /*longParameterNameB*/,\n"
+ " str /*longestParameterNameC*/);",
+ Style);
+
+ verifyNoChange("/*,\n"
+ "This is a multi-line block comment.\n"
+ "That is not part of a function declaration.\n"
+ "*/\n"
+ "static void SomeLongMethodName()",
+ Style);
+
+ verifyNoChange("static const unsigned int c_cMediaEntranceEntries = 31;\n"
+ "static const unsigned int c_cMediaEmphasisEntries = 4 /* "
+ "media effects */ + 12;\n"
+ "static const unsigned int c_cMediaExitEntries = 32;",
+ Style);
+
+ verifyNoChange(
+ "static bool SomeLongMethodName(int longParameterNameA,\n"
+ " bool longParameterNameB "
+ "/*=false*/,\n"
+ " std::string &longParameterNameC);",
+ Style);
+}
+
TEST_F(FormatTest, AlignConsecutiveShortCaseStatements) {
FormatStyle Alignment = getLLVMStyle();
Alignment.AllowShortCaseLabelsOnASingleLine = true;
@@ -20259,7 +20305,8 @@ TEST_F(FormatTest, AlignWithLineBreaks) {
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
/*AcrossComments=*/false, /*AlignCompound=*/false,
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true}));
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true,
+ /*AlignBlockComments=*/false}));
EXPECT_EQ(Style.AlignConsecutiveDeclarations,
FormatStyle::AlignConsecutiveStyle({}));
verifyFormat("void foo() {\n"
>From d48cad3334535e0e14ef6c6795cd703fb1e18896 Mon Sep 17 00:00:00 2001
From: Jesse Harvey <jesseh at microsoft.com>
Date: Mon, 23 Sep 2024 09:58:57 -0700
Subject: [PATCH 2/4] Regenerate ClangFormatStyleOptions.rst via
dump_format_style.py
---
clang/docs/ClangFormatStyleOptions.rst | 161 +++++++++++++++++++++++++
1 file changed, 161 insertions(+)
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index a427d7cd40fcdd..d0940f2d26c85b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -429,6 +429,29 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
.. _AlignConsecutiveBitFields:
@@ -571,6 +594,29 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
.. _AlignConsecutiveDeclarations:
@@ -713,6 +759,29 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
.. _AlignConsecutiveMacros:
@@ -856,6 +925,29 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
.. _AlignConsecutiveShortCaseStatements:
@@ -1118,6 +1210,29 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
.. _AlignConsecutiveTableGenCondOperatorColons:
@@ -1258,6 +1373,29 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
.. _AlignConsecutiveTableGenDefinitionColons:
@@ -1398,6 +1536,29 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c)
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
.. _AlignEscapedNewlines:
>From cd798d23111579ec908bcaf882e82960ffd123ff Mon Sep 17 00:00:00 2001
From: Jesse Harvey <jesseh at microsoft.com>
Date: Tue, 8 Oct 2024 11:15:35 -0700
Subject: [PATCH 3/4] Ran clang-format on missed file
---
clang/unittests/Format/ConfigParseTest.cpp | 60 ++++++++++------------
1 file changed, 28 insertions(+), 32 deletions(-)
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 30aedfe5dcb358..d8ebada50a07a1 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -302,41 +302,37 @@ TEST(ConfigParseTest, ParsesConfiguration) {
Style.FIELD.Enabled = true; \
CHECK_PARSE(#FIELD ": None", FIELD, \
FormatStyle::AlignConsecutiveStyle({})); \
- CHECK_PARSE( \
- #FIELD ": Consecutive", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionDeclarations=*/true, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
- /*AlignBlockComments=*/false})); \
- CHECK_PARSE( \
- #FIELD ": AcrossEmptyLines", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionDeclarations=*/true, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
- /*AlignBlockComments=*/false})); \
- CHECK_PARSE( \
- #FIELD ": AcrossEmptyLinesAndComments", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
- /*AcrossComments=*/true, /*AlignCompound=*/false, \
- /*AlignFunctionDeclarations=*/true, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
- /*AlignBlockComments=*/false})); \
+ CHECK_PARSE(#FIELD ": Consecutive", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionDeclarations=*/true, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
+ CHECK_PARSE(#FIELD ": AcrossEmptyLines", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionDeclarations=*/true, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
+ CHECK_PARSE(#FIELD ": AcrossEmptyLinesAndComments", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
+ /*AcrossComments=*/true, /*AlignCompound=*/false, \
+ /*AlignFunctionDeclarations=*/true, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
/* For backwards compability, false / true should still parse */ \
CHECK_PARSE(#FIELD ": false", FIELD, \
FormatStyle::AlignConsecutiveStyle({})); \
- CHECK_PARSE( \
- #FIELD ": true", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionDeclarations=*/true, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
- /*AlignBlockComments=*/false})); \
+ CHECK_PARSE(#FIELD ": true", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignCompound=*/false, \
+ /*AlignFunctionDeclarations=*/true, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
+ /*AlignBlockComments=*/false})); \
\
CHECK_PARSE_NESTED_BOOL(FIELD, Enabled); \
CHECK_PARSE_NESTED_BOOL(FIELD, AcrossEmptyLines); \
>From 5a43a9ef36bc5f5c13c80a94da22ea35be35cb63 Mon Sep 17 00:00:00 2001
From: Jesse Harvey <jesseh at microsoft.com>
Date: Wed, 20 Nov 2024 16:54:47 -0800
Subject: [PATCH 4/4] Addressed feedback: Reordered options, updated release
notes, re-ran clang-format
---
clang/docs/ClangFormatStyleOptions.rst | 322 ++++++++++-----------
clang/docs/ReleaseNotes.rst | 1 +
clang/include/clang/Format/Format.h | 48 +--
clang/lib/Format/Format.cpp | 37 ++-
clang/unittests/Format/ConfigParseTest.cpp | 72 ++---
clang/unittests/Format/FormatTest.cpp | 14 +-
6 files changed, 250 insertions(+), 244 deletions(-)
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 59bcacd9228602..2991f8697a90aa 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -380,6 +380,29 @@ the configuration (without a prefix: ``Auto``).
/* A comment. */
double e = 4;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
@@ -445,29 +468,6 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
- * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
- are aligned in declarations.
-
- .. code-block:: c++
-
- true:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
- false:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
.. _AlignConsecutiveBitFields:
@@ -561,6 +561,29 @@ the configuration (without a prefix: ``Auto``).
/* A comment. */
double e = 4;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
@@ -626,29 +649,6 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
- * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
- are aligned in declarations.
-
- .. code-block:: c++
-
- true:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
- false:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
.. _AlignConsecutiveDeclarations:
@@ -742,6 +742,29 @@ the configuration (without a prefix: ``Auto``).
/* A comment. */
double e = 4;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
@@ -807,29 +830,6 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
- * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
- are aligned in declarations.
-
- .. code-block:: c++
-
- true:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
- false:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
.. _AlignConsecutiveMacros:
@@ -924,6 +924,29 @@ the configuration (without a prefix: ``Auto``).
/* A comment. */
double e = 4;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
@@ -989,29 +1012,6 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
- * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
- are aligned in declarations.
-
- .. code-block:: c++
-
- true:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
- false:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
.. _AlignConsecutiveShortCaseStatements:
@@ -1225,6 +1225,29 @@ the configuration (without a prefix: ``Auto``).
/* A comment. */
double e = 4;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
@@ -1290,29 +1313,6 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
- * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
- are aligned in declarations.
-
- .. code-block:: c++
-
- true:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
- false:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
.. _AlignConsecutiveTableGenCondOperatorColons:
@@ -1404,6 +1404,29 @@ the configuration (without a prefix: ``Auto``).
/* A comment. */
double e = 4;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
@@ -1469,29 +1492,6 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
- * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
- are aligned in declarations.
-
- .. code-block:: c++
-
- true:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
- false:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
.. _AlignConsecutiveTableGenDefinitionColons:
@@ -1583,6 +1583,29 @@ the configuration (without a prefix: ``Auto``).
/* A comment. */
double e = 4;
+ * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ are aligned in declarations.
+
+ .. code-block:: c++
+
+ true:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
+ false:
+ bool someLongFunction(int /*a*/,
+ bool b,
+ const std::string& c);
+
+ const bool ret = someLongFunction(4 /*a*/,
+ true /*b*/,
+ str /*c*/);
+
* ``bool AlignCompound`` Only for ``AlignConsecutiveAssignments``. Whether compound assignments
like ``+=`` are aligned along with ``=``.
@@ -1648,29 +1671,6 @@ the configuration (without a prefix: ``Auto``).
a = 2;
bbb >>= 2;
- * ``bool AlignBlockComments`` Only for ``AlignConsecutiveDeclarations``. Whether block comments
- are aligned in declarations.
-
- .. code-block:: c++
-
- true:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
- false:
- someLongFunction(int /*a*/,
- bool b,
- const std::string& c)
-
- const bool ret = someLongFunction(4 /*a*/,
- true /*b*/,
- str /*c*/);
-
.. _AlignEscapedNewlines:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 999c88455b64a5..e0e6ac33d85ca9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -901,6 +901,7 @@ clang-format
``Never``, and ``true`` to ``Always``.
- Adds ``RemoveEmptyLinesInUnwrappedLines`` option.
- Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style.
+- Adds ``AlignBlockComments`` option.
libclang
--------
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index a2726e199ddef0..1827375aceb1bf 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -214,6 +214,28 @@ struct FormatStyle {
/// double e = 4;
/// \endcode
bool AcrossComments;
+ /// Only for ``AlignConsecutiveDeclarations``. Whether block comments
+ /// are aligned in declarations.
+ /// \code
+ /// true:
+ /// bool someLongFunction(int /*a*/,
+ /// bool b,
+ /// const std::string& c);
+ ///
+ /// const bool ret = someLongFunction(4 /*a*/,
+ /// true /*b*/,
+ /// str /*c*/);
+ ///
+ /// false:
+ /// bool someLongFunction(int /*a*/,
+ /// bool b,
+ /// const std::string& c);
+ ///
+ /// const bool ret = someLongFunction(4 /*a*/,
+ /// true /*b*/,
+ /// str /*c*/);
+ /// \endcode
+ bool AlignBlockComments;
/// Only for ``AlignConsecutiveAssignments``. Whether compound assignments
/// like ``+=`` are aligned along with ``=``.
/// \code
@@ -275,36 +297,14 @@ struct FormatStyle {
/// bbb >>= 2;
/// \endcode
bool PadOperators;
- /// Only for ``AlignConsecutiveDeclarations``. Whether block comments
- /// are aligned in declarations.
- /// \code
- /// true:
- /// someLongFunction(int /*a*/,
- /// bool b,
- /// const std::string& c)
- ///
- /// const bool ret = someLongFunction(4 /*a*/,
- /// true /*b*/,
- /// str /*c*/);
- ///
- /// false:
- /// someLongFunction(int /*a*/,
- /// bool b,
- /// const std::string& c)
- ///
- /// const bool ret = someLongFunction(4 /*a*/,
- /// true /*b*/,
- /// str /*c*/);
- /// \endcode
- bool AlignBlockComments;
bool operator==(const AlignConsecutiveStyle &R) const {
return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
AcrossComments == R.AcrossComments &&
+ AlignBlockComments == R.AlignBlockComments &&
AlignCompound == R.AlignCompound &&
AlignFunctionDeclarations == R.AlignFunctionDeclarations &&
AlignFunctionPointers == R.AlignFunctionPointers &&
- PadOperators == R.PadOperators &&
- AlignBlockComments == R.AlignBlockComments;
+ PadOperators == R.PadOperators;
}
bool operator!=(const AlignConsecutiveStyle &R) const {
return !(*this == R);
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e5268e15b3fcb9..dca001f50e8b0e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -48,45 +48,50 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
IO.enumCase(Value, "Consecutive",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
- /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AcrossComments=*/false,
+ /*AlignBlockComments=*/false,
+ /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
/*AlignFunctionPointers=*/false,
- /*PadOperators=*/true,
- /*AlignBlockComments=*/false}));
+ /*PadOperators=*/true}));
IO.enumCase(Value, "AcrossEmptyLines",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/true,
- /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AcrossComments=*/false,
+ /*AlignBlockComments=*/false,
+ /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
/*AlignFunctionPointers=*/false,
- /*PadOperators=*/true,
- /*AlignBlockComments=*/false}));
+ /*PadOperators=*/true}));
IO.enumCase(Value, "AcrossComments",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
- /*AcrossComments=*/true, /*AlignCompound=*/false,
+ /*AcrossComments=*/true,
+ /*AlignBlockComments=*/false,
+ /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
/*AlignFunctionPointers=*/false,
- /*PadOperators=*/true,
- /*AlignBlockComments=*/false}));
+ /*PadOperators=*/true}));
IO.enumCase(Value, "AcrossEmptyLinesAndComments",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/true,
- /*AcrossComments=*/true, /*AlignCompound=*/false,
+ /*AcrossComments=*/true,
+ /*AlignBlockComments=*/false,
+ /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
/*AlignFunctionPointers=*/false,
- /*PadOperators=*/true,
- /*AlignBlockComments=*/false}));
+ /*PadOperators=*/true}));
// For backward compatibility.
IO.enumCase(Value, "true",
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/true, /*AcrossEmptyLines=*/false,
- /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AcrossComments=*/false,
+ /*AlignBlockComments=*/false,
+ /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
/*AlignFunctionPointers=*/false,
- /*PadOperators=*/true,
- /*AlignBlockComments=*/false}));
+ /*PadOperators=*/true}));
IO.enumCase(Value, "false", FormatStyle::AlignConsecutiveStyle({}));
}
@@ -94,12 +99,12 @@ template <> struct MappingTraits<FormatStyle::AlignConsecutiveStyle> {
IO.mapOptional("Enabled", Value.Enabled);
IO.mapOptional("AcrossEmptyLines", Value.AcrossEmptyLines);
IO.mapOptional("AcrossComments", Value.AcrossComments);
+ IO.mapOptional("AlignBlockComments", Value.AlignBlockComments);
IO.mapOptional("AlignCompound", Value.AlignCompound);
IO.mapOptional("AlignFunctionDeclarations",
Value.AlignFunctionDeclarations);
IO.mapOptional("AlignFunctionPointers", Value.AlignFunctionPointers);
IO.mapOptional("PadOperators", Value.PadOperators);
- IO.mapOptional("AlignBlockComments", Value.AlignBlockComments);
}
};
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 22a82c9ea0df29..f84b78863efc9b 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -303,53 +303,53 @@ TEST(ConfigParseTest, ParsesConfiguration) {
Style.FIELD.Enabled = true; \
CHECK_PARSE(#FIELD ": None", FIELD, \
FormatStyle::AlignConsecutiveStyle({})); \
- CHECK_PARSE(#FIELD ": Consecutive", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionDeclarations=*/true, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
- /*AlignBlockComments=*/false})); \
- CHECK_PARSE(#FIELD ": AcrossEmptyLines", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionDeclarations=*/true, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
- /*AlignBlockComments=*/false})); \
- CHECK_PARSE(#FIELD ": AcrossComments", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/true, /*AlignCompound=*/false, \
- /*AlignFunctionDeclarations=*/true, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
- /*AlignBlockComments=*/false})); \
- CHECK_PARSE(#FIELD ": AcrossEmptyLinesAndComments", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
- /*AcrossComments=*/true, /*AlignCompound=*/false, \
- /*AlignFunctionDeclarations=*/true, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
- /*AlignBlockComments=*/false})); \
+ CHECK_PARSE( \
+ #FIELD ": Consecutive", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/false, /*AlignBlockComments=*/false, \
+ /*AlignCompound=*/false, /*AlignFunctionDeclarations=*/true, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": AcrossEmptyLines", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
+ /*AcrossComments=*/false, /*AlignBlockComments=*/false, \
+ /*AlignCompound=*/false, /*AlignFunctionDeclarations=*/true, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": AcrossComments", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
+ /*AcrossComments=*/true, /*AlignBlockComments=*/false, \
+ /*AlignCompound=*/false, /*AlignFunctionDeclarations=*/true, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
+ CHECK_PARSE( \
+ #FIELD ": AcrossEmptyLinesAndComments", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AcrossEmptyLines=*/true, \
+ /*AcrossComments=*/true, /*AlignBlockComments=*/false, \
+ /*AlignCompound=*/false, /*AlignFunctionDeclarations=*/true, \
+ /*AlignFunctionPointers=*/false, /*PadOperators=*/true})); \
/* For backwards compability, false / true should still parse */ \
CHECK_PARSE(#FIELD ": false", FIELD, \
FormatStyle::AlignConsecutiveStyle({})); \
- CHECK_PARSE(#FIELD ": true", FIELD, \
- FormatStyle::AlignConsecutiveStyle( \
- {/*Enabled=*/true, /*AcrossEmptyLines=*/false, \
- /*AcrossComments=*/false, /*AlignCompound=*/false, \
- /*AlignFunctionDeclarations=*/true, \
- /*AlignFunctionPointers=*/false, /*PadOperators=*/true, \
- /*AlignBlockComments=*/false})); \
+ CHECK_PARSE( \
+ #FIELD ": true", FIELD, \
+ FormatStyle::AlignConsecutiveStyle( \
+ {/*Enabled=*/true, /*AlignBlockComments=*/false, \
+ /*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, AlignBlockComments); \
CHECK_PARSE_NESTED_BOOL(FIELD, AlignCompound); \
CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionDeclarations); \
CHECK_PARSE_NESTED_BOOL(FIELD, AlignFunctionPointers); \
CHECK_PARSE_NESTED_BOOL(FIELD, PadOperators); \
- CHECK_PARSE_NESTED_BOOL(FIELD, AlignBlockComments); \
} while (false)
CHECK_ALIGN_CONSECUTIVE(AlignConsecutiveAssignments);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index bcaf87a93ac2d8..6ace1a6e534cb5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20031,7 +20031,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
}
TEST_F(FormatTest, AlignConsecutiveDeclarationsBlockComments) {
- FormatStyle Style = getLLVMStyleWithColumns(80);
+ auto Style = getLLVMStyle();
Style.AlignConsecutiveDeclarations.Enabled = true;
Style.AlignConsecutiveDeclarations.AlignBlockComments = true;
Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
@@ -20316,19 +20316,19 @@ TEST_F(FormatTest, AlignWithLineBreaks) {
EXPECT_EQ(Style.AlignConsecutiveAssignments,
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
- /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AcrossComments=*/false, /*AlignBlockComments=*/false,
+ /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/false,
/*AlignFunctionPointers=*/false,
- /*PadOperators=*/true,
- /*AlignBlockComments=*/false}));
+ /*PadOperators=*/true}));
EXPECT_EQ(Style.AlignConsecutiveDeclarations,
FormatStyle::AlignConsecutiveStyle(
{/*Enabled=*/false, /*AcrossEmptyLines=*/false,
- /*AcrossComments=*/false, /*AlignCompound=*/false,
+ /*AcrossComments=*/false, /*AlignBlockComments=*/false,
+ /*AlignCompound=*/false,
/*AlignFunctionDeclarations=*/true,
/*AlignFunctionPointers=*/false,
- /*PadOperators=*/false,
- /*AlignBlockComments=*/false}));
+ /*PadOperators=*/false}));
verifyFormat("void foo() {\n"
" int myVar = 5;\n"
" double x = 3.14;\n"
More information about the cfe-commits
mailing list