ctor30.c

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

C
42
字号
#include "fail.h"

struct S {
    int s;
    S( int );
    S( S const & );
    ~S();
};

int c;

S::S( int s ) : s(s) {
    ++c;
}
S::S( S const &s ) : s(s.s) {
    if( this == &s ) fail(__LINE__);
    ++c;
}
S::~S(){
    --c;
    if( c < 0 ) fail(__LINE__);
    s = -1;
}

void check( S const &x, unsigned line ) {
    if( c != 2 ) fail( line );
}

// 5.2.3 S(x) == (S)x
// 5.2.8 S -> S is an implicit cast
// 4 - equivalent to: S t(x); with result equal to 't'
int main() {
    S x(__LINE__);
    check( S(x), __LINE__ );
    if( c != 1 ) fail(__LINE__);
#if __WATCOM_REVISION__ >= 8
    check( (S)x, __LINE__ );
    if( c != 1 ) fail(__LINE__);
#endif
    _PASS;
}

⌨️ 快捷键说明

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