Skip to content
Snippets Groups Projects
Commit 60ca75d4 authored by Daniel Jasper's avatar Daniel Jasper
Browse files

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
parent df96e022
No related branches found
No related tags found
No related merge requests found
...@@ -1390,6 +1390,13 @@ private: ...@@ -1390,6 +1390,13 @@ private:
// change the "binding" behavior of a comment. // change the "binding" behavior of a comment.
return false; 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 // We only break before r_brace if there was a corresponding break before
// the l_brace, which is tracked by BreakBeforeClosingBrace. // the l_brace, which is tracked by BreakBeforeClosingBrace.
if (Right.is(tok::r_brace)) if (Right.is(tok::r_brace))
......
...@@ -899,6 +899,10 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { ...@@ -899,6 +899,10 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {
TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) { TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) {
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
" GUARDED_BY(aaaaaaaaaaaaa);"); " 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) { TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment