forked from OSchip/llvm-project
[clang-format] SpacesInSquareBrackets should affect lambdas with parameters too
Summary: This patch makes the `SpacesInSquareBrackets` setting also apply to C++ lambdas with parameters. Looking through the revision history, it appears support for only array brackets was added, and lambda brackets were ignored. Therefore, I am inclined to think it was simply an omission, rather than a deliberate choice. See https://bugs.llvm.org/show_bug.cgi?id=17887 and https://reviews.llvm.org/D4944. Reviewers: MyDeveloperDay, reuk, owenpan Reviewed By: MyDeveloperDay Subscribers: cfe-commits Patch by: mitchell-stellar Tags: #clang-format, #clang Differential Revision: https://reviews.llvm.org/D68473 llvm-svn: 373821
This commit is contained in:
parent
b1f0183e57
commit
375a84bb75
|
@ -2301,7 +2301,8 @@ the configuration (without a prefix: ``Auto``).
|
|||
|
||||
**SpacesInSquareBrackets** (``bool``)
|
||||
If ``true``, spaces will be inserted after ``[`` and before ``]``.
|
||||
Lambdas or unspecified size array declarations will not be affected.
|
||||
Lambdas without arguments or unspecified size array declarations will not be
|
||||
affected.
|
||||
|
||||
.. code-block:: c++
|
||||
|
||||
|
|
|
@ -2616,8 +2616,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
if (Left.is(tok::l_square))
|
||||
return (Left.is(TT_ArrayInitializerLSquare) && Right.isNot(tok::r_square) &&
|
||||
SpaceRequiredForArrayInitializerLSquare(Left, Style)) ||
|
||||
(Left.isOneOf(TT_ArraySubscriptLSquare,
|
||||
TT_StructuredBindingLSquare) &&
|
||||
(Left.isOneOf(TT_ArraySubscriptLSquare, TT_StructuredBindingLSquare,
|
||||
TT_LambdaLSquare) &&
|
||||
Style.SpacesInSquareBrackets && Right.isNot(tok::r_square));
|
||||
if (Right.is(tok::r_square))
|
||||
return Right.MatchingParen &&
|
||||
|
@ -2626,7 +2626,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
Style)) ||
|
||||
(Style.SpacesInSquareBrackets &&
|
||||
Right.MatchingParen->isOneOf(TT_ArraySubscriptLSquare,
|
||||
TT_StructuredBindingLSquare)) ||
|
||||
TT_StructuredBindingLSquare,
|
||||
TT_LambdaLSquare)) ||
|
||||
Right.MatchingParen->is(TT_AttributeParen));
|
||||
if (Right.is(tok::l_square) &&
|
||||
!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
|
||||
|
|
|
@ -10515,10 +10515,6 @@ TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
|
|||
|
||||
FormatStyle Spaces = getLLVMStyle();
|
||||
Spaces.SpacesInSquareBrackets = true;
|
||||
// Lambdas unchanged.
|
||||
verifyFormat("int c = []() -> int { return 2; }();\n", Spaces);
|
||||
verifyFormat("return [i, args...] {};", Spaces);
|
||||
|
||||
// Not lambdas.
|
||||
verifyFormat("int a[ 5 ];", Spaces);
|
||||
verifyFormat("a[ 3 ] += 42;", Spaces);
|
||||
|
@ -10529,6 +10525,9 @@ TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
|
|||
verifyFormat("std::unique_ptr<int[]> foo() {}", Spaces);
|
||||
verifyFormat("int i = a[ a ][ a ]->f();", Spaces);
|
||||
verifyFormat("int i = (*b)[ a ]->f();", Spaces);
|
||||
// Lambdas.
|
||||
verifyFormat("int c = []() -> int { return 2; }();\n", Spaces);
|
||||
verifyFormat("return [ i, args... ] {};", Spaces);
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, ConfigurableSpaceBeforeAssignmentOperators) {
|
||||
|
|
Loading…
Reference in New Issue