1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6
7 #include <stdio.h>
8 #include <Block.h>
9
10 // CONFIG C++ rdar://6243400,rdar://6289367
11
12
13 int constructors = 0;
14 int destructors = 0;
15
16
17 #define CONST const
18
19 class TestObject
20 {
21 public:
22 TestObject(CONST TestObject& inObj);
23 TestObject();
24 ~TestObject();
25
26 TestObject& operator=(CONST TestObject& inObj);
27
version()28 int version() CONST { return _version; }
29 private:
30 mutable int _version;
31 };
32
TestObject(CONST TestObject & inObj)33 TestObject::TestObject(CONST TestObject& inObj)
34
35 {
36 ++constructors;
37 _version = inObj._version;
38 //printf("%p (%d) -- TestObject(const TestObject&) called\n", this, _version);
39 }
40
41
TestObject()42 TestObject::TestObject()
43 {
44 _version = ++constructors;
45 //printf("%p (%d) -- TestObject() called\n", this, _version);
46 }
47
48
~TestObject()49 TestObject::~TestObject()
50 {
51 //printf("%p -- ~TestObject() called\n", this);
52 ++destructors;
53 }
54
55
56 TestObject& TestObject::operator=(CONST TestObject& inObj)
57 {
58 //printf("%p -- operator= called\n", this);
59 _version = inObj._version;
60 return *this;
61 }
62
63
64
testRoutine()65 void testRoutine() {
66 TestObject one;
67
68 void (^b)(void) = ^{ printf("my const copy of one is %d\n", one.version()); };
69 }
70
71
72
main(int argc,char * argv[])73 int main(int argc, char *argv[]) {
74 testRoutine();
75 if (constructors == 0) {
76 printf("No copy constructors!!!\n");
77 return 1;
78 }
79 if (constructors != destructors) {
80 printf("%d constructors but only %d destructors\n", constructors, destructors);
81 return 1;
82 }
83 printf("%s:success\n", argv[0]);
84 return 0;
85 }
86