This revision was automatically updated to reflect the committed changes. Closed by commit rL373821: [clang-format] SpacesInSquareBrackets should affect lambdas with parameters too (authored by paulhoad, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D68473?vs=223245&id=223368#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D68473/new/ https://reviews.llvm.org/D68473 Files: cfe/trunk/docs/ClangFormatStyleOptions.rst cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTest.cpp Index: cfe/trunk/lib/Format/TokenAnnotator.cpp =================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/lib/Format/TokenAnnotator.cpp @@ -2616,8 +2616,8 @@ 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 @@ 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, Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -10515,10 +10515,6 @@ 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 @@ 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) { Index: cfe/trunk/docs/ClangFormatStyleOptions.rst =================================================================== --- cfe/trunk/docs/ClangFormatStyleOptions.rst +++ cfe/trunk/docs/ClangFormatStyleOptions.rst @@ -2301,7 +2301,8 @@ **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++
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp =================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp +++ cfe/trunk/lib/Format/TokenAnnotator.cpp @@ -2616,8 +2616,8 @@ 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 @@ 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, Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -10515,10 +10515,6 @@ 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 @@ 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) { Index: cfe/trunk/docs/ClangFormatStyleOptions.rst =================================================================== --- cfe/trunk/docs/ClangFormatStyleOptions.rst +++ cfe/trunk/docs/ClangFormatStyleOptions.rst @@ -2301,7 +2301,8 @@ **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++
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits