Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Create check to prefer operator== over wxString::Cmp #28021

Open Quuxplusone opened 8 years ago

Quuxplusone commented 8 years ago
Bugzilla Link PR28022
Status CONFIRMED
Importance P enhancement
Reported by Richard (legalize@xmission.com)
Reported on 2016-06-06 12:42:44 -0700
Last modified on 2018-02-01 10:22:42 -0800
Version unspecified
Hardware All All
CC alexfh@google.com, djasper@google.com, klimek@google.com, madsravn@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
wxWidgets' string class wxString provides operator== for both wxString and
wxChar * arguments allowing you to write:

wxString foo;
// ...
if (foo == wxT("foo")) // ...

and

wxString bar;
// ...
if (foo == bar) // ...

It also provides wxString::Cmp which is intended for sorting functions and
returns -1, 0, or 1 depending on the lexicographic relationship of the two
strings.

Create a clang-tidy check that replaces:

if (!foo.Cmp(wxT("foo"))) // ...
and
if (foo.Cmp(wxT("foo")) == 0)

with

if (foo == wxT("foo")) // ...

Similarly, replace

if (foo.Cmp(wxT("foo"))) // ...
and
if (foo.Cmp(wxT("foo")) != 0) // ...

with

if (foo != wxT("foo"))

This relates to another wxWidgets specific check
https://llvm.org/bugs/show_bug.cgi?id=27300
and both could go in a wxWidgets module
Quuxplusone commented 8 years ago

A similar check could be created for std::string::operator== vs std::string::compare.

Most string classes have some sort of lexicographical compare type function to use with sorting algorithms, so this might be a generic string class check with specific support for wxWidgets wxString.

Quuxplusone commented 7 years ago

I will look into this one. Currently I am having a little difficulty matching on the different cases. Hopefully I will have it solved soon.

Quuxplusone commented 6 years ago

Hi Mads, I'm revisiting my old clang bugs. Did you make any progress on this one?

Quuxplusone commented 6 years ago
(In reply to Richard from comment #3)
> Hi Mads, I'm revisiting my old clang bugs.  Did you make any progress on
> this one?

Hi Richard,

I made a new Clang tidy check for std::string::operator== vs
std::string::compare. I thought it would be more generic. That could easily be
extended to include wxString.
Quuxplusone commented 6 years ago

Great! Yes, the action for this bug is to extend the existing check to allow you to specify the name of a custom string class (instead of std::string) and its associated compare function (instead of std::string::compare).