[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

Malcolm Parsons via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 26 15:14:04 PST 2016


malcolm.parsons added inline comments.


================
Comment at: clang-tidy/misc/StringCompareCheck.cpp:37
+      hasArgument(0, expr().bind("str2")), argumentCountIs(1),
+      callee(memberExpr(has(implicitCastExpr(anyOf(
+          has(callExpr(has(implicitCastExpr(has(declRefExpr())))).bind("str1")),
----------------
madsravn wrote:
> malcolm.parsons wrote:
> > Do you really care what the callee expression is? 
> > Use `isArrow()` on the `MemberExpr` to check if it's a pointer.
> How else would I get str1? Using the below snippet, I only get str1.compare and str1->compare instead of str1. 
> Given a MemberExpr (str1.compare) is there an easy way to extract str1? 
> 
> ```
> const auto StrCompare = cxxMemberCallExpr(
>       callee(cxxMethodDecl(hasName("compare"),
>                            ofClass(classTemplateSpecializationDecl(
>                                hasName("::std::basic_string"))))),
>       hasArgument(0, expr().bind("str2")), argumentCountIs(1),
>       callee(memberExpr().bind("str1")))
> ```
`getBase()`


https://reviews.llvm.org/D27210





More information about the cfe-commits mailing list