Opened 10 years ago

Closed 9 years ago

#7201 closed Bugs (fixed)

boost::make_shared clobbers libstdc++ std::thread

Reported by: t551@… Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.49.0 Severity: Problem
Keywords: make_shared thread Cc: flast@…

Description

This program fails to compile using g++ version 4.7.1.

#include <functional>
#include <thread>

#include <boost/smart_ptr.hpp>

void demo_entry(
    boost::shared_ptr<int> &demo_ptr
)
{
}

int main(int argc, char **argv)
{
    auto demo_ptr = boost::make_shared<int>(5);

    std::thread demo_thread(
        demo_entry,
        std::ref(demo_ptr)
    );

    demo_thread.join();

    return 0;
}

I get the following error output:

[100%] Building CXX object CMakeFiles/make_shared_repro.dir/make_shared_repro.cpp.o
In file included from /home/ahmedtd/project/make-shared-repro/make_shared_repro.cpp:3:0:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/thread: In instantiation of 'std::shared_ptr<std::thread::_Impl<_Callable> > std::thread::_M_make_routine(_Callable&&) [with _Callable = std::_Bind_simple<void (*(std::reference_wrapper<boost::shared_ptr<int> >))(boost::shared_ptr<int>&)>]':
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/thread:133:9:   required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(boost::shared_ptr<int>&); _Args = {std::reference_wrapper<boost::shared_ptr<int> >}]'
/home/ahmedtd/project/make-shared-repro/make_shared_repro.cpp:20:5:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4/thread:191:67: error: could not convert 'boost::make_shared(Arg1&&, Args&& ...) [with T = std::thread::_Impl<std::_Bind_simple<void (*(std::reference_wrapper<boost::shared_ptr<int> >))(boost::shared_ptr<int>&)> >; Arg1 = std::_Bind_simple<void (*(std::reference_wrapper<boost::shared_ptr<int> >))(boost::shared_ptr<int>&)>; Args = {}]()' from 'boost::shared_ptr<std::thread::_Impl<std::_Bind_simple<void (*(std::reference_wrapper<boost::shared_ptr<int> >))(boost::shared_ptr<int>&)> > >' to 'std::shared_ptr<std::thread::_Impl<std::_Bind_simple<void (*(std::reference_wrapper<boost::shared_ptr<int> >))(boost::shared_ptr<int>&)> > >'
make[2]: *** [CMakeFiles/make_shared_repro.dir/make_shared_repro.cpp.o] Error 1
make[1]: *** [CMakeFiles/make_shared_repro.dir/all] Error 2
make: *** [all] Error 2

After deciphering the template error, it appears the problem stems from line 194 in the libstdc++ <thread> header, which has a non-namespace-qualified call to make_shared. For some reason, even though this code is declared in the std namespace, it is deciding to use boost::make_shared.

This is particularly strange because at the point <thread> is processed by the compiler, no boost code has yet been included.

I have no idea whether this is bug in boost::smart_ptr, libstdc++, or the compiler itself.

Attachments (1)

make-shared-repro.tar.gz (24.8 KB ) - added by t551@… 10 years ago.
Zipped cmake project for the reproducing program.

Download all attachments as: .zip

Change History (5)

by t551@…, 10 years ago

Attachment: make-shared-repro.tar.gz added

Zipped cmake project for the reproducing program.

comment:1 by Kohei Takahashi <flast@…>, 10 years ago

It seems libstdc++'s bug, see PR53872 . GCC 4.7.2/4.8.0 will fix this bug.

comment:2 by Kohei Takahashi <flast@…>, 10 years ago

Cc: flast@… added

comment:3 by t551@…, 10 years ago

Ok, I'll work around it until that release. Thank you for finding that -- I had no idea that ADL was the magic word to search for.

comment:4 by Peter Dimov, 9 years ago

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