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

            Bug ID: 104218
           Summary: 23_containers/vector/ext_pointer/types tests rely on
                    GCC overload-resolution bug
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: brooks at gcc dot gnu.org
  Target Milestone: ---

In cleaning up some old internal bugs, I came across this one from years ago
when I was running the 4.9.4 libstdc++ testsuite through Clang, and it looks
like it's still relevant.

The 23_containers/vector/ext_pointer/types/{1,2}.cc programs compile
successfully with GCC, of course, but with Clang we get "use of overloaded
operator '-' is ambiguous" errors in std::vector<N::X,
__gnu_cxx::_ExtPtr_allocator<N::X> >.

This reduced testcase shows the difference in the two compilers' behavior:

----
  template<typename T> struct X {
    template<typename U> void operator-(const X<U>&);
  };
  template<typename T> void operator-(T, T);

  void f(X<int> x) { x - x; }
----

Compiler explorer link: https://godbolt.org/z/nnb98W5nW

Richard Smith believes this is a GCC bug, not a Clang bug, per this analysis:
> GCC appears to believe the member function is more specialized, and calls it.
> Clang and I think that's wrong: deduction fails in both directions in partial
> ordering, so the call is ambiguous.
>
> Indeed, C++ DR 532 gives a very similar example. Following its rule, the above
> would be equivalent to:
>
>  template<typename T> struct X {};
>  template<typename T, typename U> void operator-(X<T> &, const X<U>&);
>  template<typename T> void operator-(T, T);
>
>  void f(X<int> x) { x - x; }
>
> ... which GCC and Clang agree is ambiguous. So: this test is relying on a GCC
> bug.
----

Reply via email to