From: Daniel Jasper Date: Tue, 21 Jul 2015 22:51:00 +0000 (+0000) Subject: clang-format: Fix unary operator detection in for loops. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb1bfe54641495484569376d9e1fbea441032aa4;p=clang clang-format: Fix unary operator detection in for loops. Before: for (;; * a = b) {} After: for (;; *a = b) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242849 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 55f5b103f9..36856eaeea 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -836,7 +836,8 @@ private: Contexts.back().IsExpression = true; if (!Line.startsWith(TT_UnaryOperator)) { for (FormatToken *Previous = Current.Previous; - Previous && !Previous->isOneOf(tok::comma, tok::semi); + Previous && Previous->Previous && + !Previous->Previous->isOneOf(tok::comma, tok::semi); Previous = Previous->Previous) { if (Previous->isOneOf(tok::r_square, tok::r_paren)) { Previous = Previous->MatchingParen; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 252ae4db3f..9cb1c31b05 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5458,6 +5458,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { FormatStyle Left = getLLVMStyle(); Left.PointerAlignment = FormatStyle::PAS_Left; verifyFormat("x = *a(x) = *a(y);", Left); + verifyFormat("for (;; * = b) {\n}", Left); verifyIndependentOfContext("a = *(x + y);"); verifyIndependentOfContext("a = &(x + y);");