Modify

Opened 2 years ago

Closed 2 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.)

Attachments (0)

Change History (4)

comment:1 Changed 2 years ago by Ben Wiederhake <Ben.Wiederhake@…>

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

comment:2 Changed 2 years ago by viboes

Owner: changed from Anthony Williams to viboes
Status: newassigned

thanks for the PR.

comment:4 Changed 2 years ago by viboes

Resolution: fixed
Status: assignedclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain viboes.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.