From 7e27400c90e9e295bcf5857eebf2d60c4b32106e Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 11 Sep 2013 20:37:10 +0000 Subject: [PATCH] clang-format: Fix bug in pointer detection Before: for (int i = 0; i* 2 < z; i *= 2) {} After: for (int i = 0; i * 2 < z; i *= 2) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190546 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTest.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index f10e68c340..dec631fcfb 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -574,7 +574,7 @@ private: (!Current.Previous || Current.Previous->isNot(tok::kw_operator))) { Contexts.back().IsExpression = true; for (FormatToken *Previous = Current.Previous; - Previous && Previous->isNot(tok::comma); + Previous && !Previous->isOneOf(tok::comma, tok::semi); Previous = Previous->Previous) { if (Previous->is(tok::r_square)) Previous = Previous->MatchingParen; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 00ece1a659..2500c8e4a7 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3825,6 +3825,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { "}"); verifyFormat("for (int i = a * a; i < 10; ++i) {\n}"); verifyFormat("for (int i = 0; i < a * a; ++i) {\n}"); + verifyGoogleFormat("for (int i = 0; i * 2 < z; i *= 2) {\n}"); verifyFormat("#define MACRO \\\n" " int *i = a * b; \\\n" -- 2.40.0