Opened 7 years ago
Closed 7 years ago
#11266 closed Bugs (fixed)
boost::packaged_task has invalid variadic signature
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | Boost 1.60.0 | Component: | thread |
Version: | Boost 1.58.0 | Severity: | Problem |
Keywords: | packaged_task, variadic | Cc: |
Description
The following code doesn't compile:
#define BOOST_THREAD_VERSION 4 #include <boost/thread/future.hpp> void func(int) { } int main() { boost::packaged_task<void(int)> task{func}; }
Compilation error is caused by the misuse of BOOST_THREAD_RV_REF
macro. Constructor expects argument of type void(int&&)
and can't accept func
. There is similar issue with operator ()
. The file future.hpp
needs to be patched:
diff --git a/include/boost/thread/future.hpp b/include/boost/thread/future.hpp index e6e2236..e477535 100644 --- a/include/boost/thread/future.hpp +++ b/include/boost/thread/future.hpp @@ -2715,3 +2715,3 @@ #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) - typedef R (*CallableType)(BOOST_THREAD_RV_REF(ArgTypes) ... ); + typedef R (*CallableType)(ArgTypes ... ); #else @@ -2946,3 +2946,3 @@ #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) - typedef void (*CallableType)(BOOST_THREAD_RV_REF(ArgTypes)...); + typedef void (*CallableType)(ArgTypes...); #else @@ -3269,3 +3269,3 @@ #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD) - void operator()(BOOST_THREAD_RV_REF(ArgTypes)... args) { + void operator()(ArgTypes... args) { if(!task) {
Change History (6)
comment:1 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 7 years ago
It seems that the last change is not really needed.
- void operator()(BOOST_THREAD_RV_REF(ArgTypes)... args) { + void operator()(ArgTypes... args) {
Please, could you confirm?
comment:3 by , 7 years ago
It's needed. Just try slightly modified test:
#define BOOST_THREAD_VERSION 4 #include <boost/thread/future.hpp> void func(int) { } int main() { boost::packaged_task<void(int)> task{func}; task(0); // ok int x = 0; task(x); // compile error: can't bind to rvalue reference }
comment:4 by , 7 years ago
Milestone: | To Be Determined → Boost 1.59.0 |
---|
comment:5 by , 7 years ago
Milestone: | Boost 1.59.0 → Boost 1.60.0 |
---|
comment:6 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Hi, you are surely right. I will take a look soon.