diff options
| author | Krasimir Georgiev <krasimir@google.com> | 2018-03-06 13:56:28 +0000 |
|---|---|---|
| committer | Krasimir Georgiev <krasimir@google.com> | 2018-03-06 13:56:28 +0000 |
| commit | 446d6ec996c6c397d4576d9608e1dd01a97e0064 (patch) | |
| tree | 9f61b2081f0c64824e4bdac3b82afd041d25708e /clang/lib/Format | |
| parent | b417eeaeb561ff285c7bb12298cd61762ae69e01 (diff) | |
| download | bcm5719-llvm-446d6ec996c6c397d4576d9608e1dd01a97e0064.tar.gz bcm5719-llvm-446d6ec996c6c397d4576d9608e1dd01a97e0064.zip | |
[clang-format] fix handling of consecutive unary operators
Summary:
Code that used to be formatted as `if (! + object) {` is now formatted as `if (!+object) {`
(we have a particular object in our codebase where unary `operator+` is overloaded to return the underlying value, which in this case is a `bool`)
We still preserve the TypeScript behavior where `!` is a trailing non-null operator. (This is already tested by an existing unit test in `FormatTestJS.cpp`)
It doesn't appear like handling of consecutive unary operators are tested in general, so I added another test for completeness
Patch contributed by @kevinl!
Reviewers: krasimir
Reviewed By: krasimir
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43312
llvm-svn: 326792
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 4302ad4f6e9..d083cc7c33d 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1531,10 +1531,8 @@ private: if (!PrevToken) return TT_UnaryOperator; - if (PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator) && - !PrevToken->is(tok::exclaim)) - // There aren't any trailing unary operators except for TypeScript's - // non-null operator (!). Thus, this must be squence of leading operators. + if (PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator)) + // This must be a sequence of leading unary operators. return TT_UnaryOperator; // Use heuristics to recognize unary operators. |

