From c18cff311118fc6a30929468fc82b2b35cbd7fbf Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 11 Jul 2013 12:34:23 +0000 Subject: [PATCH] Keep trailing annotations close to their argument. Before: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY( aaaaaaaaaaaa); After: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186077 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 ++ unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index f5b6fbde7c..1e4de6eb94 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1020,6 +1020,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Right.Type == TT_StartOfName || Right.is(tok::kw_operator)) { if (Line.First->is(tok::kw_for) && Right.PartOfMultiVariableDeclStmt) return 3; + if (Left.Type == TT_StartOfName) + return 20; else if (Line.MightBeFunctionDecl && Right.BindingStrength == 1) // FIXME: Clean up hack of using BindingStrength to find top-level names. return Style.PenaltyReturnTypeOnItsOwnLine; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b87393a9da..8435c94a0f 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2511,6 +2511,10 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) { "bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" " GUARDED_BY(aaaaaaaaaaaa);", getGoogleStyle()); + verifyFormat( + "bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + " GUARDED_BY(aaaaaaaaaaaa);", + getGoogleStyle()); } TEST_F(FormatTest, BreaksDesireably) { -- 2.40.0