[PATCH] Fix bug in clang-format while merging short function (PR19461)
Daniel Jasper
djasper at google.com
Mon Apr 28 01:05:51 PDT 2014
================
Comment at: lib/Format/Format.cpp:641
@@ -640,2 +640,3 @@
AnnotatedLine &Line = **I;
- if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::r_brace,
+ if (Line.First->MustBreakBefore ||
+ Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::r_brace,
----------------
Why would it be a problem if we need to wrap before the first of the lines we are going to join. I think the test case passes for the wrong reason. Of course MustBreakBefore is set for the first token of:
"void foo().."
But that is not the point. We are actually interested at whether there is any token other than the first where MustBreakBefore is set (the "{" in the case of the test).
================
Comment at: lib/Format/Format.cpp:664
@@ +663,3 @@
+ // allows merging
+ if (I[1]->First->MustBreakBefore || I[2]->First->MustBreakBefore)
+ return 0;
----------------
How about we put this check into "nextTwoLinesFitInto"?
http://reviews.llvm.org/D3439
More information about the cfe-commits
mailing list