From: Daniel Jasper Date: Tue, 13 Aug 2013 09:09:09 +0000 (+0000) Subject: clang-format: Improve boolean expression formatting in macros. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b644dd68d3d7261ceb8823595290439dc65530b1;p=clang clang-format: Improve boolean expression formatting in macros. Before: #define IF(a, b, c) if (a&&(b == c)) After: #define IF(a, b, c) if (a && (b == c)) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188256 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 4feddfd8d4..94acbd3e4e 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -93,7 +93,8 @@ private: } } - if (Left->Previous && Left->Previous->is(tok::kw_static_assert)) + if (Left->Previous && Left->Previous->isOneOf(tok::kw_static_assert, + tok::kw_if, tok::kw_while)) Contexts.back().IsExpression = true; if (StartsObjCMethodExpr) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 6cea8a332a..79e0186a81 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3712,6 +3712,8 @@ TEST_F(FormatTest, UnderstandsRvalueReferences) { verifyFormat("template class A {\n" " static_assert(B && C, \"Something is wrong\");\n" "};"); + verifyGoogleFormat("#define IF(a, b, c) if (a && (b == c))"); + verifyGoogleFormat("#define WHILE(a, b, c) while (a && (b == c))"); } TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {