[PATCH] D68415: [clang-format] C++11 braced lists should respect the SpacesInParentheses setting
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 07:26:50 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373751: [clang-format] C++11 braced lists should respect the SpacesInParentheses setting (authored by paulhoad, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D68415?vs=223212&id=223219#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68415/new/
https://reviews.llvm.org/D68415
Files:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -8214,6 +8214,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: cfe/trunk/lib/Format/TokenAnnotator.cpp
===================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2196,7 +2196,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;
@@ -2520,7 +2521,9 @@
return Left.is(tok::hash);
if (Left.isOneOf(tok::hashhash, tok::hash))
return Right.is(tok::hash);
- if (Left.is(tok::l_paren) && Right.is(tok::r_paren))
+ if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
+ (Left.is(tok::l_brace) && Left.BlockKind != BK_Block &&
+ Right.is(tok::r_brace) && Right.BlockKind != BK_Block))
return Style.SpaceInEmptyParentheses;
if (Left.is(tok::l_paren) || Right.is(tok::r_paren))
return (Right.is(TT_CastRParen) ||
@@ -2636,7 +2639,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 ||
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68415.223219.patch
Type: text/x-patch
Size: 3372 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191004/10e36942/attachment.bin>
More information about the llvm-commits
mailing list