From: Daniel Jasper Date: Tue, 25 Mar 2014 10:52:45 +0000 (+0000) Subject: clang-format: Fix incorrect &/* detection. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a5e37f5429afa82cf72843affcb0b6f579be3977;p=clang clang-format: Fix incorrect &/* detection. Before: STATIC_ASSERT((a &b) == 0); After: STATIC_ASSERT((a & b) == 0); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204709 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index efb983e736..369a37b082 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -98,8 +98,10 @@ private: } } - if (Left->Previous && Left->Previous->isOneOf(tok::kw_static_assert, - tok::kw_if, tok::kw_while)) { + if (Left->Previous && + (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_if, + tok::kw_while, tok::l_paren, tok::comma) || + Left->Previous->Type == TT_BinaryOperator)) { // static_assert, if and while usually contain expressions. Contexts.back().IsExpression = true; } else if (Left->Previous && Left->Previous->is(tok::r_square) && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 0ae08bcfc0..3da478c092 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4527,6 +4527,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { FormatStyle PointerLeft = getLLVMStyle(); PointerLeft.PointerBindsToType = true; verifyFormat("delete *x;", PointerLeft); + verifyFormat("STATIC_ASSERT((a & b) == 0);"); + verifyFormat("STATIC_ASSERT(0 == (a & b));"); } TEST_F(FormatTest, UnderstandsAttributes) {