summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-10-07 01:41:14 +0000
committerDaniel Jasper <djasper@google.com>2015-10-07 01:41:14 +0000
commita164fa507bb77b057e0e3d3f5dbab0e9d15bfde4 (patch)
tree6ccfdbe8e5329af6df90090063034ccc69a6fed7
parentd9ceee0abb2822019cb083ff865b3bd0f4e4bcaa (diff)
downloadclang-a164fa507bb77b057e0e3d3f5dbab0e9d15bfde4.tar.gz
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
-rw-r--r--lib/Format/TokenAnnotator.cpp4
-rw-r--r--unittests/Format/FormatTest.cpp1
2 files changed, 4 insertions, 1 deletions
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"