Skip to content

[clang-tidy][readability-container-contains] Also match when comparing find() to string::npos. #109327

Open
@nicovank

Description

@nicovank

Opening this issue for tracking.

For std::string and std::string_view, an element is (not) found when comparing find() against std::string::npos or std::string_view::npos, not end(). This is not causing false positives since comparing a find() result to end() doesn't make sense to begin with in those classes, so in fact the check would probably be fixing bugs. (Is there a bugprone-string-find-end check?)

As of C++23 the following transformations and derivatives can be added to the check:

string.find(...) != std::string::npos; // -> string.contains(...)
string.find(...) != string.npos; // -> string.contains(...)

// Ideally, make this work for any npos, e.g. llvm::StringRef::npos.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions