delete shared_ptr object???
Rather disturbingly, the following code compiles (at least, with g++-3.3.2): #include "boost/shared_ptr.hpp" using namespace boost; class X {}; int main() { const shared_ptr<X> y; delete y; } Normally, when you compile code with delete applied to a non-pointer type, you get a compile-time error. What's going on here? TIA, Dan.
Dan Bikel wrote:
Rather disturbingly, the following code compiles (at least, with g++-3.3.2):
#include "boost/shared_ptr.hpp" using namespace boost; class X {}; int main() { const shared_ptr<X> y; delete y; }
Normally, when you compile code with delete applied to a non-pointer type, you get a compile-time error. What's going on here?
try this: struct X { operator X*(){ return this; } void operator delete (void *p){} }; int main(int, char*[]) { X x; delete x; }
TIA, Dan. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
pps
Dan Bikel wrote:
Rather disturbingly, the following code compiles (at least, with g++-3.3.2): #include "boost/shared_ptr.hpp" using namespace boost; class X {}; int main() { const shared_ptr<X> y; delete y; } Normally, when you compile code with delete applied to a non-pointer type, you get a compile-time error. What's going on here?
try this:
struct X { operator X*(){ return this; } void operator delete (void *p){} }; int main(int, char*[]) { X x; delete x; }
But shared_ptr isn't implicitly convertible to anything, for just that reason. -- Dave Abrahams Boost Consulting www.boost-consulting.com
Dan Bikel wrote:
Rather disturbingly, the following code compiles (at least, with g++-3.3.2): #include "boost/shared_ptr.hpp" using namespace boost; class X {}; int main() { const shared_ptr<X> y; delete y; }
Normally, when you compile code with delete applied to a non-pointer type, you get a compile-time error. What's going on here?
Seems like a g++ specific "feature". g++ allows delete on a member pointer for some reason. You should probably file a bug report against g++ 3.3. And I should probably add this test case to the regression tests. ;-)
participants (4)
-
Dan Bikel
-
David Abrahams
-
Peter Dimov
-
pps