]> granicus.if.org Git - clang/commitdiff
clang-format: Fix incorrect space in parameters named by comment.
authorDaniel Jasper <djasper@google.com>
Sat, 23 Nov 2013 14:51:47 +0000 (14:51 +0000)
committerDaniel Jasper <djasper@google.com>
Sat, 23 Nov 2013 14:51:47 +0000 (14:51 +0000)
This fixes llvm.org/PR17979.

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

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195553 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index e841b94474a4cdbe0723a2d1f7a392e42de6a66c..804db6283397e42f57bb4be6c7c41fa181b92969 100644 (file)
@@ -1303,6 +1303,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
     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::spaceRequiredBetween(const AnnotatedLine &Line,
     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;
index f279c272745a056f31f222dcbf0c288b979f799b..1dc5215d187d774c31841bc36ecd58896128c183 100644 (file)
@@ -842,6 +842,7 @@ TEST_F(FormatTest, RemovesTrailingWhitespaceOfComments) {
 
 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);",