7

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) ?

Vincent
  • 57,703
  • 61
  • 205
  • 388

1 Answers1

6

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

Robᵩ
  • 163,533
  • 20
  • 239
  • 308