dtor10.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 30 行

C
30
字号
#include "fail.h"

#if defined( __OS2__) && defined( _CPPUNWIND )

// Currently does not work on OS/2. With -xs, main() will register
// an exception handler that calls the destructor. When exit() is
// called, eventually the runtime calls DosExit. This will trigger
// XCPT_PROCESS_TERMINATE and the destructor will be run. Note that
// at that point the runtime has been shut down.

ALWAYS_PASS

#else

int ctor;

struct S {
    S() { ++ctor; }
    ~S() { fail(__LINE__); }
};

void main()
{
    S x;    // dtor should not be called!
    if( ctor != 1 ) fail(__LINE__);
    _PASS_EXIT;
}

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?