From a164fa507bb77b057e0e3d3f5dbab0e9d15bfde4 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 7 Oct 2015 01:41:14 +0000 Subject: [PATCH] clang-format: Fix false positive in pointer/reference detection. Before: return options != nullptr &&operator==(*options); After: return options != nullptr && operator==(*options); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249501 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 4 +++- unittests/Format/FormatTest.cpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index f6a80342dc..55a1ddd91c 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1158,7 +1158,9 @@ private: if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare)) return TT_PointerOrReference; - if (NextToken->isOneOf(tok::kw_operator, tok::comma, tok::semi)) + if (NextToken->is(tok::kw_operator) && !IsExpression) + return TT_PointerOrReference; + if (NextToken->isOneOf(tok::comma, tok::semi)) return TT_PointerOrReference; if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index a34aa88958..581b10baaf 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5568,6 +5568,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { // verifyIndependentOfContext("MACRO(A *a);"); verifyFormat("DatumHandle const *operator->() const { return input_; }"); + verifyFormat("return options != nullptr && operator==(*options);"); EXPECT_EQ("#define OP(x) \\\n" " ostream &operator<<(ostream &s, const A &a) { \\\n" -- 2.50.1