diff options
author | Daniel Jasper <djasper@google.com> | 2013-02-04 07:30:30 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-02-04 07:30:30 +0000 |
commit | f7f13c0ef288841f3695f825302e39dc0fb6f088 (patch) | |
tree | ae31d1d08eb3957ae8bd12552f1a127a71aa765c /clang/lib/Format/Format.cpp | |
parent | 3a9370cbca9145696eafdc7c8b9849371eecfe01 (diff) | |
download | bcm5719-llvm-f7f13c0ef288841f3695f825302e39dc0fb6f088.tar.gz bcm5719-llvm-f7f13c0ef288841f3695f825302e39dc0fb6f088.zip |
Fix an error in formatting of for-loops.
Two minor changes:
* Slight penalty for breaking at "," as opposed to ";".
* Don't apply bin-packing rules to for-loops.
Before:
for (int aaaaaa = aaaaaaaaaa; aaaaaa < bbbbbbbb; ++aaaaaa,
++ccccccccccccccc) {}
After:
for (int aaaaaa = aaaaaaaaaa; aaaaaa < bbbbbbbb;
++aaaaaa, ++ccccccccccccccc) {}
llvm-svn: 174308
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r-- | clang/lib/Format/Format.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 6d227cca627..2f14fc0ce15 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -493,7 +493,8 @@ private: if (Newline && Previous.is(tok::l_brace)) State.Stack.back().BreakBeforeClosingBrace = true; - if (State.Stack.back().AvoidBinPacking && Newline) { + if (State.Stack.back().AvoidBinPacking && Newline && + (Line.First.isNot(tok::kw_for) || ParenLevel != 1)) { // If we are breaking after '(', '{', '<', this is not bin packing unless // AllowAllParametersOfDeclarationOnNextLine is false. if ((Previous.isNot(tok::l_paren) && Previous.isNot(tok::l_brace) && @@ -505,7 +506,8 @@ private: // Any break on this level means that the parent level has been broken // and we need to avoid bin packing there. for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) { - State.Stack[i].BreakAfterComma = true; + if (Line.First.isNot(tok::kw_for) || i != 1) + State.Stack[i].BreakAfterComma = true; } } |