Bug 53009 - pointer to static member function of template class is “invalid” as a template argument of another template class
Summary: pointer to static member function of template class is “invalid” as a templat...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.2
: P3 normal
Target Milestone: 8.0
Assignee: Marek Polacek
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-04-16 16:07 UTC by Lorenzo Pistone
Modified: 2021-08-12 02:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-06-21 00:00:00


Attachments
testcase (1.06 KB, text/x-c++src)
2012-04-16 16:09 UTC, Lorenzo Pistone
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lorenzo Pistone 2012-04-16 16:07:59 UTC
I believe that this bug is somewhat related to #35167: probably g++ thinks that the address of a static member function of a template class is not a constant expression, whereas it is. I'm filing a new bug though because the situation here involves two distinct class templates, the error message is different ("error: template argument 2 is invalid", not helpful at all), and because it's said in the comments of #35167 that it's fixed if C++11 is used, whereas my testcase is compiled with and needs C++11 (for variadic templates).

Fails to build with g++ 4.6.2 4.5.4 4.4.6.
Comment 1 Lorenzo Pistone 2012-04-16 16:09:16 UTC
Created attachment 27170 [details]
testcase
Comment 2 Lorenzo Pistone 2012-04-16 16:22:04 UTC
I just tested, the problem happens only if the template arguments of function_proxy are function pointers. More trivial types (int is what I've tested) just work fine
Comment 3 Jonathan Wakely 2012-04-16 16:53:46 UTC
reduced:

template<typename T, T> class function_proxy;

template<typename Return, typename Obj, Return(*func)(Obj)>
struct function_proxy<Return(*)(Obj), func>
{
    static void wrapper(){ }
};

template<typename CT, CT> class member_helper;

template<typename Class, void(Class::*fun)()>
struct member_helper<void(Class::*)(), fun>
{
    static void as_free(Class& obj){ }

    static void worker(){
        //ERROR HERE: template argument 2 is invalid. Not very helpful message.
        (void) function_proxy<decltype(&as_free), &as_free>::wrapper;
    }
};

struct Test
{
    void test(){ }
};

int main()
{
    //does not work
    member_helper<decltype(&Test::test), &Test::test>::worker();
}
Comment 4 Marek Polacek 2019-08-02 17:47:54 UTC
Fixed by r251438.
Comment 5 Marek Polacek 2019-08-02 17:52:28 UTC
Author: mpolacek
Date: Fri Aug  2 17:51:53 2019
New Revision: 274027

URL: https://gcc.gnu.org/viewcvs?rev=274027&root=gcc&view=rev
Log:
	PR c++/53009
	* g++.dg/cpp0x/nontype3.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/nontype3.C
Modified:
    trunk/gcc/testsuite/ChangeLog
Comment 6 Marek Polacek 2019-08-02 17:53:10 UTC
Fixed.