Open bluetarpmedia opened 8 months ago
If a base class has a public non-virtual destructor, then unique pointers to derived classes shouldn't be convertible (automatically or explicitly) to unique pointers of the base class.
That might be hard to enforce while using std::unique_ptr, so cpp2 should probably implements its own unique_ptr
Can Cppfront detect bugs where an object of derived class is deleted via a pointer to its base class that has a non-virtual destructor?
Here's some Cpp2 code demonstrating the problem:
This results in undefined behaviour. The
unique_ptr<Circle>
is converted tounique_ptr<Shape>
whencircle
is moved intoprint_position
, and when theunique_ptr
destructs it deletes theShape *
and only theShape
destructor is called.See Godbolt for an example with LeakSanitizer enabled.
Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code? The bug causes undefined behaviour but I've only found one CVE which treats this as a vulnerability:
Will your feature suggestion automate or eliminate X% of current C++ guidance literature? Yes, see: