]> granicus.if.org Git - clang/commitdiff
clang-format: Fix incorrect &&-detection in macros.
authorDaniel Jasper <djasper@google.com>
Mon, 14 Apr 2014 12:50:02 +0000 (12:50 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 14 Apr 2014 12:50:02 +0000 (12:50 +0000)
Before:
  #define A(a, b) (a &&b)

After:
  #define A(a, b) (a && b)

This fixes llvm.org/PR19343.

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

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

index b81bf91c78b178e51741e0d787f88d0f6ab318ad..410a84ecd2ca9b04a3fc9127f2d49791b4e55e5e 100644 (file)
@@ -110,6 +110,9 @@ private:
          Left->Previous->Type == TT_BinaryOperator)) {
       // static_assert, if and while usually contain expressions.
       Contexts.back().IsExpression = true;
+    } else if (Line.InPPDirective &&
+               (!Left->Previous || Left->Previous->isNot(tok::identifier))) {
+      Contexts.back().IsExpression = true;
     } else if (Left->Previous && Left->Previous->is(tok::r_square) &&
                Left->Previous->MatchingParen &&
                Left->Previous->MatchingParen->Type == TT_LambdaLSquare) {
index f829dccbe982872fcf4e9642c28c26b689960bc9..a98e3d55556f166e82c1b642e35b730497bbebe0 100644 (file)
@@ -4647,6 +4647,7 @@ TEST_F(FormatTest, UnderstandsRvalueReferences) {
                "};");
   verifyGoogleFormat("#define IF(a, b, c) if (a && (b == c))");
   verifyGoogleFormat("#define WHILE(a, b, c) while (a && (b == c))");
+  verifyFormat("#define A(a, b) (a && b)");
 }
 
 TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {