diff options
| author | Daniel Jasper <djasper@google.com> | 2014-08-25 09:36:07 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-08-25 09:36:07 +0000 |
| commit | 4b3ba214d06d5681894d1f481a7bb1f5cc6a597e (patch) | |
| tree | 62f23ca7f7d30a88029cf5dd64cbb4f4380849ea | |
| parent | 7189fb2cf9c4aed01b0061756615ae5c0041d044 (diff) | |
| download | bcm5719-llvm-4b3ba214d06d5681894d1f481a7bb1f5cc6a597e.tar.gz bcm5719-llvm-4b3ba214d06d5681894d1f481a7bb1f5cc6a597e.zip | |
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
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 1 |
2 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 017a8404ba4..4c6be9f98c1 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 70b02ebc801..14c221bad95 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) {}"); |

