I have a template structure that takes a method type and a pointer to a method as parameters and wraps it in a C-like function:
template <typename T, T> struct proxy;
template <typename T, typename R, typename ...Args, R (T::* mf)(Args...)>
struct proxy<R (T::*)(Args...), mf>
{
static R call(T& obj, Args&&... args)
{
return (obj.*mf)(std::forward<Args>(args)...);
}
};
The proxy structure works in simple scenarios, as expected, for example:
struct Foo
{
int foo(int x)
{
return x + 1;
}
};
...
Foo f;
proxy<int(Foo::*)(int), &Foo::foo>::call(f, 10);
The problem is that I use proxies inside macros, which can be deployed to:
proxy<decltype((int(Foo::*)(int))(&Foo::foo)), (int(Foo::*)(int))(&Foo::foo)>::call(f, 10);
in clang and error:
error: non-type template argument is not a pointer to member constant
proxy<decltype((int(Foo::*)(int))(&Foo::foo)), (int(Foo::*)(int))(&Foo::foo)>::call(f, 10);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GCC 4.8, on the other hand, does not report any error, and everything works as expected.
My questions:
- Is there a way around the clang error and
- Is this a bug in clang that I should probably report?
source
share