r249501 - clang-format: Fix false positive in pointer/reference detection.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 6 18:41:15 PDT 2015
Author: djasper
Date: Tue Oct 6 20:41:14 2015
New Revision: 249501
URL: http://llvm.org/viewvc/llvm-project?rev=249501&view=rev
Log:
clang-format: Fix false positive in pointer/reference detection.
Before:
return options != nullptr &&operator==(*options);
After:
return options != nullptr && operator==(*options);
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=249501&r1=249500&r2=249501&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Oct 6 20:41:14 2015
@@ -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 &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=249501&r1=249500&r2=249501&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Oct 6 20:41:14 2015
@@ -5568,6 +5568,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
// 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"
More information about the cfe-commits
mailing list