diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-09 09:33:39 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-09 09:33:39 +0000 |
commit | 043835aa876b1edeca0a05def0cc0989faa15892 (patch) | |
tree | 73d24965f53a029a5d8ddd6a155e872ce4411042 | |
parent | 886568dc24eb0a1ccf73bf32d1eafa8fd4008cc6 (diff) |
Allow comments in the middle of statements to be on their own line.
This fixes llvm.org/PR14860.
Before, we messed up the format of:
if (DeclaratorInfo.isFunctionDeclarator() &&
//getDeclSpecContextFromDeclaratorContext(Context) == DSC_top_level &&
Tok.is(tok::semi) && NextToken().is(tok::l_brace)) {
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171961 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Format/Format.cpp | 4 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 16e8c2d6c5..e5e59f4550 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1062,8 +1062,10 @@ private: if (Left.is(tok::equal) && CurrentLineType == LT_VirtualFunctionDecl) return false; + if (Right.is(tok::comment)) + return !Right.Children.empty(); if (Right.is(tok::r_paren) || Right.is(tok::l_brace) || - Right.is(tok::comment) || Right.is(tok::greater)) + Right.is(tok::greater)) return false; return (isBinaryOperator(Left) && Left.isNot(tok::lessless)) || Left.is(tok::comma) || Right.is(tok::lessless) || diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 2e6424dd00..fb21ea7c6f 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -290,6 +290,9 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) { verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n" " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; // Trailing comment"); + verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n" + " // Comment inside a statement.\n" + " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;"); EXPECT_EQ("int i; // single line trailing comment", format("int i;\\\n// single line trailing comment")); |