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

            Bug ID: 78446
           Summary: Ambiguous member lookup for operator() in a function
                    call expression treated as hard error in SFINAE
                    context
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rs2740 at gmail dot com
  Target Milestone: ---

Reduced from http://stackoverflow.com/q/40706399/2756719:

struct A { void operator()(); };
struct B { void operator()(); };
struct C : A, B {};

template<class T>
decltype(T()()) foo(int);

template<class> int foo(...);

using type = decltype(foo<C>(0));
using type = int;

produces:

prog.cc: In substitution of 'template<class T> decltype (T()()) foo(int) [with
T = C]':
prog.cc:10:31:   required from here
prog.cc:6:13: error: request for member 'operator()' is ambiguous
 decltype(T()()) foo(int);
          ~~~^~
prog.cc:2:17: note: candidates are: void B::operator()()
 struct B { void operator()(); };
                 ^~~~~~~~
prog.cc:1:17: note:                 void A::operator()()
 struct A { void operator()(); };
                 ^~~~~~~~
prog.cc: In substitution of 'template<class T> decltype (T()()) foo(int) [with
T = C]':
prog.cc:10:31:   required from here
prog.cc:6:13: error: request for member 'operator()' is ambiguous
 decltype(T()()) foo(int);
          ~~~^~
prog.cc:2:17: note: candidates are: void B::operator()()
 struct B { void operator()(); };
                 ^~~~~~~~
prog.cc:1:17: note:                 void A::operator()()
 struct A { void operator()(); };
                 ^~~~~~~~

(Yes, the error messages are repeated, see
http://melpon.org/wandbox/permlink/nZj4Wn9ZgFMMm63l)

Surprisingly enough, using 'decltype(T().operator()())' compiles
(http://melpon.org/wandbox/permlink/2sJ0ZGcA4ZIvqfvn), so it seems that this
doesn't affect all name lookup, only when the overloaded operator() is used by
a function call expression.

Reply via email to