Topic: How it auto_ptr currently defined?


Author: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
Date: 1996/04/15
Raw View
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
]