]> granicus.if.org Git - clang/commitdiff
clang-format: Improve boolean expression formatting in macros.
authorDaniel Jasper <djasper@google.com>
Tue, 13 Aug 2013 09:09:09 +0000 (09:09 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 13 Aug 2013 09:09:09 +0000 (09:09 +0000)
Before:
  #define IF(a, b, c) if (a&&(b == c))

After:
  #define IF(a, b, c) if (a && (b == c))

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

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

index 4feddfd8d4d408c3ae5c09120041b1bda6dda1ea..94acbd3e4e738e5bbc3fcd144c287d88ff626df1 100644 (file)
@@ -93,7 +93,8 @@ private:
       }
     }
 
-    if (Left->Previous && Left->Previous->is(tok::kw_static_assert))
+    if (Left->Previous && Left->Previous->isOneOf(tok::kw_static_assert,
+                                                  tok::kw_if, tok::kw_while))
       Contexts.back().IsExpression = true;
 
     if (StartsObjCMethodExpr) {
index 6cea8a332adde0978810e582287aa724a22be68e..79e0186a81d0626aa02eedddfd117aa994be72bd 100644 (file)
@@ -3712,6 +3712,8 @@ TEST_F(FormatTest, UnderstandsRvalueReferences) {
   verifyFormat("template <bool B, bool C> class A {\n"
                "  static_assert(B && C, \"Something is wrong\");\n"
                "};");
+  verifyGoogleFormat("#define IF(a, b, c) if (a && (b == c))");
+  verifyGoogleFormat("#define WHILE(a, b, c) while (a && (b == c))");
 }
 
 TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {