Skip to content

Incorrect false positive warning emitted by clang-tidy readability-container-size-empty #162287

@adesitter

Description

@adesitter

Considering:

#include <string_view>

struct Label {
    virtual ~Label();
};

bool operator==(std::string_view, Label const&);

auto f() {
    std::string_view s{"aa"};
    return s == Label{};
}

clang-tidy -checks=readability-container-size-empty emits the following incorrect warning:

<source>:11:12: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object [readability-container-size-empty]
   11 |     return s == Label{};
      |            ^~~~~~~~~~~~
      |            s.empty()
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/string_view:251:7: note: method 'basic_string_view'::empty() defined here
  251 |       empty() const noexcept
      |       ^
1 warning generated.

compiler explorer

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions