From: Daniel Jasper Date: Wed, 11 Mar 2015 12:59:49 +0000 (+0000) Subject: clang-format: Fix incorrect && recognition. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b78479d858c30e789ebbbf74603f2ce8413e9ec9;p=clang clang-format: Fix incorrect && recognition. Before: if (a &&(b = c)) .. After: if (a && (b = c)) .. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231920 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index b8f8b992ce..74b7de0001 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -767,6 +767,8 @@ private: if (!Previous) break; } + if (Previous->opensScope()) + break; if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) && Previous->isOneOf(tok::star, tok::amp, tok::ampamp) && Previous->Previous && Previous->Previous->isNot(tok::equal)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 7221ec898a..3e4806f5a2 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5371,6 +5371,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("if (int *a = (&b))"); verifyIndependentOfContext("while (int *a = &b)"); verifyIndependentOfContext("size = sizeof *a;"); + verifyIndependentOfContext("if (a && (b = c))"); verifyFormat("void f() {\n" " for (const int &v : Values) {\n" " }\n"