a question about scoped_ptr and checked_delete

As I understand, checked_delete is being used by scoped_ptr to prevent deletion of incomplete type. However, this very simple program is accepted by MSVC6, MSVC71 and MinGW (GCC) 3.4.4, even though implicit destructor of A is deleting incomplete class A::impl . Only one compiler of these that I could test (Comeau 4.3.3) throws compilation error. Could we do better? I know, there are simple workaround - declare destructor in class A or use shared_ptr . But as we know, workarounds in user code to generate compilation error (not suppress them) are rare thing. B. #include <boost/scoped_ptr.hpp> struct A { struct impl; boost::scoped_ptr<impl> impl_; A(); }; int main() { A a; } struct A::impl {}; A::A() : impl_(new impl()) {}

Bronek Kozicki wrote:
As I understand, checked_delete is being used by scoped_ptr to prevent deletion of incomplete type. However, this very simple program is accepted by MSVC6, MSVC71 and MinGW (GCC) 3.4.4, even though implicit destructor of A is deleting incomplete class A::impl.
Apparently, ~A is being implicitly generated at the end of the translation unit, where A::impl is complete. If you add ~impl that prints something, you'll see that it is actually being called. If you remove the definition of A::impl, the program will no longer compile. At least under MSVC 7.1.
participants (2)
-
Bronek Kozicki
-
Peter Dimov