[Bug c++/57464] c++11 create a std::function object with lambda expr
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu May 30 10:51:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57464
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |4.7.0
Summary|c++11 crate a std::function |c++11 create a
|object with lambda expr |std::function object with
| |lambda expr
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
GCC 4.7 implements
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3687.html#2132 so it
rejects the program, because the inner lambda expression has void return type
so is not convertible to function<int()>
Modifying it to not use std::function shows the bug is fixed already in GCC
4.7.0
template<typename Sig>
class function;
template<typename R, typename... A>
class function< R(A...) >
{
struct interface
{
virtual ~interface() { }
virtual R invoke(A... a) = 0;
};
template<typename F>
struct impl : interface
{
impl(F f) : f(f) { }
F f;
virtual R invoke(A... a) { return f(a...); }
};
interface* i;
public:
template<typename F>
function(F f) : i(new impl<F>(f)) { }
~function() { delete i; }
R operator()(A... a) const { return i->invoke(a...); }
};
int main()
{
function<function<int()>(int)> rclouse =
[](int i) { return [&i](){return ++i;}; };
function<int()> seed3 = rclouse(3);
__builtin_printf("%d\n", seed3());
}
More information about the Gcc-bugs
mailing list