This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: check that a member function really operates on an object of the expected type


Erik <esigra@gmail.com> writes:

> Ian Lance Taylor skrev:
>> Erik <esigra@gmail.com> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]