Title
shared_ptr conversion constructor not constrained
Status
cd1
Section
[util.smartptr.shared.const][util.smartptr.weak.const]
Submitter
Peter Dimov

Created on 2007-05-10.00:00:00 last changed 172 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

In [util.smartptr.shared.const], change:

-14- Requires: For the second constructor The second constructor shall not participate in the overload resolution unless Y* shall be is implicitly convertible to T*.

In [util.smartptr.weak.const], change:

template<class Y> weak_ptr(shared_ptr<Y> const& r);
weak_ptr(weak_ptr const& r);
template<class Y> weak_ptr(weak_ptr<Y> const& r);
weak_ptr(weak_ptr const& r);
template<class Y> weak_ptr(weak_ptr<Y> const& r);
template<class Y> weak_ptr(shared_ptr<Y> const& r);

-4- Requires: For tThe second and third constructors, shall not participate in the overload resolution unless Y* shall be is implicitly convertible to T*.

Date: 2007-05-10.00:00:00

Since all conversions from shared_ptr<T> to shared_ptr<U> have the same rank regardless of the relationship between T and U, reasonable user code that works with raw pointers fails with shared_ptr:

void f( shared_ptr<void> );
void f( shared_ptr<int> );

int main()
{
  f( shared_ptr<double>() ); // ambiguous
}

Now that we officially have enable_if, we can constrain the constructor and the corresponding assignment operator to only participate in the overload resolution when the pointer types are compatible.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg3442
2007-05-10 00:00:00admincreate