if (Right.Type == TT_TrailingAnnotation && Right.Next &&
Right.Next->isNot(tok::l_paren)) {
- // Breaking before a trailing annotation is bad unless it is function-like.
+ // Generally, breaking before a trailing annotation is bad unless it is
+ // function-like. It seems to be especially preferable to keep standard
+ // annotations (i.e. "const", "final" and "override") on the same line.
// Use a slightly higher penalty after ")" so that annotations like
// "const override" are kept together.
- return Left.is(tok::r_paren) ? 100 : 120;
+ bool is_standard_annotation = Right.is(tok::kw_const) ||
+ Right.TokenText == "override" ||
+ Right.TokenText == "final";
+ return (Left.is(tok::r_paren) ? 100 : 120) +
+ (is_standard_annotation ? 50 : 0);
}
// In for-loops, prefer breaking at ',' and ';'.
"virtual void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()\n"
" const override;");
- // Unless this would lead to the first parameter being broken.
- verifyFormat("void someLongFunction(int someLongParameter)\n"
- " const {}",
+ // Even if the first parameter has to be wrapped.
+ verifyFormat("void someLongFunction(\n"
+ " int someLongParameter) const {}",
getLLVMStyleWithColumns(46));
- verifyFormat("void someLongFunction(int someLongParameter)\n"
- " const {}",
+ verifyFormat("void someLongFunction(\n"
+ " int someLongParameter) const {}",
+ Style);
+ verifyFormat("void someLongFunction(\n"
+ " int someLongParameter) override {}",
Style);
+ verifyFormat("void someLongFunction(\n"
+ " int someLongParameter) final {}",
+ Style);
+ verifyFormat("void someLongFunction(\n"
+ " int parameter) const override {}",
+ Style);
+
+ // Unless these are unknown annotations.
verifyFormat("void SomeFunction(aaaaaaaaaa aaaaaaaaaaaaaaa,\n"
" aaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
" LONG_AND_UGLY_ANNOTATION;");