This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: About exit4.c


Even if it is not important It might be good to know about an other bug (probably) of the Microsoft compiler (which I
discovered trying to fix the problem with exit4.c):

The following code:
----------------------------------
#include <stdio.h>

class CheckDestructor
{
public:
 CheckDestructor() { printf("CheckDestructor"); };
 ~CheckDestructor() { printf("~CheckDestructor"); };
};

void f()
{
 CheckDestructor check;
 throw 1;
}

int main(int argc, char* argv[])
{
 //try
 //{
  f();
 //}
 //catch (...) {
 // printf("inside catch(...)\n");
 //}
 return 0;
}
----------------------------------

doens't call the destructor ~CheckDestructor().
But it does that if we put f() inside the try... catch block

The reason is that main() is called from crt0.c inside a __try ... __except block, which does not call the destructor.

This violates the Ansi C++ specification dec96: see
http://www.codeproject.com/cpp/ANSI-cpp-dec96/except.asp
where 15.2  Constructors and destructors                       [except.ctor].

Best Regards,
Marcello


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]