aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-17 13:31:52 +0000
committerDaniel Jasper <djasper@google.com>2013-01-17 13:31:52 +0000
commit60ca75d4d1878f8a45799316f462d4d0114238b4 (patch)
treed8cef0c3db5ef6365d49dfddeb425308b4a99e3d
parentdf96e022e95b8540c51e1bdaed03f66d851c6f93 (diff)
Allow breaking after the trailing const after a function declaration.
Before: void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const GUARDED_BY( aaaaaaaaaaaaa); After: void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const GUARDED_BY(aaaaaaaaaaaaa); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172718 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/Format.cpp7
-rw-r--r--unittests/Format/FormatTest.cpp4
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 108ae7a736..f8e185086d 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -1390,6 +1390,13 @@ private:
// change the "binding" behavior of a comment.
return false;
+ // 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.Parent != NULL &&
+ Left.Parent->is(tok::r_paren))
+ return Right.isNot(tok::l_brace) && Right.isNot(tok::semi) &&
+ Right.isNot(tok::equal);
+
// We only break before r_brace if there was a corresponding break before
// the l_brace, which is tracked by BreakBeforeClosingBrace.
if (Right.is(tok::r_brace))
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 190eabab38..28d9fbe4e2 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -899,6 +899,10 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {
TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) {
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
" GUARDED_BY(aaaaaaaaaaaaa);");
+ verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const\n"
+ " GUARDED_BY(aaaaaaaaaaaaa);");
+ verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const\n"
+ " GUARDED_BY(aaaaaaaaaaaaa) {}");
}
TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {