From: Daniel Jasper Date: Wed, 9 Jan 2013 09:33:39 +0000 (+0000) Subject: Allow comments in the middle of statements to be on their own line. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=043835aa876b1edeca0a05def0cc0989faa15892;p=clang 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 --- 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"));