[PATCH] D129443: [clang-format] Add option for aligning requires clause body
Danil Sidoruk via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 10 05:42:31 PDT 2022
eoanermine created this revision.
eoanermine added projects: clang, clang-format.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.
- Add an option whether requires clause body should be aligned with `requires` keyword
Fixes https://github.com/llvm/llvm-project/issues/56283
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129443
Files:
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20033,6 +20033,7 @@
TEST_F(FormatTest, ParsesConfigurationBools) {
FormatStyle Style = {};
Style.Language = FormatStyle::LK_Cpp;
+ CHECK_PARSE_BOOL(AlignRequiresClauseBody);
CHECK_PARSE_BOOL(AlignTrailingComments);
CHECK_PARSE_BOOL(AllowAllArgumentsOnNextLine);
CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -646,6 +646,7 @@
IO.mapOptional("AlignConsecutiveMacros", Style.AlignConsecutiveMacros);
IO.mapOptional("AlignEscapedNewlines", Style.AlignEscapedNewlines);
IO.mapOptional("AlignOperands", Style.AlignOperands);
+ IO.mapOptional("AlignRequiresClauseBody", Style.AlignRequiresClauseBody);
IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments);
IO.mapOptional("AllowAllArgumentsOnNextLine",
Style.AllowAllArgumentsOnNextLine);
@@ -1181,6 +1182,7 @@
LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
LLVMStyle.AlignOperands = FormatStyle::OAS_Align;
+ LLVMStyle.AlignRequiresClauseBody = true;
LLVMStyle.AlignTrailingComments = true;
LLVMStyle.AlignConsecutiveAssignments = {};
LLVMStyle.AlignConsecutiveAssignments.Enabled = false;
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -1398,7 +1398,7 @@
CurrentState.NestedBlockIndent = State.Column + Current.ColumnWidth + 1;
if (Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))
CurrentState.LastSpace = State.Column;
- if (Current.is(TT_RequiresExpression))
+ if (Current.is(TT_RequiresExpression) && Style.AlignRequiresClauseBody)
CurrentState.NestedBlockIndent = State.Column;
// Insert scopes created by fake parenthesis.
Index: clang/include/clang/Format/Format.h
===================================================================
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -369,6 +369,17 @@
/// \version 3.5
OperandAlignmentStyle AlignOperands;
+ /// If ``true``, aligns requires clause bodies with `requires` keyword.
+ /// \code
+ /// true: false:
+ /// template <typename T> template <typename T>
+ /// concept C = requires(T t) { vs. concept C = requires(T t) {
+ /// ... ...
+ /// } }
+ /// \endcode
+ /// \version 15
+ bool AlignRequiresClauseBody;
+
/// If ``true``, aligns trailing comments.
/// \code
/// true: false:
@@ -3856,6 +3867,7 @@
AlignConsecutiveMacros == R.AlignConsecutiveMacros &&
AlignEscapedNewlines == R.AlignEscapedNewlines &&
AlignOperands == R.AlignOperands &&
+ AlignRequiresClauseBody == R.AlignRequiresClauseBody &&
AlignTrailingComments == R.AlignTrailingComments &&
AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine &&
AllowAllParametersOfDeclarationOnNextLine ==
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129443.443495.patch
Type: text/x-patch
Size: 3540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220710/4f80534d/attachment.bin>
More information about the cfe-commits
mailing list