Opened 8 years ago

Closed 8 years ago

#10196 closed Bugs (fixed)

thread_specific_ptr does not support void*

Reported by: Zhihao Yuan <lichray@…> 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)

tss_ptr_void.diff (367 bytes ) - added by Zhihao Yuan <lichray@…> 8 years ago.
patch using shared_ptr's "private" helpers

Download all attachments as: .zip

Change History (13)

by Zhihao Yuan <lichray@…>, 8 years ago

Attachment: tss_ptr_void.diff added

patch using shared_ptr's "private" helpers

comment:1 by viboes, 8 years ago

What is the value of boost::detail::sp_dereference< void >::type ?

comment:2 by viboes, 8 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

in reply to:  1 comment:3 by Zhihao Yuan <lichray@…>, 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.

comment:4 by viboes, 8 years ago

Would the following line (*) compile?

        void operator*() const
        {
            return *get(); // (*)
        }

Please, could you add a test case?

comment:5 by viboes, 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?

in reply to:  5 comment:6 by Zhihao Yuan <lichray@…>, 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.

in reply to:  4 ; comment:7 by Zhihao Yuan <lichray@…>, 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:

https://searchcode.com/codesearch/view/15464587/

in reply to:  7 comment:8 by viboes, 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:

https://searchcode.com/codesearch/view/15464587/

This is a unique_ptr test. Do you have one for thread_specific_ptr?

comment:9 by viboes, 8 years ago

Milestone: To Be DeterminedBoost 1.57.0

Oh, I got it. It is up to the user to provide the cleanup function.

in reply to:  10 comment:11 by Zhihao Yuan <lichray@…>, 8 years ago

comment:12 by viboes, 8 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.