From 40db06af64570f0c4e627d5c0cd6a3e388ca3ccb 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); llvm-svn: 186077 --- clang/lib/Format/TokenAnnotator.cpp | 2 ++ clang/unittests/Format/FormatTest.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f5b6fbd..1e4de6e 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index b87393a..8435c94 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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.7.4