Revamp the formatting of C++11 braced init lists.
The fundamental concept is:
Format as if the braced init list was a function call (with parentheses
replaced by braces). If there is no name/type before the opening brace
(e.g. if the braced list is nested), assume a zero-length identifier
just before the opening brace.
This behavior is gated on a new style flag, which for now replaces the
SpacesInBracedLists style flag. Activate this style flag for Google
style to reflect recent style guide changes.
llvm-svn: 186433
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 747a140..aa2a709 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1637,10 +1637,9 @@
" { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }\n"
"};");
verifyGoogleFormat("SomeType Status::global_reps[3] = {\n"
- " {kGlobalRef, OK_CODE, NULL, NULL, NULL},\n"
- " {kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL},\n"
- " {kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL}\n"
- "};");
+ " {kGlobalRef, OK_CODE, NULL, NULL, NULL},\n"
+ " {kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL},\n"
+ " {kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL}};");
verifyFormat(
"CGRect cg_rect = { { rect.fLeft, rect.fTop },\n"
" { rect.fRight - rect.fLeft, rect.fBottom - rect.fTop"
@@ -1659,11 +1658,11 @@
" 333333333333333333333333333333 } },\n"
" { { 1, 2, 3 } }, { { 1, 2, 3 } } };");
verifyGoogleFormat(
- "SomeArrayOfSomeType a = {{{1, 2, 3}}, {{1, 2, 3}},\n"
- " {{111111111111111111111111111111,\n"
- " 222222222222222222222222222222,\n"
- " 333333333333333333333333333333}},\n"
- " {{1, 2, 3}}, {{1, 2, 3}}};");
+ "SomeArrayOfSomeType a = {\n"
+ " {{1, 2, 3}}, {{1, 2, 3}},\n"
+ " {{111111111111111111111111111111, 222222222222222222222222222222,\n"
+ " 333333333333333333333333333333}},\n"
+ " {{1, 2, 3}}, {{1, 2, 3}}};");
// FIXME: We might at some point want to handle this similar to parameter
// lists, where we have an option to put each on a single line.
@@ -3902,7 +3901,7 @@
" });");
FormatStyle NoSpaces = getLLVMStyle();
- NoSpaces.SpacesInBracedLists = false;
+ NoSpaces.Cpp11BracedListStyle = true;
verifyFormat("vector<int> x{1, 2, 3, 4};", NoSpaces);
verifyFormat("vector<T> x{{}, {}, {}, {}};", NoSpaces);
verifyFormat("f({1, 2});", NoSpaces);
@@ -5307,7 +5306,7 @@
CHECK_PARSE_BOOL(IndentCaseLabels);
CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
CHECK_PARSE_BOOL(PointerBindsToType);
- CHECK_PARSE_BOOL(SpacesInBracedLists);
+ CHECK_PARSE_BOOL(Cpp11BracedListStyle);
CHECK_PARSE_BOOL(UseTab);
CHECK_PARSE_BOOL(IndentFunctionDeclarationAfterType);