[clang-format] fix handling of consecutive unary operators
authorKrasimir Georgiev <krasimir@google.com>
Tue, 6 Mar 2018 13:56:28 +0000 (13:56 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Tue, 6 Mar 2018 13:56:28 +0000 (13:56 +0000)
commit446d6ec996c6c397d4576d9608e1dd01a97e0064
tree9f61b2081f0c64824e4bdac3b82afd041d25708e
parentb417eeaeb561ff285c7bb12298cd61762ae69e01
[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
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestJS.cpp