https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106993

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

struct string_view { string_view(const char*) { } };

struct object{};

struct foo{
  foo operator[](string_view s){
    return foo{};
  }

  template <typename T>
  operator T(){
    return object{};
  }
};

int main(){
  foo f;
  f["a"]; 
}

Clang and EDG both say this is ambiguous, because f["a"] could be either:

   "a"[(ptrdiff_t) f]

or:

   f.operator[](string_view("a"));

GCC and MSVC select the second one.


If the conversion operator isn't a template, then all compilers agree it's
ambiguous:

struct string_view { string_view(const char*) { } };

struct foo{
  foo operator[](string_view s){
    return foo{};
  }

  operator long(){
    return 0;
  }
};

int main(){
  foo f;
  f["a"]; 
}

Reply via email to