mardi 6 janvier 2015

Error in template instantiation in GCC 4.9, works fine in GCC 4.8

The test code below works perfectly fine with GCC 4.8 (and 4.7):



#include <type_traits>

template<typename T, T &object, typename... Args>
struct Functor
{
template<float (T::*function)(Args...), Args... args>
struct Inner
{
float operator()() const
{
return (object.*function)(args...);
}
};
};

class Object
{
public:

float someFunction()
{
return {};
}

float someFunctionWithArgument(int)
{
return {};
}
};

Object object;

Functor<Object, object>::template Inner<&Object::someFunction> functor1;
Functor<Object, object, int>::template Inner<&Object::someFunctionWithArgument, 1> functor2;

int main()
{

}


However with GCC 4.9 it fails with a rather unhelpful message at the point of instantiation of functor1:



$ g++ -std=c++11 test.cpp
test.cpp: In instantiation of ‘struct Functor<Object, (* & object)>’:
test.cpp:33:24: required from here
test.cpp:7:9: error: wrong number of template arguments (2, should be 1)
struct Inner
^
test.cpp:7:9: error: provided for ‘template<class T, T& object, class ... Args> template<float (T::* function)(Args ...), Args ...args> struct Functor<T, object, Args>::Inner’
test.cpp:7:9: error: wrong number of template arguments (2, should be 1)
test.cpp:7:9: error: provided for ‘template<class T, T& object, class ... Args> template<float (T::* function)(Args ...), Args ...args> struct Functor<T, object, Args>::Inner’
test.cpp:33:35: error: ‘Inner’ in ‘struct Functor<Object, (* & object)>’ does not name a template type
Functor<Object, object>::template Inner<&Object::someFunction> functor1;


If I comment the line with functor1 instantiation, everything else (functor2) works fine.


Any ideas how to solve that?


Aucun commentaire:

Enregistrer un commentaire