clang-format: Fix bad line break with pointers to members.

Before:
  void f() {
    (a->*
     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(aaaa,
                                           bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
  }

After:
  void f() {
    (a->*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(
        aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
  }

Also add missing test case.

llvm-svn: 186583
This commit is contained in:
Daniel Jasper 2013-07-18 14:46:07 +00:00
parent be0474c047
commit 998cabcff4
2 changed files with 10 additions and 1 deletions

View File

@ -1267,7 +1267,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
Left.Previous->is(tok::kw___attribute))
return false;
if (Left.is(tok::l_paren) && (Left.Previous->Type == TT_BinaryOperator ||
Left.Previous->is(tok::r_paren)))
Left.Previous->Type == TT_CastRParen))
return false;
}

View File

@ -3335,6 +3335,10 @@ TEST_F(FormatTest, UnderstandsPointersToMembers) {
" ((*a).*f)();\n"
" a.*x;\n"
"}");
verifyFormat("void f() {\n"
" (a->*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(\n"
" aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);\n"
"}");
FormatStyle Style = getLLVMStyle();
Style.PointerBindsToType = true;
verifyFormat("typedef bool* (Class::*Member)() const;", Style);
@ -3633,6 +3637,11 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("my_int a = (my_int)++ a;");
verifyFormat("my_int a = (my_int) + 2;");
// Don't break after a cast's
verifyFormat("int aaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
" (aaaaaaaaaaaaaaaaaaaaaaaaaa *)(aaaaaaaaaaaaaaaaaaaaaa +\n"
" bbbbbbbbbbbbbbbbbbbbbb);");
// These are not casts.
verifyFormat("void f(int *) {}");
verifyFormat("f(foo)->b;");