aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-02-26 13:18:08 +0000
committerDaniel Jasper <djasper@google.com>2013-02-26 13:18:08 +0000
commit84a1a63b034744b68a27ec171dca5b1b7cf303f0 (patch)
treeafa57bce3022555cc553c38dd3f5cfa0ae7e7f5d
parent1ef81d57fbcc26080c98e140e7c82db6d2aeba87 (diff)
In range-based for-loops, prefer splitting after ":".
Before: for (const aaaaaaaaaaaaaaaaaaaaa & aaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} After: for (const aaaaaaaaaaaaaaaaaaaaa &aaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176087 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/TokenAnnotator.cpp2
-rw-r--r--unittests/Format/FormatTest.cpp10
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 08290b905a..83e1facb21 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -886,7 +886,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
if (Left.Type == TT_RangeBasedForLoopColon ||
Left.Type == TT_InheritanceColon)
- return 5;
+ return 2;
if (Right.is(tok::arrow) || Right.is(tok::period)) {
if (Line.Type == LT_BuilderTypeCall)
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 53f3773d5c..9e777c66e9 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -318,6 +318,8 @@ TEST_F(FormatTest, RangeBasedForLoops) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}");
verifyFormat("for (auto aaaaaaaaaaaaaaaaaaaaa :\n"
" aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa, aaaaaaaaaaaaa)) {\n}");
+ verifyFormat("for (const aaaaaaaaaaaaaaaaaaaaa &aaaaaaaaa :\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n}");
}
TEST_F(FormatTest, FormatsWhileLoop) {
@@ -601,10 +603,10 @@ TEST_F(FormatTest, CommentsInStaticInitializers) {
" b\n"
"}"));
EXPECT_EQ("S s = { a, b };", format("S s = {\n"
- " a,\n"
- "\n"
- " b\n"
- "};"));
+ " a,\n"
+ "\n"
+ " b\n"
+ "};"));
}
//===----------------------------------------------------------------------===//