summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorDinesh Dwivedi <dinesh.d@samsung.com>2014-05-05 11:36:35 +0000
committerDinesh Dwivedi <dinesh.d@samsung.com>2014-05-05 11:36:35 +0000
commitafe6fb6f0524b3b2a9eea9faa520c9b1727edfd8 (patch)
tree42f12e5af4424ef42c78935caa4624a672b508d5 /clang/lib/Format
parent264f963114e475666ee1841502f3a1fdd74e81e9 (diff)
downloadbcm5719-llvm-afe6fb6f0524b3b2a9eea9faa520c9b1727edfd8.tar.gz
bcm5719-llvm-afe6fb6f0524b3b2a9eea9faa520c9b1727edfd8.zip
Fix bug in clang-format while merging short function
Before: #ifdef _DEBUG int foo( int i = 0 ) #else int foo( int i = 5 ) #endif { return i; } After: #ifdef _DEBUG int foo( int i = 0 ) #else int foo( int i = 5 ) #endif { return i; } llvm-svn: 207958
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/Format.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 3544cff4ddb..21334ad9c80 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -532,7 +532,7 @@ public:
? 0
: Limit - TheLine->Last->TotalLength;
- if (I + 1 == E || I[1]->Type == LT_Invalid)
+ if (I + 1 == E || I[1]->Type == LT_Invalid || I[1]->First->MustBreakBefore)
return 0;
// FIXME: TheLine->Level != 0 might or might not be the right check to do.
@@ -664,7 +664,7 @@ private:
// Second, check that the next line does not contain any braces - if it
// does, readability declines when putting it into a single line.
- if (I[1]->Last->Type == TT_LineComment || Tok->MustBreakBefore)
+ if (I[1]->Last->Type == TT_LineComment)
return 0;
do {
if (Tok->isOneOf(tok::l_brace, tok::r_brace))
@@ -674,8 +674,7 @@ private:
// Last, check that the third line contains a single closing brace.
Tok = I[2]->First;
- if (Tok->getNextNonComment() != NULL || Tok->isNot(tok::r_brace) ||
- Tok->MustBreakBefore)
+ if (Tok->getNextNonComment() != NULL || Tok->isNot(tok::r_brace))
return 0;
return 2;
@@ -698,6 +697,8 @@ private:
bool nextTwoLinesFitInto(SmallVectorImpl<AnnotatedLine *>::const_iterator I,
unsigned Limit) {
+ if (I[1]->First->MustBreakBefore || I[2]->First->MustBreakBefore)
+ return false;
return 1 + I[1]->Last->TotalLength + 1 + I[2]->Last->TotalLength <= Limit;
}
OpenPOWER on IntegriCloud