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

Mads Ravn via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 1 12:37:28 PST 2016


Hi Malcolm,

Thanks for the suggestions, I have been reading up on the fixits.
My initial four cases has been reduced to two a little more general cases:
1 & 2: implicitCast to bool str1.compare(str2). This case covers both
!str1.compare(str2) and str1.compare(str2)
3 & 4: str1.compare(str2) == 0 and str1.compare(str2) != 0.

I see the idea for the fixit clearly for case 3 & 4. Just erase
.compare(str2) and replace 0 with str2. I have a quick question though:
Given the declRefExpr().bind("str2"), how do I read the name of it in
clang-tidy? Or should I just bind 0 as well and then create replacement
with str where const auto str = Result.Nodes.getNodeAs<Stmt>("str2") ?

Where I seem to find a little trouble is how to fixit case 1 & 2 now that
they are reduced to one case. How do I check whether or not there is a
unary operator in front of the implicitCast?

Thank you,
Mads Ravn

On Thu, Dec 1, 2016 at 8:53 PM Mads Ravn via Phabricator <
reviews at reviews.llvm.org> wrote:

> madsravn updated this revision to Diff 79961.
> madsravn added a comment.
>
> Fixed broken tests.
>
>
> https://reviews.llvm.org/D27210
>
> Files:
>   clang-tidy/misc/CMakeLists.txt
>   clang-tidy/misc/MiscTidyModule.cpp
>   clang-tidy/misc/StringCompareCheck.cpp
>   clang-tidy/misc/StringCompareCheck.h
>   docs/ReleaseNotes.rst
>   docs/clang-tidy/checks/list.rst
>   docs/clang-tidy/checks/misc-string-compare.rst
>   test/clang-tidy/misc-string-compare.cpp
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161201/84e8efdd/attachment.html>


More information about the cfe-commits mailing list