diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 108ae7a73621f4781d544c25797534d878583e40..f8e185086d6b18f4fddc3dc631ee1cbad39aaf80 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 190eabab38f98b07d1282db9fe1bffffc146204c..28d9fbe4e2220c8d9ca506115a8a68a898c0f04f 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) {