llvm-project
84 строки · 1.6 Кб
1//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
6#include <stdio.h>7#include <Block.h>8
9// CONFIG C++ rdar://6243400,rdar://6289367
10
11
12int constructors = 0;13int destructors = 0;14
15
16#define CONST const17
18class TestObject
19{
20public:21TestObject(CONST TestObject& inObj);22TestObject();23~TestObject();24
25TestObject& operator=(CONST TestObject& inObj);26
27int version() CONST { return _version; }28private:29mutable int _version;30};31
32TestObject::TestObject(CONST TestObject& inObj)33
34{
35++constructors;36_version = inObj._version;37//printf("%p (%d) -- TestObject(const TestObject&) called\n", this, _version);38}
39
40
41TestObject::TestObject()42{
43_version = ++constructors;44//printf("%p (%d) -- TestObject() called\n", this, _version);45}
46
47
48TestObject::~TestObject()49{
50//printf("%p -- ~TestObject() called\n", this);51++destructors;52}
53
54
55TestObject& TestObject::operator=(CONST TestObject& inObj)56{
57//printf("%p -- operator= called\n", this);58_version = inObj._version;59return *this;60}
61
62
63
64void testRoutine() {65TestObject one;66
67void (^b)(void) = ^{ printf("my const copy of one is %d\n", one.version()); };68}
69
70
71
72int main(int argc, char *argv[]) {73testRoutine();74if (constructors == 0) {75printf("No copy constructors!!!\n");76return 1;77}78if (constructors != destructors) {79printf("%d constructors but only %d destructors\n", constructors, destructors);80return 1;81}82printf("%s:success\n", argv[0]);83return 0;84}
85