[Boost-bugs] [Boost C++ Libraries] #7598: Unable to use operator=() for boost::interprocess::unique_ptr due to its ambiguity

Subject: [Boost-bugs] [Boost C++ Libraries] #7598: Unable to use operator=() for boost::interprocess::unique_ptr due to its ambiguity
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-10-29 08:40:48


#7598: Unable to use operator=() for boost::interprocess::unique_ptr due to its
ambiguity
---------------------------------------------------+------------------------
 Reporter: Adam Romanek <romanek.adam@…> | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: interprocess
  Version: Boost 1.51.0 | Severity: Problem
 Keywords: |
---------------------------------------------------+------------------------
 I'm not able to easily use `operator=()` of
 `boost::interprocess::unique_ptr`. See the example below:

 {{{
 #include <boost/interprocess/smart_ptr/unique_ptr.hpp>
 using namespace boost::interprocess;

 class my_class {
 public:
     my_class() {}
 };

 struct my_class_deleter {
     void operator()(my_class *p) {}
 };

 typedef unique_ptr<my_class, my_class_deleter> uptr;

 uptr create() {
     return uptr();
 }

 int main() {
     uptr x;
     x = create();
     return 0;
 }
 }}}

 The problem is that gcc fails to compile the above code saying:

 {{{
 main.cpp:22: error: ambiguous overload for ‘operator=’ in ‘x = create()()’
 ../../boost_latest/boost/interprocess/smart_ptr/unique_ptr.hpp:211: note:
 candidates are: boost::interprocess::unique_ptr<T, D>&
 boost::interprocess::unique_ptr<T,
 D>::operator=(boost::rv<boost::interprocess::unique_ptr<T, D> >&) [with T
 = my_class, D = my_class_deleter]
 ../../boost_latest/boost/interprocess/smart_ptr/unique_ptr.hpp:249: note:
 boost::interprocess::unique_ptr<T, D>& boost::interprocess::unique_ptr<T,
 D>::operator=(int boost::interprocess::unique_ptr<T, D>::nat::*) [with T =
 my_class, D = my_class_deleter]
 }}}

 Now, when I change the `main()` function to something like this:

 {{{
 int main() {
     uptr x = create();
     return 0;
 }
 }}}

 the code compiles without any issues.

 I've been able to overcome this issue by using the following snippet:

 {{{
 x = static_cast<boost::rv<uptr>&>(create());
 }}}

 It works, but it's not an elegant solution. I'm not even sure if it's a
 legal construct.

 I've also investigated `boost::interprocess::unique_ptr` implementation
 and I think I've found the problem. The conversion-to-bool operator messes
 up with the `operator=()`.

 I attached a patch that fixes this problem, however I'm not sure if it
 doesn't break any existing code.

 BTW: I use gcc v4.4.3 and Boost v1.51.0 on Ubuntu 10.04.

 BTW 2: Before I managed to overcome this issue I had written about it on
 stackoverflow.com: http://stackoverflow.com/questions/13086428/how-
 should-i-assign-boostinterprocessunique-ptr-returned-from-a-factory-func

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7598>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC