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

            Bug ID: 127574
           Summary: Address of templated conversion operator is treated as
                    <unresolved overloaded function type>
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arthur.j.odwyer at gmail dot com
  Target Milestone: ---

// https://godbolt.org/z/3raz4d9sn
struct A {
  template<class T> operator T();
};
auto mp2 = &A::operator int;
int test(A a) {
  return (a .* &A::operator int)();
}

Clang and MSVC accept. GCC rejects, since the dawn of time, with:
error: unable to deduce 'auto' from '& A::operator T'
   11 | auto mp2 = &A::operator int;
note:   couldn't deduce template parameter 'auto'
   11 | auto mp2 = &A::operator int;
      |                         ^~~

and

error: '& A::operator T' cannot be used as a member pointer, since it is of
type '<unresolved overloaded function type>'
   15 |     return (a .* &A::operator int)();
      |                               ^~~

Surprisingly, it works fine if you hard-code a type for the member pointer to
convert to:

    using MP = int (A::*)();
    MP mp = &A::operator int;

I think what's happening here is that GCC understands that `operator int` names
the `operator T` template, but doesn't understand that the `int` actually
provides all the template arguments needed. The error messages quoted above
follow the same pattern as what GCC gives for this code, where GCC agrees with
Clang and MSVC:

// https://godbolt.org/z/YzYTfPr5G
struct A {
  template<class T> T f();
};
using MP = int (A::*)();
MP mp = &A::f; // OK, say all three vendors
auto mp2 = &A::f; // rejected by all three
int test(A a) {
  return (a .* &A::f)(); // rejected by all three
}
  • [Bug c++/127574] New: Addres... arthur.j.odwyer at gmail dot com via Gcc-bugs

Reply via email to