]> granicus.if.org Git - clang/commitdiff
clang-format: Fix corner case with comment in ctor initializer.
authorDaniel Jasper <djasper@google.com>
Mon, 13 Jan 2014 14:10:04 +0000 (14:10 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 13 Jan 2014 14:10:04 +0000 (14:10 +0000)
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
unittests/Format/FormatTest.cpp

index 1c580c420dbb8f600c6a6f9d718c415859e1c0d9..1584a05241533a9d4cface268f675d4559d2153a 100644 (file)
@@ -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())) {
index 3d73d47d309aa84e04ef1b891a9a91368cf781ac..08a77764ee87c51cea308f1479821a5229296e9a 100644 (file)
@@ -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) {