From fde5c28edd79f5cde6fea3c889cf1790abc73e2c Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 14 Apr 2014 12:50:02 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206165 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 3 +++ unittests/Format/FormatTest.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index b81bf91c78..410a84ecd2 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index f829dccbe9..a98e3d5555 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) { -- 2.40.0