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.
Created attachment 27170 [details] testcase
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
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(); }
Fixed by r251438.
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
Fixed.