Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

Why does this type conversion [not] work?

$
0
0

Consider the following code (live demo):

class Foo
{
public:
    void method();
};

template <typename T> struct Member;
template <typename T> struct Member<void (T::*)()>
{
    using Object = T;
};

template <typename T> class Pointer
{
public:
    operator T*();
};

template <typename Func>
void bar(typename Member<Func>::Object*, Func) {}

void test()
{
    Pointer<Foo> p;
    bar(p, &Foo::method);
}

This compiles with GCC ≥ 4.9, but GCC 4.8 doesn't know to invoke the conversion operator:

error: no matching function for call to 'bar(Pointer<Foo>&, void (Foo::*)())'
     bar(p, &Foo::method);
note: candidate is:
note: template<class Func> void bar(typename Member<Func>::Object*, Func) void bar(typename Member<Func>::Object*, Func) {}
note:   template argument deduction/substitution failed:
note:   mismatched types 'typename Member<Func>::Object*' and 'Pointer<Foo>'
     bar(p, &Foo::method);

Why? Is it a bug? Is it a new feature in C++14? Please cite either the C++ feature or GCC bug report if possible.

Thanks!

(Note: I have a work-around for my real code, I'm just wondering what changed in the compiler...)


Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>