From 6a9682038f2c155520453973b15f3088f7757331 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 7 Jan 2015 12:19:53 +0000 Subject: [PATCH] clang-format: Fix unary operator detection. Before: ** outparam = 1; After: **outparam = 1; llvm-svn: 225349 --- clang/lib/Format/TokenAnnotator.cpp | 8 ++++---- clang/unittests/Format/FormatTest.cpp | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 331776c..8966ab2 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -741,7 +741,8 @@ private: void modifyContext(const FormatToken &Current) { if (Current.getPrecedence() == prec::Assignment && - !Line.First->isOneOf(tok::kw_template, tok::kw_using) && + !Line.First->isOneOf(tok::kw_template, tok::kw_using, + TT_UnaryOperator) && (!Current.Previous || Current.Previous->isNot(tok::kw_operator))) { Contexts.back().IsExpression = true; for (FormatToken *Previous = Current.Previous; @@ -752,11 +753,10 @@ private: if (!Previous) break; } - if ((Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator)) && + if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) && Previous->isOneOf(tok::star, tok::amp) && Previous->Previous && - Previous->Previous->isNot(tok::equal)) { + Previous->Previous->isNot(tok::equal)) Previous->Type = TT_PointerOrReference; - } } } else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) { Contexts.back().IsExpression = true; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 66835d7..a0f4503 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5164,6 +5164,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); + verifyGoogleFormat("**outparam = 1;"); verifyGoogleFormat("int main(int argc, char** argv) {}"); verifyGoogleFormat("A a;"); verifyGoogleFormat("A a;"); -- 2.7.4