From 65d2c3829494d254039683c73f95843c29c661b4 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 6 Jun 2013 16:08:57 +0000 Subject: [PATCH] Fix incorrect line breaking before trailing block comments. Before, clang-format would happily move a trailing block comment to a new line, which normally changes the perceived binding of that comment. E.g., it would move: void f() { /* comment */ ... } to: void f() { /* comment */ ... } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183420 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTest.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 71a1a28c85..8b1382ed7c 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1198,7 +1198,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, Left.Previous->is(tok::kw___attribute)) return false; - if (Right.Type == TT_LineComment) + if (Right.isTrailingComment()) // We rely on MustBreakBefore being set correctly here as we should not // change the "binding" behavior of a comment. return false; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 19f702f06a..f5204b4576 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -767,6 +767,15 @@ TEST_F(FormatTest, UnderstandsMultiLineComments) { " /* Leading comment for bb... */ bbbbbbbbbbbbbbbbbbbbbbbbb);", format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , \n" "/* Leading comment for bb... */ bbbbbbbbbbbbbbbbbbbbbbbbb);")); + EXPECT_EQ( + "void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" + " aaaaaaaaaaaaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaa) { /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaa */\n" + "}", + format("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" + " aaaaaaaaaaaaaaaaaa ,\n" + " aaaaaaaaaaaaaaaaaa) { /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaa */\n" + "}")); FormatStyle NoBinPacking = getLLVMStyle(); NoBinPacking.BinPackParameters = false; -- 2.40.0