GCC 4.6.3, as well as GCC 4.8 cannot resolve template method, even if it is explicitly instantiated. The code to explain the problem is: template <class T> struct Creator { template <typename...Ts> static std::shared_ptr<T> create(Ts&&... vs) { std::shared_ptr<T> t(new T(std::forward<Ts>(vs)...)); return t; } }; class Car: public Creator<Car> { private: friend class Creator<Car>; Car() { } }; int main() { std::function< std::shared_ptr<Car> () > createFn=&Car::create<>; return 0; } This results in following compiler error: error: conversion from ‘<unresolved overloaded function type>’ to non-scalar type ‘std::function<std::shared_ptr<Car>()>’ requested However it compiles fine on Clang3.0 and 3.1.
(In reply to comment #0) > The code to explain the problem is: No it isn't, it's missing several include files. I know it's "obvious" which ones they are, but if five different people all look at the bug report and try to reproduce the behaviour then they all have to figure it out and modify the code. You'd save everyone time by providing a *complete* testcase, as clearly requested by the bug submissions guidelines. A complete example would be: template<typename Res> struct function { template<typename F> function(F) { } }; template <class T> struct Creator { template <typename...Ts> static T* create(Ts&&... vs) { return new T(vs...); } }; class Car: public Creator<Car> { private: friend class Creator<Car>; Car() { } }; int main() { function< Car* () > createFn=&Car::create<>; }
Same problem using a default template argument instead of a parameter pack: template<typename Res> struct function { template<typename F> function(F) { } }; template <class T> struct Creator { template <typename Ts = int> static T* create(Ts vs) { return new T(vs); } }; class Car: public Creator<Car> { private: friend class Creator<Car>; Car(int) { } }; int main() { function< Car* () > createFn=&Car::create<>; } (technically this is a C++11 bug, but G++ supports variadic templates and default template arguments for functions in c++98 mode)
I am sorry, Jonathan Wakely. This is my first GCC bug report. Next time I will, try to put the fallout to minimum.
Even more reason to read http://gcc.gnu.org/bugs/ first then :)
This is fixed in 4.8.0.