]> granicus.if.org Git - clang/commitdiff
clang-format: Fix false positive in pointer/reference detection.
authorDaniel Jasper <djasper@google.com>
Wed, 7 Oct 2015 01:41:14 +0000 (01:41 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 7 Oct 2015 01:41:14 +0000 (01:41 +0000)
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
unittests/Format/FormatTest.cpp

index f6a80342dc7c45583d8b5a9c41306163249426cc..55a1ddd91c0d614eb672ec3d114606baa05e77bc 100644 (file)
@@ -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 &&
index a34aa88958f690d195187c2b0742259948f3a9aa..581b10baafdf8cfb31870f5b89df746d78a4852b 100644 (file)
@@ -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"