r206165 - clang-format: Fix incorrect &&-detection in macros.

Daniel Jasper djasper at google.com
Mon Apr 14 05:50:02 PDT 2014


Author: djasper
Date: Mon Apr 14 07:50:02 2014
New Revision: 206165

URL: http://llvm.org/viewvc/llvm-project?rev=206165&view=rev
Log:
clang-format: Fix incorrect &&-detection in macros.

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

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

This fixes llvm.org/PR19343.

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=206165&r1=206164&r2=206165&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Apr 14 07:50:02 2014
@@ -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) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=206165&r1=206164&r2=206165&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 14 07:50:02 2014
@@ -4647,6 +4647,7 @@ TEST_F(FormatTest, UnderstandsRvalueRefe
                "};");
   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) {





More information about the cfe-commits mailing list