Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC bug or not : default std::function?

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

like image 344
Vincent Avatar asked Nov 06 '12 19:11

Vincent


1 Answers

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

like image 56
Robᵩ Avatar answered Nov 17 '22 09:11

Robᵩ