aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-16 07:02:34 +0000
committerDaniel Jasper <djasper@google.com>2013-01-16 07:02:34 +0000
commit55b08e769f05987942c307fde8eb168df01e504f (patch)
treea97d048468c9595791183857f27a9381685ea861 /lib/Format/Format.cpp
parent05a10ff30bd7c93f689c002963e6ba536e83904a (diff)
Remove errors were if statements were incorrectly put on a single line.
Before: if (a) // This comment confused clang-format f(); After: if (a) // No more confusion f(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172600 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 445a4064b4..9477f5e014 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -1480,6 +1480,11 @@ private:
unsigned Length = 0;
if (!fitsIntoLimit(I->First, Limit, &Length))
return false;
+
+ // We can never merge stuff if there are trailing line comments.
+ if (I->Last->Type == TT_LineComment)
+ return true;
+
if (Limit == Length)
return true; // Couldn't fit a space.
Limit -= Length + 1; // One space.
@@ -1516,6 +1521,8 @@ private:
if (!Style.AllowShortIfStatementsOnASingleLine)
return;
AnnotatedLine &Line = *I;
+ if (Line.Last->isNot(tok::r_paren))
+ return;
if (!fitsIntoLimit((I + 1)->First, Limit))
return;
if ((I + 1)->First.is(tok::kw_if) || (I + 1)->First.Type == TT_LineComment)