summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorFrancois Ferrand <thetypz@gmail.com>2018-05-16 08:03:52 +0000
committerFrancois Ferrand <thetypz@gmail.com>2018-05-16 08:03:52 +0000
commitf92f806aa45165578d4e08349ad4b3669ec71979 (patch)
tree42d790e021b3d60b669b09a3eb86432b50e38850 /clang/unittests/Format/FormatTest.cpp
parent67f9154964456ce523d8bdac892e8cf2428c3f3d (diff)
downloadbcm5719-llvm-f92f806aa45165578d4e08349ad4b3669ec71979.tar.gz
bcm5719-llvm-f92f806aa45165578d4e08349ad4b3669ec71979.zip
clang-format: tweak formatting of variable initialization blocks
Summary: This patch changes the behavior of PenaltyBreakBeforeFirstCallParameter so that is does not apply after a brace, when Cpp11BracedListStyle is false. This way, variable initialization is wrapped more like an initializer than like a function call, which is more consistent with user expectations for this braced list style. With PenaltyBreakBeforeFirstCallParameter=200, this gives the following code: (with Cpp11BracedListStyle=false) Before : const std::unordered_map<std::string, int> Something::MyHashTable = { { "aaaaaaaaaaaaaaaaaaaaa", 0 }, { "bbbbbbbbbbbbbbbbbbbbb", 1 }, { "ccccccccccccccccccccc", 2 } }; After : const std::unordered_set<std::string> Something::MyUnorderedSet = { { "aaaaaaaaaaaaaaaaaaaaa", 0 }, { "bbbbbbbbbbbbbbbbbbbbb", 1 }, { "ccccccccccccccccccccc", 2 } }; Reviewers: krasimir, djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D43290 llvm-svn: 332434
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 5c44b79ca9a..2b61a96a219 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6708,6 +6708,15 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
"};");
verifyFormat("#define A {a, a},");
+ // Avoid breaking between equal sign and opening brace
+ FormatStyle AvoidBreakingFirstArgument = getLLVMStyle();
+ AvoidBreakingFirstArgument.PenaltyBreakBeforeFirstCallParameter = 200;
+ verifyFormat("const std::unordered_map<std::string, int> MyHashTable =\n"
+ " {{\"aaaaaaaaaaaaaaaaaaaaa\", 0},\n"
+ " {\"bbbbbbbbbbbbbbbbbbbbb\", 1},\n"
+ " {\"ccccccccccccccccccccc\", 2}};",
+ AvoidBreakingFirstArgument);
+
// Binpacking only if there is no trailing comma
verifyFormat("const Aaaaaa aaaaa = {aaaaaaaaaa, bbbbbbbbbb,\n"
" cccccccccc, dddddddddd};",
@@ -6864,6 +6873,21 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
verifyFormat("vector<int> foo = { ::SomeGlobalFunction() };", ExtraSpaces);
verifyFormat("const struct A a = { .a = 1, .b = 2 };", ExtraSpaces);
verifyFormat("const struct A a = { [0] = 1, [1] = 2 };", ExtraSpaces);
+
+ // Avoid breaking between initializer/equal sign and opening brace
+ ExtraSpaces.PenaltyBreakBeforeFirstCallParameter = 200;
+ verifyFormat("const std::unordered_map<std::string, int> MyHashTable = {\n"
+ " { \"aaaaaaaaaaaaaaaaaaaaa\", 0 },\n"
+ " { \"bbbbbbbbbbbbbbbbbbbbb\", 1 },\n"
+ " { \"ccccccccccccccccccccc\", 2 }\n"
+ "};",
+ ExtraSpaces);
+ verifyFormat("const std::unordered_map<std::string, int> MyHashTable{\n"
+ " { \"aaaaaaaaaaaaaaaaaaaaa\", 0 },\n"
+ " { \"bbbbbbbbbbbbbbbbbbbbb\", 1 },\n"
+ " { \"ccccccccccccccccccccc\", 2 }\n"
+ "};",
+ ExtraSpaces);
}
TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
OpenPOWER on IntegriCloud