**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++
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 &&
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,
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);
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) {