r174508 - Fix a formatting bug caused by comments in expressions.
Daniel Jasper
djasper at google.com
Wed Feb 6 07:23:09 PST 2013
Author: djasper
Date: Wed Feb 6 09:23:09 2013
New Revision: 174508
URL: http://llvm.org/viewvc/llvm-project?rev=174508&view=rev
Log:
Fix a formatting bug caused by comments in expressions.
This fixes llvm.org/PR15162.
Before:
bool aaaaaaaaaaaaa = // comment
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
After:
bool aaaaaaaaaaaaa = // comment
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
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=174508&r1=174507&r2=174508&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Feb 6 09:23:09 2013
@@ -494,6 +494,7 @@ private:
// FIXME: Do we need to do this for assignments nested in other
// expressions?
if (RootToken.isNot(tok::kw_for) && ParenLevel == 0 &&
+ !isTrailingComment(Current) &&
(getPrecedence(Previous) == prec::Assignment ||
Previous.is(tok::kw_return)))
State.Stack.back().AssignmentColumn = State.Column + Spaces;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174508&r1=174507&r2=174508&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb 6 09:23:09 2013
@@ -456,6 +456,10 @@ TEST_F(FormatTest, UnderstandsSingleLine
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
" // Comment inside a statement.\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
+ verifyFormat(
+ "bool aaaaaaaaaaaaa = // comment\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
EXPECT_EQ("void f() { // This does something ..\n"
"}\n"
@@ -1960,6 +1964,17 @@ TEST_F(FormatTest, BlockComments) {
" 2, /* comment 2 */ \n"
" 3, /* comment 3 */\n"
"aaaa, bbbb );", getGoogleStyle()));
+ verifyFormat(
+ "bool aaaaaaaaaaaaa = /* comment: */ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
+ EXPECT_EQ(
+ "bool aaaaaaaaaaaaa = /* trailing comment */\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaa;",
+ format(
+ "bool aaaaaaaaaaaaa = /* trailing comment */\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaa||aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaa;"));
}
TEST_F(FormatTest, FormatStarDependingOnContext) {
More information about the cfe-commits
mailing list