http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60514

            Bug ID: 60514
           Summary: SFINAE using decltype fails
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: boris at dolgov dot name

Hello!

Looks like there are some problems with SFINAE when calling an overloaded
function from template function.
Please, see the following code:
#include <vector>

using namespace std;

struct X { void x() {} };

template<class T> auto f(T& t) -> decltype(t.begin(), void())
{
        f(*t.begin());
}

template<class T> auto f(T& t) -> decltype(t.x(), void())
{

}

int main()
{
        vector<X> a(1);
        f(a);
}
It compiles with clang, but with g++-4.8.1 I get the following error:
test.cpp: In instantiation of ‘decltype ((t.begin(), void())) f(T&) [with T =
std::vector<X>; decltype ((t.begin(), void())) = void]’:
test.cpp:21:5:   required from here
test.cpp:10:14: error: call of overloaded ‘f(X&)’ is ambiguous
  f(*t.begin());
              ^
test.cpp:10:14: note: candidates are:
test.cpp:8:24: note: decltype ((t.begin(), void())) f(T&) [with T = X; decltype
((t.begin(), void())) = void]
 template<class T> auto f(T& t) -> decltype(t.begin(), void())
                        ^
test.cpp:13:24: note: decltype ((t.x(), void())) f(T&) [with T = X; decltype
((t.x(), void())) = void]
 template<class T> auto f(T& t) -> decltype(t.x(), void())
                        ^

decltype(t.begin(), void()) with T = X obviously can't be void.
If I replace the line f(a) with f(*a.begin()), everything works correctly.

Reply via email to