[cfe-commits] r172600 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Tue Jan 15 23:02:35 PST 2013
Author: djasper
Date: Wed Jan 16 01:02:34 2013
New Revision: 172600
URL: http://llvm.org/viewvc/llvm-project?rev=172600&view=rev
Log:
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();
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172600&r1=172599&r2=172600&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 16 01:02:34 2013
@@ -1480,6 +1480,11 @@
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 @@
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)
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172600&r1=172599&r2=172600&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 16 01:02:34 2013
@@ -145,7 +145,17 @@
verifyFormat("if (a) return;", getGoogleStyleWithColumns(14));
verifyFormat("if (a)\n return;", getGoogleStyleWithColumns(13));
verifyFormat("if (aaaaaaaaa)\n"
- " return;", getGoogleStyleWithColumns(14));
+ " return;", getGoogleStyleWithColumns(14));
+ verifyGoogleFormat("if (a) // Can't merge this\n"
+ " f();\n");
+ verifyGoogleFormat("if (a) /* still don't merge */\n"
+ " f();");
+ verifyGoogleFormat("if (a) { // Never merge this\n"
+ " f();\n"
+ "}");
+ verifyGoogleFormat("if (a) { /* Never merge this */\n"
+ " f();\n"
+ "}");
}
TEST_F(FormatTest, ParseIfElse) {
More information about the cfe-commits
mailing list