]> granicus.if.org Git - clang/commitdiff
clang-format: Allow breaking between trailing annotations in more cases.
authorDaniel Jasper <djasper@google.com>
Wed, 9 Apr 2014 10:29:11 +0000 (10:29 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 9 Apr 2014 10:29:11 +0000 (10:29 +0000)
Before:
  void aaaaaaaaaaaaaa(aaaaaaaa aaa) override AAAAAAAAAAAAAAAAAAAAAAAA(
      aaaaaaaaaaaaaaa);

After:
  void aaaaaaaaaaaaaa(aaaaaaaa aaa) override
      AAAAAAAAAAAAAAAAAAAAAAAA(aaaaaaaaaaaaaaa);

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

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

index cd05a6807e61b6dc551630d1fd227a30f13ce8fb..a0109713a6ae6ca14cfac3e2468d7bc12086f0cb 100644 (file)
@@ -1623,11 +1623,11 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
   if (Right.is(tok::r_brace))
     return Right.MatchingParen && Right.MatchingParen->BlockKind == BK_Block;
 
-  // Allow breaking after a trailing 'const', e.g. after a method declaration,
-  // unless it is follow by ';', '{' or '='.
-  if (Left.is(tok::kw_const) && Left.Previous != NULL &&
-      Left.Previous->is(tok::r_paren))
-    return !Right.isOneOf(tok::l_brace, tok::semi, tok::equal);
+  // Allow breaking after a trailing annotation, e.g. after a method
+  // declaration.
+  if (Left.Type == TT_TrailingAnnotation)
+    return !Right.isOneOf(tok::l_brace, tok::semi, tok::equal, tok::l_paren,
+                          tok::less, tok::coloncolon);
 
   if (Right.is(tok::kw___attribute))
     return true;
index e3da016663c7899c186c9be17b64563a97c39e6d..b9310abbbea4f35d451d89e9255c0d9714633726 100644 (file)
@@ -3295,6 +3295,8 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
                "    LOCKS_EXCLUDED(aaaaaaaaaaaaa);");
   verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const\n"
                "    LOCKS_EXCLUDED(aaaaaaaaaaaaa) {}");
+  verifyGoogleFormat("void aaaaaaaaaaaaaa(aaaaaaaa aaa) override\n"
+                     "    AAAAAAAAAAAAAAAAAAAAAAAA(aaaaaaaaaaaaaaa);");
 
   verifyFormat(
       "void aaaaaaaaaaaaaaaaaa()\n"