Reduce penalty for splitting after "{" in static initializers.
This fixes llvm.org/PR15379.
Before:
const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = { 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // comment
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // comment
0x00, 0x00, 0x00, 0x00 // comment
};
After:
const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment
0x00, 0x00, 0x00, 0x00 // comment
};
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176262 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index e127f4a..b9e3512 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -880,8 +880,6 @@
else
return 100;
}
- if (Left.is(tok::l_brace) && Right.isNot(tok::l_brace))
- return 50;
if (Left.is(tok::equal) && Right.is(tok::l_brace))
return 150;
if (Left.is(tok::coloncolon))
@@ -917,7 +915,7 @@
return 20;
if (Left.is(tok::l_paren) || Left.is(tok::l_square) ||
- Left.Type == TT_TemplateOpener)
+ Left.is(tok::l_brace) || Left.Type == TT_TemplateOpener)
return 20;
if (Right.is(tok::lessless)) {
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 392548d..baeb014 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -612,6 +612,11 @@
"\n"
" b\n"
"};"));
+ verifyFormat("const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {\n"
+ " 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
+ " 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
+ " 0x00, 0x00, 0x00, 0x00 // comment\n"
+ "};");
}
//===----------------------------------------------------------------------===//