]> granicus.if.org Git - clang/commitdiff
clang-format: Improve binary operator detection in macros.
authorDaniel Jasper <djasper@google.com>
Thu, 7 Nov 2013 19:56:07 +0000 (19:56 +0000)
committerDaniel Jasper <djasper@google.com>
Thu, 7 Nov 2013 19:56:07 +0000 (19:56 +0000)
Before:
  #define M(NAME) assert(!Context.Verifying &&#NAME);

After:
  #define M(NAME) assert(!Context.Verifying && #NAME);

This fixes llvm.org/PR16156.

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

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

index 69e558571f903b8b7b07b701dc22edc7c1d6a8e4..5c70c8f914aa067f62a28f488b751db6852d35cb 100644 (file)
@@ -620,7 +620,7 @@ private:
       Contexts.back().InCtorInitializer = true;
     } else if (Current.is(tok::kw_new)) {
       Contexts.back().CanBeExpression = false;
-    } else if (Current.is(tok::semi)) {
+    } else if (Current.is(tok::semi) || Current.is(tok::exclaim)) {
       // This should be the condition or increment in a for-loop.
       Contexts.back().IsExpression = true;
     }
index 1822a24597eabbae015d34c6da80227cf62a9860..3684e071fdd5449696d0e7946458390c1ec2ed0e 100644 (file)
@@ -4081,6 +4081,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("for (int i = 0; i < a * a; ++i) {\n}");
   verifyGoogleFormat("for (int i = 0; i * 2 < z; i *= 2) {\n}");
 
+  verifyFormat("#define A (!a * b)");
   verifyFormat("#define MACRO     \\\n"
                "  int *i = a * b; \\\n"
                "  void f(a *b);",