[Insight-developers] ExceptionObject assignment crash on MSVC

Niels Dekker niels-xtk at xs4all.nl
Sat May 31 08:47:30 EDT 2008


>> So I still think that the crash is caused by a bug in MSVC's
>> std::exception::operator=.  When debugging, it looks like it's
>> messing up the virtual table of itk::ExceptionObject.

FYI, the following little program already crashes on MSVC 2003:

  //////////////////////////////////////////////////
  #include <exception>

  class MyException : public std::exception
  {
  public:
    int NonVirtualFun()
    {
      return VirtualFun();
    }

    virtual int VirtualFun()
    {
     return 0;
    }
  };

  int main()
  {
    MyException a, b;
    a = b;  // Internally calls std::exception::operator=.
    return a.NonVirtualFun();  // MSVC 2003 crash!
  }
  //////////////////////////////////////////////////

So apparently std::exception::operator= should be avoided, on MSVC 2003. 
:-(  And I still think we should remove those two lines from 
itkExceptionObject.cxx:

  // Assign its superclass:
  static_cast<Superclass &>(*this) = orig;

Right?

Kind regards,

Niels



More information about the Insight-developers mailing list