]> granicus.if.org Git - clang/commitdiff
clang-format: Fix incorrect &/* detection.
authorDaniel Jasper <djasper@google.com>
Tue, 25 Mar 2014 10:52:45 +0000 (10:52 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 25 Mar 2014 10:52:45 +0000 (10:52 +0000)
Before:
  STATIC_ASSERT((a &b) == 0);

After:
  STATIC_ASSERT((a & b) == 0);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204709 91177308-0d34-0410-b5e6-96231b3b80d8

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

index efb983e73667672db0e5949789d04cbe259f26b6..369a37b082ee5b2cd2a41b5c3d4bc649cb379399 100644 (file)
@@ -98,8 +98,10 @@ private:
       }
     }
 
-    if (Left->Previous && Left->Previous->isOneOf(tok::kw_static_assert,
-                                                  tok::kw_if, tok::kw_while)) {
+    if (Left->Previous &&
+        (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_if,
+                                 tok::kw_while, tok::l_paren, tok::comma) ||
+         Left->Previous->Type == TT_BinaryOperator)) {
       // static_assert, if and while usually contain expressions.
       Contexts.back().IsExpression = true;
     } else if (Left->Previous && Left->Previous->is(tok::r_square) &&
index 0ae08bcfc07cfcc607b1c557a1ce42009d923bfe..3da478c0923bf245698f168034eea8b82046ea8f 100644 (file)
@@ -4527,6 +4527,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   FormatStyle PointerLeft = getLLVMStyle();
   PointerLeft.PointerBindsToType = true;
   verifyFormat("delete *x;", PointerLeft);
+  verifyFormat("STATIC_ASSERT((a & b) == 0);");
+  verifyFormat("STATIC_ASSERT(0 == (a & b));");
 }
 
 TEST_F(FormatTest, UnderstandsAttributes) {