clang-format: Fix trailing const (etc.) with Allman brace style.

Before:
  void someLongFunction(int someLongParameter)
      const
  {
  }

After:
  void someLongFunction(
      int someLongParameter) const
  {
  }

This fixes llvm.org/PR19912.

llvm-svn: 210010
This commit is contained in:
Daniel Jasper 2014-06-02 09:52:08 +00:00
parent 2fcc427741
commit e3f907fded
2 changed files with 9 additions and 2 deletions

View File

@ -1329,8 +1329,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
return 150;
}
if (Right.Type == TT_TrailingAnnotation && Right.Next &&
Right.Next->isNot(tok::l_paren)) {
if (Right.Type == TT_TrailingAnnotation &&
(!Right.Next || Right.Next->isNot(tok::l_paren))) {
// 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.

View File

@ -3469,6 +3469,13 @@ TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
" int parameter) const override {}",
Style);
Style.BreakBeforeBraces = FormatStyle::BS_Allman;
verifyFormat("void someLongFunction(\n"
" int someLongParameter) const\n"
"{\n"
"}",
Style);
// Unless these are unknown annotations.
verifyFormat("void SomeFunction(aaaaaaaaaa aaaaaaaaaaaaaaa,\n"
" aaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"