]> granicus.if.org Git - clang/commitdiff
clang-format: Improve binary operator detection.
authorDaniel Jasper <djasper@google.com>
Mon, 28 Apr 2014 09:19:28 +0000 (09:19 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 28 Apr 2014 09:19:28 +0000 (09:19 +0000)
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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index 54961218a2da9e7897c4cd40187fd753c1418bf0..843d8777188cdc798cc67307b3caeeb315d909bb 100644 (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)) {
index c006c399f3867d28705b34e43eb68afc5c7ea33b..084d1dd33d8e8cf82c4626bf092883eefc37e054 100644 (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 ******);");