Thread View: comp.std.c++
1 messages
1 total messages
Started by Dietmar Kuehl
Mon, 15 Apr 1996 16:35
How it auto_ptr currently defined?
Author: Dietmar Kuehl
Date: Mon, 15 Apr 1996 16:35
Date: Mon, 15 Apr 1996 16:35
46 lines
2681 bytes
2681 bytes
Hi,
gregor@netcom.com (Greg Colvin) recently posted a sample implementation
of 'auto_ptr' to this forum. With his implementation, the following
code would be well defined:
#include <auto_ptr>
auto_ptr<int> f(auto_ptr<int> ptr) { return ptr; }
int main()
{
auto_ptr<int> p1(new int(17));
auto_ptr<int> p2 = f(p1);
return *p1;
}
The key point I'm confused about, is that 'p1' holds a valid pointer
even after copying the pointer when creating the argument for the
function 'f()': The 'get()' member function of an 'auto_ptr' apparently
returns the correct value even if the pointer is not owned by the
'auto_ptr' (in the above case, the pointer is owned by 'p2' not by
'p1'). This might result in an 'auto_ptr' holding a stale pointer.
As I have no access to the changes made at the last committee meeting,
my question is this: Is the above code required to be well defined for
a standard conforming implementation? The thread where Greg Colvin
posted his version of 'auto_ptr' implies that the standard will require
the above code to be well defined but there was no explicit statement
about this. The above code resulted in undefined behavior according to
the April DWP (because the copy ctor of 'auto_ptr' was defined to
implicitly call 'release()').
Thank you very much for any responses
dk
--
dietmar.kuehl@uni-konstanz.de
http://www.informatik.uni-konstanz.de/~kuehl/
I am a realistic optimist - that's why I appear to be slightly pessimistic
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads