mitchell-stellar updated this revision to Diff 223077. mitchell-stellar added a comment.
Added additional unit tests to verify that the `SpaceInEmptyParentheses` setting is also correctly adhered to. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D68415/new/ https://reviews.llvm.org/D68415 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -8210,6 +8210,34 @@ SpaceBeforeBrace.SpaceBeforeCpp11BracedList = true; verifyFormat("vector<int> x {1, 2, 3, 4};", SpaceBeforeBrace); verifyFormat("f({}, {{}, {}}, MyMap[{k, v}]);", SpaceBeforeBrace); + + FormatStyle SpaceBetweenBraces = getLLVMStyle(); + SpaceBetweenBraces.SpacesInAngles = true; + SpaceBetweenBraces.SpacesInParentheses = true; + SpaceBetweenBraces.SpacesInSquareBrackets = true; + verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces); + verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces); + verifyFormat("vector< int > x{ // comment 1\n" + " 1, 2, 3, 4 };", + SpaceBetweenBraces); + SpaceBetweenBraces.ColumnLimit = 20; + EXPECT_EQ("vector< int > x{\n" + " 1, 2, 3, 4 };", + format("vector<int>x{1,2,3,4};", SpaceBetweenBraces)); + SpaceBetweenBraces.ColumnLimit = 24; + EXPECT_EQ("vector< int > x{ 1, 2,\n" + " 3, 4 };", + format("vector<int>x{1,2,3,4};", SpaceBetweenBraces)); + EXPECT_EQ("vector< int > x{\n" + " 1,\n" + " 2,\n" + " 3,\n" + " 4,\n" + "};", + format("vector<int>x{1,2,3,4,};", SpaceBetweenBraces)); + verifyFormat("vector< int > x{};", SpaceBetweenBraces); + SpaceBetweenBraces.SpaceInEmptyParentheses = true; + verifyFormat("vector< int > x{ };", SpaceBetweenBraces); } TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2188,7 +2188,8 @@ if (Current->is(TT_LineComment)) { if (Current->Previous->BlockKind == BK_BracedInit && Current->Previous->opensScope()) - Current->SpacesRequiredBefore = Style.Cpp11BracedListStyle ? 0 : 1; + Current->SpacesRequiredBefore = + (Style.Cpp11BracedListStyle && !Style.SpacesInParentheses) ? 0 : 1; else Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments; @@ -2628,7 +2629,7 @@ if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) || (Right.is(tok::r_brace) && Right.MatchingParen && Right.MatchingParen->BlockKind != BK_Block)) - return !Style.Cpp11BracedListStyle; + return Style.Cpp11BracedListStyle ? Style.SpacesInParentheses : true; if (Left.is(TT_BlockComment)) // No whitespace in x(/*foo=*/1), except for JavaScript. return Style.Language == FormatStyle::LK_JavaScript ||
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -8210,6 +8210,34 @@ SpaceBeforeBrace.SpaceBeforeCpp11BracedList = true; verifyFormat("vector<int> x {1, 2, 3, 4};", SpaceBeforeBrace); verifyFormat("f({}, {{}, {}}, MyMap[{k, v}]);", SpaceBeforeBrace); + + FormatStyle SpaceBetweenBraces = getLLVMStyle(); + SpaceBetweenBraces.SpacesInAngles = true; + SpaceBetweenBraces.SpacesInParentheses = true; + SpaceBetweenBraces.SpacesInSquareBrackets = true; + verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces); + verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces); + verifyFormat("vector< int > x{ // comment 1\n" + " 1, 2, 3, 4 };", + SpaceBetweenBraces); + SpaceBetweenBraces.ColumnLimit = 20; + EXPECT_EQ("vector< int > x{\n" + " 1, 2, 3, 4 };", + format("vector<int>x{1,2,3,4};", SpaceBetweenBraces)); + SpaceBetweenBraces.ColumnLimit = 24; + EXPECT_EQ("vector< int > x{ 1, 2,\n" + " 3, 4 };", + format("vector<int>x{1,2,3,4};", SpaceBetweenBraces)); + EXPECT_EQ("vector< int > x{\n" + " 1,\n" + " 2,\n" + " 3,\n" + " 4,\n" + "};", + format("vector<int>x{1,2,3,4,};", SpaceBetweenBraces)); + verifyFormat("vector< int > x{};", SpaceBetweenBraces); + SpaceBetweenBraces.SpaceInEmptyParentheses = true; + verifyFormat("vector< int > x{ };", SpaceBetweenBraces); } TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2188,7 +2188,8 @@ if (Current->is(TT_LineComment)) { if (Current->Previous->BlockKind == BK_BracedInit && Current->Previous->opensScope()) - Current->SpacesRequiredBefore = Style.Cpp11BracedListStyle ? 0 : 1; + Current->SpacesRequiredBefore = + (Style.Cpp11BracedListStyle && !Style.SpacesInParentheses) ? 0 : 1; else Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments; @@ -2628,7 +2629,7 @@ if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) || (Right.is(tok::r_brace) && Right.MatchingParen && Right.MatchingParen->BlockKind != BK_Block)) - return !Style.Cpp11BracedListStyle; + return Style.Cpp11BracedListStyle ? Style.SpacesInParentheses : true; if (Left.is(TT_BlockComment)) // No whitespace in x(/*foo=*/1), except for JavaScript. return Style.Language == FormatStyle::LK_JavaScript ||
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits