Title
auto_ptr_ref creation requirements underspecified
Status
resolved
Section
[auto.ptr.conv]
Submitter
Hubert Tong

Created on 2015-05-28.00:00:00 last changed 102 months ago

Messages

Date: 2016-08-07.20:34:58

Proposed resolution:

Resolved by acceptance of N4190.

Date: 2016-08-05.03:33:05

[ 2016-08 - Chicago ]

Thurs AM: Moved to Tentatively Resolved

Date: 2016-08-15.00:00:00

[ 2016-08-03, Alisdair Meredith comments ]

As C++17 removes auto_ptr, I suggest closing this issue as closed by paper N4190.

Previous resolution [SUPERSEDED]:

This wording is relative to ISO/IEC 14882:2014(E).

  1. Change [auto.ptr.conv] as indicated:

    template<class Y> operator auto_ptr_ref<Y>() throw();
    

    -?- Requires: X* can be implicitly converted to Y*.

    -3- Returns: An auto_ptr_ref<Y> that holds *this.

    -?- Notes: Because auto_ptr_ref is present for exposition only, the only way to invoke this function is by calling one of the auto_ptr conversions which take an auto_ptr_ref as an argument. Since all such conversions will call release() on *this (in the form of the auto_ptr that the auto_ptr_ref holds a reference to), an implementation of this function may cause instantiation of said release() function without changing the semantics of the program.

    template<class Y> operator auto_ptr<Y>() throw();
    

    -?- Requires: X* can be implicitly converted to Y*.

    -4- Effects: Calls release().

    -5- Returns: An auto_ptr<Y> that holds the pointer returned from release().

Date: 2016-03-15.00:00:00

[ 2016-03-16, Alisdair Meredith comments ]

This issue is a defect in a component we have actively removed from the standard. I can't think of a clearer example of something that is no longer a defect!

Date: 2016-05-06.14:05:27

[ 2015-07, Telecon ]

Marshall to resolve.

Date: 2015-05-28.00:00:00

In C++14 sub-clause [auto.ptr.conv], there appears to be no requirement that the formation of an auto_ptr_ref<Y> from an auto_ptr<X> is done only when X* can be implicitly converted to Y*.

For example, I expect formation of the auto_ptr_ref<A> from the prvalue of type auto_ptr<B> to be invalid in the case below (but the wording does not seem to be there):

#include <memory>

struct A { };
struct B { } b;

std::auto_ptr<B> apB() { return std::auto_ptr<B>(&b); }
int main() {
  std::auto_ptr<A> apA(apB());
  apA.release();
}

The behaviour of the implementation in question on the case presented above is to compile and execute it successfully (which is what the C++14 wording implies). The returned value from apA.release() is essentially reinterpret_cast<A*>(&b).

There is nothing in the specification of

template <class X>
template <class Y> operator auto_ptr<X>::auto_ptr_ref<Y>() throw();

which implies that X* should be implicitly convertible to Y*.

The implementation in question uses the reinterpret_cast interpretation even when Y is an accessible, unambiguous base class of X; the result thereof is that no offset adjustment is performed.

History
Date User Action Args
2016-08-05 03:33:05adminsetmessages: + msg8409
2016-08-05 03:33:05adminsetstatus: open -> resolved
2016-08-03 21:05:13adminsetmessages: + msg8376
2016-05-06 14:05:27adminsetmessages: + msg8071
2015-11-05 06:08:51adminsetstatus: new -> open
2015-09-27 20:55:06adminsetmessages: + msg7555
2015-06-10 20:27:53adminsetmessages: + msg7463
2015-05-28 00:00:00admincreate