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``)
|
**SpacesInSquareBrackets** (``bool``)
|
||||||
If ``true``, spaces will be inserted after ``[`` and before ``]``.
|
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++
|
.. code-block:: c++
|
||||||
|
|
||||||
|
|
|
@ -2616,8 +2616,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
||||||
if (Left.is(tok::l_square))
|
if (Left.is(tok::l_square))
|
||||||
return (Left.is(TT_ArrayInitializerLSquare) && Right.isNot(tok::r_square) &&
|
return (Left.is(TT_ArrayInitializerLSquare) && Right.isNot(tok::r_square) &&
|
||||||
SpaceRequiredForArrayInitializerLSquare(Left, Style)) ||
|
SpaceRequiredForArrayInitializerLSquare(Left, Style)) ||
|
||||||
(Left.isOneOf(TT_ArraySubscriptLSquare,
|
(Left.isOneOf(TT_ArraySubscriptLSquare, TT_StructuredBindingLSquare,
|
||||||
TT_StructuredBindingLSquare) &&
|
TT_LambdaLSquare) &&
|
||||||
Style.SpacesInSquareBrackets && Right.isNot(tok::r_square));
|
Style.SpacesInSquareBrackets && Right.isNot(tok::r_square));
|
||||||
if (Right.is(tok::r_square))
|
if (Right.is(tok::r_square))
|
||||||
return Right.MatchingParen &&
|
return Right.MatchingParen &&
|
||||||
|
@ -2626,7 +2626,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
||||||
Style)) ||
|
Style)) ||
|
||||||
(Style.SpacesInSquareBrackets &&
|
(Style.SpacesInSquareBrackets &&
|
||||||
Right.MatchingParen->isOneOf(TT_ArraySubscriptLSquare,
|
Right.MatchingParen->isOneOf(TT_ArraySubscriptLSquare,
|
||||||
TT_StructuredBindingLSquare)) ||
|
TT_StructuredBindingLSquare,
|
||||||
|
TT_LambdaLSquare)) ||
|
||||||
Right.MatchingParen->is(TT_AttributeParen));
|
Right.MatchingParen->is(TT_AttributeParen));
|
||||||
if (Right.is(tok::l_square) &&
|
if (Right.is(tok::l_square) &&
|
||||||
!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
|
!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
|
||||||
|
|
|
@ -10515,10 +10515,6 @@ TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
|
||||||
|
|
||||||
FormatStyle Spaces = getLLVMStyle();
|
FormatStyle Spaces = getLLVMStyle();
|
||||||
Spaces.SpacesInSquareBrackets = true;
|
Spaces.SpacesInSquareBrackets = true;
|
||||||
// Lambdas unchanged.
|
|
||||||
verifyFormat("int c = []() -> int { return 2; }();\n", Spaces);
|
|
||||||
verifyFormat("return [i, args...] {};", Spaces);
|
|
||||||
|
|
||||||
// Not lambdas.
|
// Not lambdas.
|
||||||
verifyFormat("int a[ 5 ];", Spaces);
|
verifyFormat("int a[ 5 ];", Spaces);
|
||||||
verifyFormat("a[ 3 ] += 42;", Spaces);
|
verifyFormat("a[ 3 ] += 42;", Spaces);
|
||||||
|
@ -10529,6 +10525,9 @@ TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
|
||||||
verifyFormat("std::unique_ptr<int[]> foo() {}", Spaces);
|
verifyFormat("std::unique_ptr<int[]> foo() {}", Spaces);
|
||||||
verifyFormat("int i = a[ a ][ a ]->f();", Spaces);
|
verifyFormat("int i = a[ a ][ a ]->f();", Spaces);
|
||||||
verifyFormat("int i = (*b)[ 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) {
|
TEST_F(FormatTest, ConfigurableSpaceBeforeAssignmentOperators) {
|
||||||
|
|
Loading…
Reference in New Issue