public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/3946: auto_ptr_ref constructor allows dangerous conversion
@ 2002-07-04 10:05 bkoz
  0 siblings, 0 replies; 2+ messages in thread
From: bkoz @ 2002-07-04 10:05 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, kenny.simpson, nobody, pme, theonetruekenny

Synopsis: auto_ptr_ref constructor allows dangerous conversion

Responsible-Changed-From-To: unassigned->pme
Responsible-Changed-By: bkoz
Responsible-Changed-When: Thu Jul  4 10:05:24 2002
Responsible-Changed-Why:
    Yours...
State-Changed-From-To: open->closed
State-Changed-By: bkoz
State-Changed-When: Thu Jul  4 10:05:24 2002
State-Changed-Why:
    Fixed.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=3946


^ permalink raw reply	[flat|nested] 2+ messages in thread

* libstdc++/3946: auto_ptr_ref constructor allows dangerous conversion
@ 2001-08-05 15:26 theonetruekenny
  0 siblings, 0 replies; 2+ messages in thread
From: theonetruekenny @ 2001-08-05 15:26 UTC (permalink / raw)
  To: gcc-gnats; +Cc: kenny.simpson

>Number:         3946
>Category:       libstdc++
>Synopsis:       auto_ptr_ref constructor allows dangerous conversion
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 05 15:26:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Kenny Simpson
>Release:        online compiler (gcc version 3.0.1 20010626 (prerelease)) and 8-05-2001 CVS
>Organization:
>Environment:
online compiler
>Description:
auto_ptr_ref<T>'s constructor  allows conversion from  T*.
auto_ptr<U> has a member operator=( auto_ptr_ref<T>).
This effectively adds a member operator=(T*) to auto_ptr.

I believe this to be neither intentional, nor desirable.
>From http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#127
:

auto_ptr& operator=(auto_ptr_ref<X> r) throw()
	Effects: Calls reset(p.release()) for the auto_ptr p that r holds a 
	reference to.
	Returns: *this. 

This implies that auto_ptr_ref's must have an associated auto_ptr, but allowing an auto_ptr_ref to be constructed for any pointer defeats this.
>How-To-Repeat:
#include <memory>

int main()
{
  std::auto_ptr<int> a;
  int* b = new int(3);
  a = b; // this should NOT compile
  return 0;
}
>Fix:
on line 62 of include/bits/std_memory.h change:
   auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
to
   explicit auto_ptr_ref(_Tp1* __p) : _M_ptr(__p) {}
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-07-04 17:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-04 10:05 libstdc++/3946: auto_ptr_ref constructor allows dangerous conversion bkoz
  -- strict thread matches above, loose matches on Subject: below --
2001-08-05 15:26 theonetruekenny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).