From ad005369790fd8f53ff01c53625c3d4f5f2631ed Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 13 Jan 2014 14:10:04 +0000 Subject: [PATCH] clang-format: Fix corner case with comment in ctor initializer. Formatting: Constructor() : // Comment forcing unwanted break. aaaa(aaaa) {} Before: Constructor() : // Comment forcing unwanted break. aaaa(aaaa) {} After: Constructor() : // Comment forcing unwanted break. aaaa(aaaa) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199107 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 1 + unittests/Format/FormatTest.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 1c580c420d..1584a05241 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1436,6 +1436,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, const FormatToken &Right) { if (Right.is(tok::comment)) { return Right.Previous->BlockKind != BK_BracedInit && + Right.Previous->Type != TT_CtorInitializerColon && Right.NewlinesBefore > 0; } else if (Right.Previous->isTrailingComment() || (Right.isStringLiteral() && Right.Previous->isStringLiteral())) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 3d73d47d30..08a77764ee 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2896,6 +2896,13 @@ TEST_F(FormatTest, ConstructorInitializers) { " : aaaaa(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaaaa) {}", OnePerLine); + + EXPECT_EQ("Constructor()\n" + " : // Comment forcing unwanted break.\n" + " aaaa(aaaa) {}", + format("Constructor() :\n" + " // Comment forcing unwanted break.\n" + " aaaa(aaaa) {}")); } TEST_F(FormatTest, MemoizationTests) { -- 2.40.0