[ASTMatchers] Fix bug in `hasUnaryOperand`

Currently, `hasUnaryOperand` fails for the overloaded `operator*`. This patch fixes the bug and
adds tests for this case.

Differential Revision: https://reviews.llvm.org/D104389
This commit is contained in:
Yitzhak Mandelbaum 2021-06-16 14:47:18 +00:00
parent 54384d1723
commit 439c920694
2 changed files with 19 additions and 0 deletions

View File

@ -2102,6 +2102,8 @@ equivalentUnaryOperator<CXXOperatorCallExpr>(const CXXOperatorCallExpr &Node) {
return UO_Minus;
case OO_Amp:
return UO_AddrOf;
case OO_Star:
return UO_Deref;
case OO_Tilde:
return UO_Not;
case OO_Exclaim:

View File

@ -1893,6 +1893,23 @@ void plusIntOperator()
cxxOperatorCallExpr(
forFunction(functionDecl(hasName("plusIntOperator"))),
hasOperatorName("+"), hasUnaryOperand(expr())))));
Code = R"cpp(
struct HasOpArrow
{
int& operator*();
};
void foo()
{
HasOpArrow s1;
*s1;
}
)cpp";
EXPECT_TRUE(
matches(Code, traverse(TK_IgnoreUnlessSpelledInSource,
cxxOperatorCallExpr(hasOperatorName("*"),
hasUnaryOperand(expr())))));
}
TEST(Matcher, UnaryOperatorTypes) {