clang-format: Improve binary operator detection.

Before:
  *(int *)(p &~3UL) = 0;

After:
  *(int *)(p & ~3UL) = 0;

This fixes llvm.org/PR19464.

llvm-svn: 207405
This commit is contained in:
Daniel Jasper 2014-04-28 09:19:28 +00:00
parent f8542956d3
commit 942d971c84
2 changed files with 2 additions and 1 deletions

View File

@ -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)) {

View File

@ -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 ******);");