Erik <esigra@xxxxxxxxx> writes: > Ian Lance Taylor skrev: >> Erik <esigra@xxxxxxxxx> writes: >> >>> This will throw std::bad_cast if the bug in question is encountered. Of >>> course it is not practically possible to add such an assertion to the >>> beginning of every method, but there should be a compiler flag to enable >>> this (in debug builds). Is there such a flag? Is there a feature request >>> for it? >>> >> >> even if there were such a flag, it would not work reliably for your example. > > It must work reliably for my example (and it does). Perhaps I misunderstood your example. It seemed that your class was holding a reference to an object which had been passed to delete. If that is what was happening, then my statement is correct. If you are instead holding a reference to a partially but not completely destroyed object, then I agree that dynamic_cast can work correctly. However, I personally don't see a sufficient reason to add yet another compiler option to support an arguably broken programming style. Ian