Re: [Cppunit-devel] Final answer: Exception::operator =() bug with VC++ (was :Partial answer: 2.3) W
Brought to you by:
blep
From: Baptiste L. <gai...@fr...> - 2001-10-08 12:36:44
|
Quoting Baptiste Lepilleur <bl...@cl...>: It does raise an interesting point about testing in C++. Exception::operator = () test failed, but NotEqualException::operator =() test worked!!! NotEqualException compared the values in the same method where the object were declared, while Exception called an helper method to do the job, passing reference to the Exception objects. That means that in the case of NotEqualException, the compiler knew the actual type of the object and resolved the virtual method call statically. That same test would have failed if the comparison was done in an helper function, since std::exception::operator =() implementation is bugged, leading to a buggy implementation of Exception::operator =(). So we had a passing test that should have failed, but did not because the compiler optimized away the resolution of the virtual call. Disturbing, isn't it ? That does raise interesting question about testing components that subclass third party class. Baptiste. > Went one step further in that quest... > > When the std::exception::operator =() call the destructor and the > constructor to do the 'copy', the constructor reset the virtual table > back > to std::exception > virtual table. Therefore, the previous affectation to > CppUnit::Exception > virtual table is lost, and all call to any virtual function of > std::exception (what() is among them) will lead to a call to the > std::exception implementatin instead of the most derived class > implementation. > > I beleive this is a MSVC++ STL bug (I'll tell you, that stuff is pure > black > magic ;-) ). Has anyone heard of it ? > > Well, anyway I'll go for the simplest thing that could possibly work > and > comment out the call to std::exception::operator =() in > CppUnit::Exception::operator =() (no data from the base class are use > anyway). But at least, now we know what is going wrong ! > > And we finaly got to see the green bar =) > > Thanks Phil, > Baptiste. --- Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html Language: English, French |