Incorrect false positive warning emitted by clang-tidy readability-container-size-empty
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.
@llvm/issue-subscribers-clang-tidy
Author: Arnaud Desitter (adesitter)
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](https://godbolt.org/z/6953xh7d4)
</details>