return 150;
}
+ // Breaking before a trailing 'const' is bad.
+ if (Left.is(tok::r_paren) && Right.is(tok::kw_const))
+ return 150;
+
// In for-loops, prefer breaking at ',' and ';'.
if (Line.First.is(tok::kw_for) && Left.is(tok::equal))
return 4;
// change the "binding" behavior of a comment.
return false;
+ // We only break before r_brace if there was a corresponding break before
+ // the l_brace, which is tracked by BreakBeforeClosingBrace.
+ if (Right.isOneOf(tok::r_brace, tok::r_paren, tok::greater))
+ 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 &&
if (Right.is(tok::kw___attribute))
return true;
- // We only break before r_brace if there was a corresponding break before
- // the l_brace, which is tracked by BreakBeforeClosingBrace.
- if (Right.isOneOf(tok::r_brace, tok::r_paren, tok::greater))
- return false;
if (Left.is(tok::identifier) && Right.is(tok::string_literal))
return true;
return (Left.isBinaryOperator() && Left.isNot(tok::lessless)) ||
}
TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
- verifyFormat("void someLongFunction(int someLongParameter)\n"
- " const;",
- getLLVMStyleWithColumns(45));
+ verifyFormat("void someLongFunction(\n"
+ " int someLongParameter) const {}",
+ getLLVMStyleWithColumns(46));
+ FormatStyle Style = getGoogleStyle();
+ Style.ColumnLimit = 47;
+ verifyFormat("void\n"
+ "someLongFunction(int someLongParameter) const {\n}",
+ getLLVMStyleWithColumns(47));
+ verifyFormat("void someLongFunction(\n"
+ " int someLongParameter) const {}",
+ Style);
+ verifyFormat("LoooooongReturnType\n"
+ "someLoooooooongFunction() const {}",
+ getLLVMStyleWithColumns(47));
+ verifyFormat("LoooooongReturnType someLoooooooongFunction()\n"
+ " const {}",
+ Style);
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
" LOCKS_EXCLUDED(aaaaaaaaaaaaa);");