clang-format: Understand sequenced casts.

This fixed llvm.org/PR20712.

Before:
  int i = (int)(int) -2;

After:
  int i = (int)(int)-2;

llvm-svn: 216378
This commit is contained in:
Daniel Jasper 2014-08-25 09:36:07 +00:00
parent 7189fb2cf9
commit 4b3ba214d0
2 changed files with 4 additions and 2 deletions

View File

@ -853,8 +853,9 @@ private:
FormatToken *LeftOfParens = nullptr;
if (Tok.MatchingParen)
LeftOfParens = Tok.MatchingParen->getPreviousNonComment();
if (LeftOfParens && LeftOfParens->is(tok::r_paren))
return false;
if (LeftOfParens && LeftOfParens->is(tok::r_paren) &&
LeftOfParens->MatchingParen)
LeftOfParens = LeftOfParens->MatchingParen->Previous;
if (LeftOfParens && LeftOfParens->is(tok::r_square) &&
LeftOfParens->MatchingParen &&
LeftOfParens->MatchingParen->Type == TT_LambdaLSquare)

View File

@ -5057,6 +5057,7 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("my_int a = (my_int *)1;");
verifyFormat("my_int a = (const my_int)-1;");
verifyFormat("my_int a = (const my_int *)-1;");
verifyFormat("my_int a = (my_int)(my_int)-1;");
// FIXME: single value wrapped with paren will be treated as cast.
verifyFormat("void f(int i = (kValue)*kMask) {}");