Opened 8 years ago
Closed 8 years ago
#10196 closed Bugs (fixed)
thread_specific_ptr does not support void*
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | Boost 1.57.0 | Component: | thread |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Forming reference to void in T& operator*
.
Attachments (1)
Change History (13)
by , 8 years ago
Attachment: | tss_ptr_void.diff added |
---|
follow-up: 3 comment:1 by , 8 years ago
What is the value of boost::detail::sp_dereference< void >::type ?
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
Replying to viboes:
What is the value of boost::detail::sp_dereference< void >::type ?
void
.
boost::detail::sp_dereference
is used by shared_ptr
internally to implement shared_ptr<void>.get
. shared_ptr
is the underlying implementation of thread_specific_ptr
.
follow-up: 7 comment:4 by , 8 years ago
Would the following line (*) compile?
void operator*() const { return *get(); // (*) }
Please, could you add a test case?
follow-up: 6 comment:5 by , 8 years ago
Well it seems that this compiles, but I'm getting these warnings
clang-darwin.compile.c++ ../../../bin.v2/libs/thread/test/test_tss_lib.test/clang-darwin-3.2_11/debug/threading-multi/test_tss.o In file included from test_tss.cpp:13: ../../../boost/thread/tss.hpp:42:17: warning: cannot delete expression with pointer-to-'void' type 'void *' delete static_cast<T*>(data); ^ ~~~~~~~~~~~~~~~~~~~~~ ../../../boost/thread/pthread/thread_heap_alloc.hpp:17:24: note: in instantiation of member function 'boost::thread_specific_ptr<void>::delete_data::operator()' requested here return new T(); ^ ../../../boost/thread/tss.hpp:68:21: note: in instantiation of function template specialization 'boost::detail::heap_new<boost::thread_specific_ptr<void>::delete_data>' requested here cleanup(detail::heap_new<delete_data>(),detail::do_heap_delete<delete_data>()) ^ test_tss.cpp:51:34: note: in instantiation of member function 'boost::thread_specific_ptr<void>::thread_specific_ptr' requested here boost::thread_specific_ptr<void> tss_void; ^ 1 warning generated.
How do you want to use it?
comment:6 by , 8 years ago
Replying to viboes:
Well it seems that this compiles, but I'm getting these warnings
clang-darwin.compile.c++ ../../../bin.v2/libs/thread/test/test_tss_lib.test/clang-darwin-3.2_11/debug/threading-multi/test_tss.o In file included from test_tss.cpp:13: ../../../boost/thread/tss.hpp:42:17: warning: cannot delete expression with pointer-to-'void' type 'void *' delete static_cast<T*>(data); ^ ~~~~~~~~~~~~~~~~~~~~~ ../../../boost/thread/pthread/thread_heap_alloc.hpp:17:24: note: in instantiation of member function 'boost::thread_specific_ptr<void>::delete_data::operator()' requested here return new T(); ^ ../../../boost/thread/tss.hpp:68:21: note: in instantiation of function template specialization 'boost::detail::heap_new<boost::thread_specific_ptr<void>::delete_data>' requested here cleanup(detail::heap_new<delete_data>(),detail::do_heap_delete<delete_data>()) ^ test_tss.cpp:51:34: note: in instantiation of member function 'boost::thread_specific_ptr<void>::thread_specific_ptr' requested here boost::thread_specific_ptr<void> tss_void; ^ 1 warning generated.
C++11's default_delete is ill-formed for incomplete types including void.
It's boost::shared_ptr's job to decide whether deleting void* is OK or not.
How do you want to use it?
Many C APIs expose their interface types with an opaque pointer; void* is a choice. You'll need to use a customized deleter calling the C API's cleanup function.
follow-up: 8 comment:7 by , 8 years ago
Replying to viboes:
Please, could you add a test case?
Sorry I'm so lazy... But you can copy & paste libc++'s test on void* support:
comment:8 by , 8 years ago
Replying to Zhihao Yuan <lichray@…>:
Replying to viboes:
Please, could you add a test case?
Sorry I'm so lazy... But you can copy & paste libc++'s test on void* support:
This is a unique_ptr test. Do you have one for thread_specific_ptr?
comment:9 by , 8 years ago
Milestone: | To Be Determined → Boost 1.57.0 |
---|
Oh, I got it. It is up to the user to provide the cleanup function.
follow-up: 11 comment:10 by , 8 years ago
comment:11 by , 8 years ago
Replying to viboes:
https://github.com/boostorg/thread/commit/27befdf26fbfdc977010f40b6590415a84196916
Looks good to me.
comment:12 by , 8 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
patch using shared_ptr's "private" helpers