clang-format: Fix corner case with comment in ctor initializer.

Formatting:
  Constructor() :
      // Comment forcing unwanted break.
      aaaa(aaaa) {}

Before:
  Constructor()
      :
        // Comment forcing unwanted break.
        aaaa(aaaa) {}

After:
  Constructor()
      : // Comment forcing unwanted break.
        aaaa(aaaa) {}

llvm-svn: 199107
This commit is contained in:
Daniel Jasper 2014-01-13 14:10:04 +00:00
parent 4e033b0e92
commit f6c7c18b8e
2 changed files with 8 additions and 0 deletions

View File

@ -1436,6 +1436,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
const FormatToken &Right) {
if (Right.is(tok::comment)) {
return Right.Previous->BlockKind != BK_BracedInit &&
Right.Previous->Type != TT_CtorInitializerColon &&
Right.NewlinesBefore > 0;
} else if (Right.Previous->isTrailingComment() ||
(Right.isStringLiteral() && Right.Previous->isStringLiteral())) {

View File

@ -2896,6 +2896,13 @@ TEST_F(FormatTest, ConstructorInitializers) {
" : aaaaa(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaa) {}",
OnePerLine);
EXPECT_EQ("Constructor()\n"
" : // Comment forcing unwanted break.\n"
" aaaa(aaaa) {}",
format("Constructor() :\n"
" // Comment forcing unwanted break.\n"
" aaaa(aaaa) {}"));
}
TEST_F(FormatTest, MemoizationTests) {