Menu

#31 cppunittest fails under DevStudio

-- deleted --
closed-fixed
nobody
5
2001-12-13
2001-11-28
No

The cppunittest program fails if the Settings-
>C/C++/Code Generation option is changed to, "Debug
Multithreaded."

ExceptionTest::testAssignment() is failing
because "message" != "Unknown exception"

[e:\dev\isscommon\cppunit\examples\cppunittest]
Debug\CppUnitTestMain.exe
....F..................................................
................................
!!!FAILURES!!!
Test Results:
Run: 86 Failures: 1 Errors: 0
There was 1 failure:
1) test: ExceptionTest.testAssignment line: 103
e:\dev\isscommon\cppunit\examples\cppunittest\exception
test.cpp
expected: message
but was: Unknown exception

Somehow Exception::operator=() is corrupting the VTBL
(as shown below). If I remove
the, "SuperClass::operator= (other)" statement, the
test suite finishes successfully.

- this 0x0012fa14
+ [exception] {...}
+ exception {...}
+ UNKNOWNFILENAME {0x00302ca1 "<unknown>"}
UNKNOWNLINENUMBER 0xffffffff
+ m_message {0x00000000 ""}
m_lineNumber 0xffffffff
+ m_fileName {0x00302ca1 "<unknown>"}

A couple of observations.

1) It's not a good idea to sub-class a class
containing a a default constructor and not provide a
matching semantics. In the case of Exception{} class,
the Exception( m = dp1, l = dp2, ... ) acts like a
default constructor, but it's not really.

2) Since the code is not using implementation from
std::exception, its important to initialize its state.
See the stdexcept in MsDev directory for examples of
using sub-classed exceptions.

Beside these points, I believe there is some bad code
being generated by MsDev. I have followed this sub-
classed std::exception pattern and always avoided
calling the std::exception::operator=() method. I am
still scratching my head trying to figure out who's
not following the standards.

Regards,
David Dennerline
Atlanta, GA

Discussion

  • Alexey Malov

    Alexey Malov - 2001-12-06

    Logged In: YES
    user_id=394945

    Let me add some comments, about the bug.
    I believe MS's developers made this one.
    exception::operator= destroy old object and create new
    exception object in place of pointer this. Let me display
    asm code generated by VC++(6.0) for
    exception::operator =
    push ebp
    mov ebp,esp
    push ecx
    mov dword ptr [ebp-4],ecx
    mov eax,dword ptr [ebp-4]
    cmp eax,dword ptr [ebp+8]
    je exception::operator=+23h (1020d9b3)
    mov ecx,dword ptr [ebp-4]
    call exception::~exception (1020d9c0)
    mov ecx,dword ptr [ebp+8]
    push ecx
    mov ecx,dword ptr [ebp-4]
    call exception::exception (1020d900)
    mov eax,dword ptr [ebp-4]
    mov esp,ebp
    pop ebp
    ret 4

    what can be reassembled as:
    exception& exception::operator= (const exception& e)
    {
    if (this != &e)
    {
    this->~exception();
    new (this)(e);
    }
    return *this;
    }
    So, who does not follow the standards?
    (perhaps MS's developers believe in existance of virtual
    constructors :)

     
  • Baptiste Lepilleur

    • status: open --> closed
     
  • Baptiste Lepilleur

    Logged In: YES
    user_id=196852

    This bug was known (see the FAQ). It has been corrected
    since then (see the new FAQ).

     
  • Baptiste Lepilleur

    • status: closed --> closed-fixed
     

Log in to post a comment.