Opened 7 years ago

Closed 7 years ago

#11672 closed Bugs (fixed)

Thread: Should use unique_ptr, not auto_ptr

Reported by: Ben Wiederhake <Ben.Wiederhake@…> Owned by: viboes
Milestone: Boost 1.60.0 Component: thread
Version: Boost 1.59.0 Severity: Problem
Keywords: auto_ptr Cc:

Description

Boost.Thread has two occurrences of auto_ptr, which is deprecated since C++11:

$ grep -rn 'auto_ptr'
include/boost/thread/detail/thread_group.hpp:78:
  std::auto_ptr<thread> new_thread(new thread(threadfunc));
src/win32/thread.cpp:156:
  std::auto_ptr< ThreadProxyData> data(reinterpret_cast< ThreadProxyData*>(args));

This causes a warning when compiling with gcc-5.2, and soon other compilers as they become compliant with the clause "std::auto_ptr is deprecated".

I can see the following ways to resolve the warning:

  • Literally silence the warning, like in #11622. I view this as a very bad idea.
  • Use std::unique_ptr if using C++11 or newer. I view this as a bad idea.
  • Use boost::movelib::unique_ptr. I view this as a good idea.

I checked both occurrences of auto_ptr by hand, and found that in both cases, std::unique_ptr can be used just as well! (In both cases, auto_ptr is only used to guarantee a call to delete in case anything throws.)

Change History (4)

comment:1 by Ben Wiederhake <Ben.Wiederhake@…>, 7 years ago

Created fix and submitted as PR: https://github.com/boostorg/thread/pull/66

comment:2 by viboes, 7 years ago

Owner: changed from Anthony Williams to viboes
Status: newassigned

thanks for the PR.

Note: See TracTickets for help on using tickets.