Re: [Cppunit-devel] Explanation of ExceptionTest.testAssignment failure under VisualC++
Brought to you by:
blep
From: Baptiste L. <bl...@cl...> - 2001-10-24 18:13:33
|
Thanks. I came to similar conclusion a few weeks ago. See http://www.geocrawler.com/lists/3/SourceForge/6780/0/6778865/ for my comments on that bug. Baptiste. ----- Original Message ----- From: "Niel Clausen" <nr...@tr...> To: <cpp...@li...> Sent: Monday, October 22, 2001 9:56 AM Subject: [Cppunit-devel] Explanation of ExceptionTest.testAssignment failure under VisualC++ > Hi, > The cause of the failure isn't too hard to figure. To keep the description > simple, imagine that the vtable for an object is implemented by the _vtbl > data member. _vtbl points to the class specific vtable, which I'll call > Class::class_vtbl. > > 1. the line "other = e;" causes the other._vtbl to be overwritten with > exception::class_vtbl. > > 2. Hence when "other.what()" is called from within "checkIsSame", the > routine exception::what() is run, not CppUnit::Exception::what() as > expected. > > The problem seems to lie in the call to the compiler generated assignment > operator for exception (exception::operator =). Ignoring self assignment, > this routine first calls exception::~exception (destructor) followed by the > compiler generated constructor (I can't tell if this is a default > constructor or a copy constructor, only the latter really makes sense). The > constructor writes this->_vtbl (which of course, it should). In principle, > this algorithm for generating the assignment operator seems reasonable, > although not really what I'd expect. > > Note that the implementation of CppUnit::Exception::operator = is not needed > for this program, as C++ will do the "right thing" when assigning data > members (it calls each member's assignment operator). Interestingly, > commenting out CppUnit::Exception::operator = results in the same problem. > The compiler generated assignment operator for CppUnit::Exception first > calls exception::operator = (exactly the same as your original > implementation), and then performs the assignments for each data member. > Applying the same logic to CppUnit::Exception's copy constructor and > commenting that out also still gives the same result. For some reason, the > compiler generated exception::operator = is generated in a fundamentally > different way to the CppUnit::Exception derived class. > > Obviously there's something very odd going on here. > > > best regards, > > Niel Clausen. > > > /\ Manor Court Yard, High Wycombe > / \ /\ TRANSTECH Bucks, HP13 5RE, UK > -/ \ / \^--------- Voice +44 1494 464432 > \/ D S P Fax +44 1494 464472 > > nr...@tr... http://www.transtech-dsp.com > > > > _______________________________________________ > Cppunit-devel mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppunit-devel > |