How to specify a default function as a parameter of a class member ?
A current example derived from my code is :
#include <iostream>
#include <functional>
template<typename T> struct C
{
static T test(std::function<T(int)> f = [](int i){return i;})
{return f(42);}
};
int main(int argc, char* argv[])
{
C<int>::test(); // ERROR = internal compiler error : in tsubst_copy, at cp/pt.c:11354
C<int>::test([](int i){return i;}); // OK
return 0;
}
Is it a bug of GCC ?
Is it possible to avoid this problem with another syntax ?
Can you try it on other C++11 compilers (for people that have ones) ?
Without question, this is a compiler bug. Regardless of whether your program is well-formed, the compiler has detected an inconsistency in its own data structures.
Please follow the GCC bug-reporting instructions: http://gcc.gnu.org/bugs/#report
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With