diff options
author | Daniel Jasper <djasper@google.com> | 2014-04-28 09:19:28 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-04-28 09:19:28 +0000 |
commit | 9a7de2412c5eb546b125d33802b17c608e6645a3 (patch) | |
tree | 74bd653318060895c4da92ae63618a45bcf12078 | |
parent | c944d2a475e3f13d98ea826784c820082c118764 (diff) | |
download | clang_35a-9a7de2412c5eb546b125d33802b17c608e6645a3.tar.gz |
clang-format: Improve binary operator detection.
Before:
*(int *)(p &~3UL) = 0;
After:
*(int *)(p & ~3UL) = 0;
This fixes llvm.org/PR19464.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207405 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 2 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 54961218a2..843d877718 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -682,7 +682,7 @@ private: for (FormatToken *Previous = Current.Previous; Previous && !Previous->isOneOf(tok::comma, tok::semi); Previous = Previous->Previous) { - if (Previous->is(tok::r_square)) + if (Previous->isOneOf(tok::r_square, tok::r_paren)) Previous = Previous->MatchingParen; if (Previous->Type == TT_BinaryOperator && Previous->isOneOf(tok::star, tok::amp)) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c006c399f3..084d1dd33d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4523,6 +4523,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("a * [self dostuff];"); verifyIndependentOfContext("int x = a * (a + b);"); verifyIndependentOfContext("(a *)(a + b);"); + verifyIndependentOfContext("*(int *)(p & ~3UL) = 0;"); verifyIndependentOfContext("int *pa = (int *)&a;"); verifyIndependentOfContext("return sizeof(int **);"); verifyIndependentOfContext("return sizeof(int ******);"); |