Bug 52768 - cannot resolve address of function template with empty template argument list
Summary: cannot resolve address of function template with empty template argument list
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-03-29 12:19 UTC by kmakaron11
Modified: 2013-05-25 15:38 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.0, 4.9.0
Known to fail:
Last reconfirmed: 2012-03-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kmakaron11 2012-03-29 12:19:50 UTC
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.
Comment 1 Jonathan Wakely 2012-03-29 13:02:14 UTC
(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<>;
}
Comment 2 Jonathan Wakely 2012-03-29 13:09:10 UTC
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)
Comment 3 kmakaron11 2012-03-29 13:25:11 UTC
I am sorry, Jonathan Wakely. This is my first GCC bug report.
Next time I will, try to put the fallout to minimum.
Comment 4 Jonathan Wakely 2012-03-29 13:30:28 UTC
Even more reason to read http://gcc.gnu.org/bugs/ first then :)
Comment 5 Paolo Carlini 2013-05-25 15:38:03 UTC
This is fixed in 4.8.0.