Skip to content

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

@LegalizeAdulthood

Description

@LegalizeAdulthood
Bugzilla Link 28022
Version unspecified
OS All
CC @madsravn

Extended Description

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

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillacheck-requestRequest for a new check in clang-tidyclang-tidyconfirmedVerified by a second party

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions