Simplified code as below:
#include <string>
#include <string_view>
struct object{
operator std::string(){return "";}
}
struct foo{
foo operator[](std::string_view s){
return foo{};
}
template <typename T>
operator T(){
return object{};
}
};
int main(){
foo f;
std::string s = f["a"];
}
clang gives an error:
error: use of overloaded oeprator '[]' is ambiguous (with oeprand types 'foo' and 'const char*') note: candidate function foo operator[](std::string_view s) note: built-in candidate operator[](long, const char*) note: built-in candidate operator[](long, const volatile char*)
but gcc compiles above code successfully.
clang version is 12.0.1, gcc is 7.5.0
I'm confused, which compiler is right?