From 40bc7466a84ffbf5f5e900fb6fe69775809f57ab Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sat, 23 Nov 2013 14:51:47 +0000 Subject: [PATCH] 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); } llvm-svn: 195553 --- clang/lib/Format/TokenAnnotator.cpp | 4 ++-- clang/unittests/Format/FormatTest.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index e841b94474a4..804db6283397 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f279c272745a..1dc5215d187d 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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);",