diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index b81bf91c78b1..410a84ecd2ca 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f829dccbe982..a98e3d55556f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) {