return 150;
}
- // Breaking before a trailing 'const' is bad.
- if (Left.is(tok::r_paren) && Right.is(tok::kw_const))
+ // Breaking before a trailing 'const' or not-function-like annotation is bad.
+ if (Left.is(tok::r_paren) &&
+ (Right.is(tok::kw_const) || (Right.is(tok::identifier) && Right.Next &&
+ Right.Next->isNot(tok::l_paren))))
return 150;
// In for-loops, prefer breaking at ',' and ';'.
}
TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
+ // Avoid breaking before trailing 'const'.
verifyFormat("void someLongFunction(\n"
" int someLongParameter) const {}",
getLLVMStyleWithColumns(46));
" const {}",
Style);
+ // Avoid breaking before other trailing annotations, if they are not
+ // function-like.
+ verifyFormat("void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE;");
+
+ // Breaking before function-like trailing annotations is fine to keep them
+ // close to their arguments.
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
" LOCKS_EXCLUDED(aaaaaaaaaaaaa);");
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const\n"