From: Daniel Jasper Date: Mon, 28 Apr 2014 09:19:28 +0000 (+0000) Subject: clang-format: Improve binary operator detection. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a7de2412c5eb546b125d33802b17c608e6645a3;p=clang clang-format: Improve binary operator detection. Before: *(int *)(p &~3UL) = 0; After: *(int *)(p & ~3UL) = 0; This fixes llvm.org/PR19464. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207405 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 54961218a2..843d877718 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -682,7 +682,7 @@ private: for (FormatToken *Previous = Current.Previous; Previous && !Previous->isOneOf(tok::comma, tok::semi); Previous = Previous->Previous) { - if (Previous->is(tok::r_square)) + if (Previous->isOneOf(tok::r_square, tok::r_paren)) Previous = Previous->MatchingParen; if (Previous->Type == TT_BinaryOperator && Previous->isOneOf(tok::star, tok::amp)) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c006c399f3..084d1dd33d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -4523,6 +4523,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("a * [self dostuff];"); verifyIndependentOfContext("int x = a * (a + b);"); verifyIndependentOfContext("(a *)(a + b);"); + verifyIndependentOfContext("*(int *)(p & ~3UL) = 0;"); verifyIndependentOfContext("int *pa = (int *)&a;"); verifyIndependentOfContext("return sizeof(int **);"); verifyIndependentOfContext("return sizeof(int ******);");