Topic: ~auto_ptr
Author: Marc Girod <girod@trshp.trs.ntc.nokia.com>
Date: 1997/02/13 Raw View
I check with three compilers, and two implementations of auto_ptr,
that the following code is dangerous:
class A;
struct B {
auto_ptr<A> a;
};
The compilers report either an error:
In method `auto_ptr<A>::~auto_ptr()': invalid use of undefined type `struct A'
or a warning not to take lightly:
Deleting a pointer to tentative class A; any destructor or operator
delete in the class will not be called.
This stems from the fact that the auto_ptr destructor is declared
inline, and that my compilers all insist in processing this
definition.
I wish they are all three wrong, and that the correct behaviour is to
ignore the issue until a point where the code is actually used (i.e.
at the point of declaring the first instance of B type, or of defining
a non-inline destructor for B).
At that point, of course, the A type should be fully defined.
Opinions?
(I am still looking in the draft myself...)
--
Marc Girod Kilo RD 4 Phone: +358-9-511 27703
Nokia Telecommunications P.O. Box 370 Fax: +358-9-511 27432
00045 NOKIA Group Finland marc.girod@ntc.nokia.com
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/02/13 Raw View
Marc Girod <girod@trshp.trs.ntc.nokia.com> writes:
>class A;
>struct B {
> auto_ptr<A> a;
>};
[...]
>In method `auto_ptr<A>::~auto_ptr()': invalid use of undefined type `struct A'
[...]
>Deleting a pointer to tentative class A; any destructor or operator
>delete in the class will not be called.
[...]
>I wish they are all three wrong, and that the correct behaviour is to
>ignore the issue until a point where the code is actually used (i.e.
>at the point of declaring the first instance of B type, or of defining
>a non-inline destructor for B).
>At that point, of course, the A type should be fully defined.
I believe all three compilers are wrong. Template member functions
should not be instantiated until they are used.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ 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
]
Author: Marc Girod <girod@trshp.trs.ntc.nokia.com>
Date: 1997/02/15 Raw View
>>>>> "me" == Marc Girod <girod@trshp.trs.ntc.nokia.com> writes:
me> I check with three compilers, and two implementations of auto_ptr,
me> that the following code is dangerous:
me> class A;
me> struct B {
B(A* a_): a(a-) {} // better like that...
me> auto_ptr<A> a;
me> };
void foo(A* a) {
B b(a);
}
I apologize. I made an error in narrowing my code. Two of my compliers
actually do what I wished.
Only, the one gives a warning instead of an error for cases like the
one above (with the additions). I still wonder why.
--
Marc Girod Kilo RD 4 Phone: +358-9-511 27703
Nokia Telecommunications P.O. Box 370 Fax: +358-9-511 27432
00045 NOKIA Group Finland marc.girod@ntc.nokia.com
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Marcelo Cantos <marcelo@mds.rmit.edu.au>
Date: 1997/02/16 Raw View
Fergus Henderson wrote:
>
> Marc Girod <girod@trshp.trs.ntc.nokia.com> writes:
>
> >class A;
> >struct B {
> > auto_ptr<A> a;
> >};
> [...]
> >In method `auto_ptr<A>::~auto_ptr()': invalid use of undefined type
> >`struct A'
> [...]
> >Deleting a pointer to tentative class A; any destructor or operator
> >delete in the class will not be called.
> [...]
> >I wish they are all three wrong, and that the correct behaviour is to
> >ignore the issue until a point where the code is actually used (i.e.
> >at the point of declaring the first instance of B type, or of defining
> >a non-inline destructor for B).
> >At that point, of course, the A type should be fully defined.
>
> I believe all three compilers are wrong. Template member functions
> should not be instantiated until they are used.
I would presume that in this case the error *did* appear when the
template was instantiated. Nothing in the original indicates
otherwise.
--
___________________________________________________________________
Marcelo Cantos, Research Assistant marcelo@mds.rmit.edu.au
Multimedia Database Systems Group Tel: +61-3-9282-2497
723 Swanston St, Carlton VIC 3053, Australia Fax: +61-3-9282-2490
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/02/17 Raw View
Marcelo Cantos <marcelo@mds.rmit.edu.au> writes:
>Fergus Henderson wrote:
>>
>> Marc Girod <girod@trshp.trs.ntc.nokia.com> writes:
>>
>> >class A;
>> >struct B {
>> > auto_ptr<A> a;
>> >};
>> [...]
>> >In method `auto_ptr<A>::~auto_ptr()': invalid use of undefined type
>> >`struct A'
>> [...]
>> >Deleting a pointer to tentative class A; any destructor or operator
>> >delete in the class will not be called.
>> [...]
>> >I wish they are all three wrong, and that the correct behaviour is to
>> >ignore the issue until a point where the code is actually used (i.e.
>> >at the point of declaring the first instance of B type, or of defining
>> >a non-inline destructor for B).
>> >At that point, of course, the A type should be fully defined.
>>
>> I believe all three compilers are wrong. Template member functions
>> should not be instantiated until they are used.
>
>I would presume that in this case the error *did* appear when the
>template was instantiated. Nothing in the original indicates
>otherwise.
Yes, I agree. From the original poster's description, my guess was that
(a) the compilers wrongly instantiated the template member functions
too early, and then (b) the error appeared when the template was
instantiated. And (a) implies that the compilers are broken, even
though I agree with you about (b).
(Note that the original poster has since posted a correction which
indicates that only one of the three compilers is broken in this way.)
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]