Open
Description
Describe the bug
The bug reported in GCC Bugzilla #115939 is currently also present in MSVC STL. Iterator comparison is currently broken for all but set containers.
The reason of the bug is that expected<any, T>
is so permissive on implicit conversion that operator==
for expected
can cause ambiguity. Note that while there may be a defect in expected
, such ambiguity can also caused by some (misdesigned) user-defined types in C++14 mode.
Command-line test case
#include <any>
#include <expected>
#include <vector>
#include <forward_list>
#include <deque>
#include <list>
#include <array>
#include <map>
// #include <set> // possibly fine
#include <unordered_map>
// #include <unordered_set> // possibly fine
int main()
{
{
std::array<std::expected<std::any, char>, 1> cont{};
(void)(cont.begin() == cont.end());
}
{
std::vector<std::expected<std::any, char>> cont;
(void)(cont.begin() == cont.end());
}
{
std::forward_list<std::expected<std::any, char>> cont;
(void)(cont.begin() == cont.end());
}
{
std::list<std::expected<std::any, char>> cont;
(void)(cont.begin() == cont.end());
}
{
std::deque<std::expected<std::any, char>> cont;
(void)(cont.begin() == cont.end());
}
{
std::map<int, std::expected<std::any, char>> cont;
(void)(cont.begin() == cont.end());
}
{
std::multimap<int, std::expected<std::any, char>> cont;
(void)(cont.begin() == cont.end());
}
{
std::unordered_map<int, std::expected<std::any, char>> cont;
(void)(cont.begin() == cont.end());
}
{
std::unordered_multimap<int, std::expected<std::any, char>> cont;
(void)(cont.begin() == cont.end());
}
}
Expected behavior
This program compiles and operator==
overloads for iterators are selected.
STL version
Microsoft Visual Studio Community 2022
Version 17.11.0 Preview ? (14.41.33923 from Godbolt)
Still present in 17.11.0 Preview 4.0 and ecbc1ef.