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 | |
12 | int constructors = 0; |
13 | int destructors = 0; |
14 | |
15 | |
16 | #define CONST const |
17 | |
18 | class TestObject |
19 | { |
20 | public: |
21 | TestObject(CONST TestObject& inObj); |
22 | TestObject(); |
23 | ~TestObject(); |
24 | |
25 | TestObject& operator=(CONST TestObject& inObj); |
26 | |
27 | int version() CONST { return _version; } |
28 | private: |
29 | mutable int _version; |
30 | }; |
31 | |
32 | TestObject::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 | |
41 | TestObject::TestObject() |
42 | { |
43 | _version = ++constructors; |
44 | //printf("%p (%d) -- TestObject() called\n", this, _version); |
45 | } |
46 | |
47 | |
48 | TestObject::~TestObject() |
49 | { |
50 | //printf("%p -- ~TestObject() called\n", this); |
51 | ++destructors; |
52 | } |
53 | |
54 | |
55 | TestObject& TestObject::operator=(CONST TestObject& inObj) |
56 | { |
57 | //printf("%p -- operator= called\n", this); |
58 | _version = inObj._version; |
59 | return *this; |
60 | } |
61 | |
62 | |
63 | |
64 | void testRoutine() { |
65 | TestObject one; |
66 | |
67 | void (^b)(void) = ^{ printf(format: "my const copy of one is %d\n" , one.version()); }; |
68 | } |
69 | |
70 | |
71 | |
72 | int main(int argc, char *argv[]) { |
73 | testRoutine(); |
74 | if (constructors == 0) { |
75 | printf(format: "No copy constructors!!!\n" ); |
76 | return 1; |
77 | } |
78 | if (constructors != destructors) { |
79 | printf(format: "%d constructors but only %d destructors\n" , constructors, destructors); |
80 | return 1; |
81 | } |
82 | printf(format: "%s:success\n" , argv[0]); |
83 | return 0; |
84 | } |
85 | |