[utility]result_of - erroneous result type from a C++11 lambda
Hi, I've started to use C++11 lambda functions with Boost.Thread. The following works with clang-3.2 boost::future<int> f1 = boost::async( []() -> int {return 123;} ); But it fails with gcc-4.6.2, 4.7.2 and 4.8.0 ../example/lambda_future.cpp:25:91: erreur: conversion from ‘boost::future<void>’ to non-scalar type ‘boost::future<int>’ requested boost::future<int> f1 = boost::async( []() -> int {return 123;} ); The current implementation of boost::async uses boost::result_of to get the result type of the callable parameter. Is this a know bug on boost::result_of or gcc compiler? Best, Vicente
On Tuesday 02 April 2013 19:16:21 Vicente J. Botet Escriba wrote:
Hi,
I've started to use C++11 lambda functions with Boost.Thread.
The following works with clang-3.2
boost::future<int> f1 = boost::async( []() -> int {return 123;} );
But it fails with gcc-4.6.2, 4.7.2 and 4.8.0
../example/lambda_future.cpp:25:91: erreur: conversion from ‘boost::future<void>’ to non-scalar type ‘boost::future<int>’ requested boost::future<int> f1 = boost::async( []() -> int {return 123;} );
The current implementation of boost::async uses boost::result_of to get the result type of the callable parameter.
Is this a know bug on boost::result_of or gcc compiler?
I think this is because result_of is based on decltype for clang and TR1 protocol for gcc. This is because gcc doesn't support N3276. 4.8.0 release notes state that it is supported but I saw someone on the list found some bug in it so the support is incomplete for now.
On 2 April 2013 18:35, Andrey Semashev wrote:
I think this is because result_of is based on decltype for clang and TR1 protocol for gcc. This is because gcc doesn't support N3276. 4.8.0 release notes state that it is supported but I saw someone on the list found some bug in it so the support is incomplete for now.
No, the GCC 4.8 release notes say: "As of GCC 4.8.1, G++ implements the change to decltype semantics from N3276." The support is complete.
Hi All,
Andrey Semashev Vicente J. Botet Escriba wrote: Hi, I've started to use C++11 lambda functions with Boost.Thread. The following works with clang-3.2 boost::future<int> f1 = boost::async( []() -> int {return 123;} ); But it fails with gcc-4.6.2, 4.7.2 and 4.8.0 ../example/lambda_future.cpp:25:91: erreur: conversion from
‘boost::future<void>’ to non-scalar type ‘boost::future<int>’ requested
boost::future<int> f1 = boost::async( []() -> int {return 123;} ); The current implementation of boost::async uses boost::result_of to get
the result type of the callable parameter. Is this a know bug on boost::result_of or gcc compiler? I think this is because result_of is based on decltype for clang and TR1
protocol for gcc. This is because gcc doesn't support N3276. 4.8.0 release
notes state that it is supported but I saw someone on the list found some
bug
in it so the support is incomplete for now. For what it's worth, there's a patch in trac[1] which would allow the
previous to compile without requiring a full decltype implementation and
without causing errors when using tr1::result_of would succeed.
The patch was created after some discussion[2], but I haven't continued to
push for its acceptance -- work happens. Some may find it useful, however.
Thanks,
Nate
[1] https://svn.boost.org/trac/boost/ticket/7753
[2]
http://boost.2283326.n4.nabble.com/Range-amp-c-0x-Lambdas-Can-this-be-done-t...
02.04.2013 21:16, Vicente J. Botet Escriba:
Is this a know bug on boost::result_of or gcc compiler?
Try http://liveworkspace.org/code/J6bEg$0 :
#define BOOST_THREAD_PROVIDES_FUTURE
#define BOOST_RESULT_OF_USE_DECLTYPE
#include
Le 02/04/13 19:42, Evgeny Panasyuk a écrit :
02.04.2013 21:16, Vicente J. Botet Escriba:
Is this a know bug on boost::result_of or gcc compiler?
Try http://liveworkspace.org/code/J6bEg$0 :
#define BOOST_THREAD_PROVIDES_FUTURE #define BOOST_RESULT_OF_USE_DECLTYPE #include
int main() { boost::future<int> f1 = boost::async( []() -> int {return 123;} ); } // ___________________________ //
For additional info refer http://www.boost.org/users/news/a_special_note_for_boost_1_52_0_and_higher.h... , http://www.boost.org/doc/libs/1_53_0/libs/utility/utility.htm#result_of
Thanks, this works. Should then the user of Boost.Thread define BOOST_RESULT_OF_USE_DECLTYPE explicitly? Best, Vicente
02.04.2013 22:46, Vicente J. Botet Escriba:
Should then the user of Boost.Thread define BOOST_RESULT_OF_USE_DECLTYPE explicitly?
If user is happy with behaviour of decltype on his compiler - then yes, he may define BOOST_RESULT_OF_USE_DECLTYPE. I guess that in simple cases result of decltype is OK on most compilers. As Andrey Semashev pointed out, looks like current GCC implementation of decltype is not mature enough to be used by default within boost::result_of. -- Evgeny Panasyuk
2013/4/2 Evgeny Panasyuk:
As Andrey Semashev pointed out, looks like current GCC implementation of decltype is not mature enough to be used by default within boost::result_of.
Why? Have any proofs? -- Regards, niXman ___________________________________________________ Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows: http://sourceforge.net/projects/mingwbuilds/ ___________________________________________________ Another online IDE: http://liveworkspace.org/
2013/4/2 niXman:
2013/4/2 Evgeny Panasyuk:
As Andrey Semashev pointed out, looks like current GCC implementation of decltype is not mature enough to be used by default within boost::result_of.
Why? Have any proofs?
I understand what you mean: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3276.pdf Thanks. -- Regards, niXman ___________________________________________________ Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows: http://sourceforge.net/projects/mingwbuilds/ ___________________________________________________ Another online IDE: http://liveworkspace.org/
On 2 April 2013 20:44, niXman wrote:
2013/4/2 Evgeny Panasyuk:
As Andrey Semashev pointed out, looks like current GCC implementation of decltype is not mature enough to be used by default within boost::result_of.
Why? Have any proofs?
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52748 The support is complete, but only in 4.8.1 and later.
2013/4/2 Jonathan Wakely:
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52748
The support is complete, but only in 4.8.1 and later.
I.e. in gcc-4_8-branch N3276 is already implemented? -- Regards, niXman ___________________________________________________ Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows: http://sourceforge.net/projects/mingwbuilds/ ___________________________________________________ Another online IDE: http://liveworkspace.org/
2013/4/3 niXman:
I.e. in gcc-4_8-branch N3276 is already implemented?
I readed bug 52748. I have no more questions. -- Regards, niXman ___________________________________________________ Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows: http://sourceforge.net/projects/mingwbuilds/ ___________________________________________________ Another online IDE: http://liveworkspace.org/
On 13-04-02 12:53 PM, Jonathan Wakely wrote:
On 2 April 2013 20:44, niXman wrote:
2013/4/2 Evgeny Panasyuk:
As Andrey Semashev pointed out, looks like current GCC implementation of decltype is not mature enough to be used by default within boost::result_of.
Why? Have any proofs?
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52748
The support is complete, but only in 4.8.1 and later.
This is already fixed on trunk: https://svn.boost.org/trac/boost/changeset/83625 -- Eric Niebler Boost.org
Le 02/04/13 20:46, Vicente J. Botet Escriba a écrit :
Le 02/04/13 19:42, Evgeny Panasyuk a écrit :
02.04.2013 21:16, Vicente J. Botet Escriba:
Is this a know bug on boost::result_of or gcc compiler?
Try http://liveworkspace.org/code/J6bEg$0 :
#define BOOST_THREAD_PROVIDES_FUTURE #define BOOST_RESULT_OF_USE_DECLTYPE #include
int main() { boost::future<int> f1 = boost::async( []() -> int {return 123;} ); } // ___________________________ //
For additional info refer http://www.boost.org/users/news/a_special_note_for_boost_1_52_0_and_higher.h... , http://www.boost.org/doc/libs/1_53_0/libs/utility/utility.htm#result_of
Thanks, this works.
Should then the user of Boost.Thread define BOOST_RESULT_OF_USE_DECLTYPE explicitly?
BTW,
the definition of BOOST_RESULT_OF_USE_DECLTYPE can be done only if
BOOST_NO_CXX11_DECLTYPE because otherwise the inclusion of of
result_of.hpp generates some compiler errors on compilers not supporting
decltype.
#include
On Apr 2, 2013, at 4:57 PM, "Vicente J. Botet Escriba"
Le 02/04/13 20:46, Vicente J. Botet Escriba a écrit :
Le 02/04/13 19:42, Evgeny Panasyuk a écrit :
02.04.2013 21:16, Vicente J. Botet Escriba:
Is this a know bug on boost::result_of or gcc compiler?
Try http://liveworkspace.org/code/J6bEg$0 :
#define BOOST_THREAD_PROVIDES_FUTURE #define BOOST_RESULT_OF_USE_DECLTYPE #include
int main() { boost::future<int> f1 = boost::async( []() -> int {return 123;} ); } // ___________________________ //
For additional info refer http://www.boost.org/users/news/a_special_note_for_boost_1_52_0_and_higher.h... , http://www.boost.org/doc/libs/1_53_0/libs/utility/utility.htm#result_of
Thanks, this works.
Should then the user of Boost.Thread define BOOST_RESULT_OF_USE_DECLTYPE explicitly?
BTW,
the definition of BOOST_RESULT_OF_USE_DECLTYPE can be done only if BOOST_NO_CXX11_DECLTYPE because otherwise the inclusion of of result_of.hpp generates some compiler errors on compilers not supporting decltype.
#include
#if ! defined BOOST_NO_CXX11_DECLTYPE #define BOOST_RESULT_OF_USE_DECLTYPE #endif #include Could result_of.hpp undefine BOOST_RESULT_OF_USE_DECLTYPE if BOOST_NO_CXX11_DECLTYPE is defined?
This question has come up in the past. The answer we've arrived at in previous discussions has been that requesting decltype on a compiler that doesn't have decltype is a user error that should result in a compilation failure. - Daniel
Le 02/04/13 19:42, Evgeny Panasyuk a écrit :
02.04.2013 21:16, Vicente J. Botet Escriba:
Is this a know bug on boost::result_of or gcc compiler?
Try http://liveworkspace.org/code/J6bEg$0 :
#define BOOST_THREAD_PROVIDES_FUTURE #define BOOST_RESULT_OF_USE_DECLTYPE #include
int main() { boost::future<int> f1 = boost::async( []() -> int {return 123;} ); } // ___________________________ //
For additional info refer http://www.boost.org/users/news/a_special_note_for_boost_1_52_0_and_higher.h... , http://www.boost.org/doc/libs/1_53_0/libs/utility/utility.htm#result_of
Thanks, this works.
Should then the user of Boost.Thread define BOOST_RESULT_OF_USE_DECLTYPE explicitly?
I define it whenever I use lambdas with any Boost library, whether it be Range, Thread, or something else. Regards, Nate
participants (9)
-
Andrey Semashev
-
Daniel Walker
-
Eric Niebler
-
Evgeny Panasyuk
-
Jonathan Wakely
-
Nathan Crookston
-
Nathan Ridge
-
niXman
-
Vicente J. Botet Escriba