r195553 - clang-format: Fix incorrect space in parameters named by comment.

Daniel Jasper djasper at google.com
Sat Nov 23 06:51:47 PST 2013


Author: djasper
Date: Sat Nov 23 08:51:47 2013
New Revision: 195553

URL: http://llvm.org/viewvc/llvm-project?rev=195553&view=rev
Log:
clang-format: Fix incorrect space in parameters named by comment.

This fixes llvm.org/PR17979.

Before:
  void f() { g(/*aaa=*/x, /*bbb=*/ !y); }

After:
  void f() { g(/*aaa=*/x, /*bbb=*/!y); }

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=195553&r1=195552&r2=195553&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Nov 23 08:51:47 2013
@@ -1303,6 +1303,8 @@ bool TokenAnnotator::spaceRequiredBetwee
     return !Left.Children.empty(); // No spaces in "{}".
   if (Left.is(tok::l_brace) || Right.is(tok::r_brace))
     return !Style.Cpp11BracedListStyle;
+  if (Left.Type == TT_BlockComment && Left.TokenText.endswith("=*/"))
+    return false;
   if (Right.Type == TT_UnaryOperator)
     return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) &&
            (Left.isNot(tok::colon) || Left.Type != TT_ObjCMethodExpr);
@@ -1312,8 +1314,6 @@ bool TokenAnnotator::spaceRequiredBetwee
     return false;
   if (Left.is(tok::period) || Right.is(tok::period))
     return false;
-  if (Left.Type == TT_BlockComment && Left.TokenText.endswith("=*/"))
-    return false;
   if (Right.is(tok::hash) && Left.is(tok::identifier) && Left.TokenText == "L")
     return false;
   return true;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=195553&r1=195552&r2=195553&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Nov 23 08:51:47 2013
@@ -842,6 +842,7 @@ TEST_F(FormatTest, RemovesTrailingWhites
 
 TEST_F(FormatTest, UnderstandsBlockComments) {
   verifyFormat("f(/*noSpaceAfterParameterNamingComment=*/true);");
+  verifyFormat("void f() { g(/*aaa=*/x, /*bbb=*/!y); }");
   EXPECT_EQ(
       "f(aaaaaaaaaaaaaaaaaaaaaaaaa, /* Trailing comment for aa... */\n"
       "  bbbbbbbbbbbbbbbbbbbbbbbbb);",





More information about the cfe-commits mailing list