Clang when adding typecast to template parameter method

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?
+4
source share
1 answer

, . , -. .

, - :

#define WORKING_LUA_METHOD_FLAGS(name_, methodType_, methodPtr_, flags_) \
  ANKI_LUA_FUNCTION_AS_METHOD_FLAGS(name_, \
  (&proxy<methodType_, methodPtr_>::func), flags_)

:

ANKI_LUA_METHOD_FLAGS( "bob", (int(Foo::*)(int))(&Foo::foo), empty_flags )

:

WORKING_LUA_METHOD_FLAGS( "bob", int(Foo:::*)(int), &Foo::foo, empty_flags )

. "bob" empty_flags , . .

+1

Source: https://habr.com/ru/post/1536181/


All Articles