https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100330
Bug ID: 100330 Summary: operator bool() is used when operator<() is available to do comparison Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: yin.li at bytedance dot com Target Milestone: --- code: #include <iostream> #include <map> class vertex_descriptor { public: vertex_descriptor() : p(nullptr) {} vertex_descriptor(void *pp) : p(pp) {} operator bool() const { std::cout << __func__ << std::endl; return p; } bool operator<(const vertex_descriptor b) const { std::cout << __func__ << std::endl; return p < b.p; } private: void *p; }; int main() { std::map<std::pair<vertex_descriptor, int>, vertex_descriptor> vs; vertex_descriptor v1(nullptr), v2((void *)1); vs[std::make_pair(v1, 0)] = v1; vs[std::make_pair(v2, 0)] = v2; return 0; } result: ~ $ g++ --std=c++17 1.cpp && ./a.out operator< operator< operator< operator< ~ $ g++ --std=c++20 1.cpp && ./a.out operator bool operator bool operator bool operator bool operator bool operator bool ~ $ g++ --version g++ (Ubuntu 10.2.0-13ubuntu1) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.