From: Daniel Jasper Date: Wed, 9 Apr 2014 10:29:11 +0000 (+0000) Subject: clang-format: Allow breaking between trailing annotations in more cases. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f53df4e28343bccc4b53a961589f25a67423eb9;p=clang clang-format: Allow breaking between trailing annotations in more cases. 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 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index cd05a6807e..a0109713a6 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index e3da016663..b9310abbbe 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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"