简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM