[Cppunit-devel] Explanation of ExceptionTest.testAssignment failure under VisualC++
Brought to you by:
blep
|
From: Niel C. <nr...@tr...> - 2001-10-22 09:01:55
|
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
|