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
13int constructors = 0;
14int destructors = 0;
15
16
17#define CONST const
18
19class TestObject
20{
21public:
22	TestObject(CONST TestObject& inObj);
23	TestObject();
24	~TestObject();
25
26	TestObject& operator=(CONST TestObject& inObj);
27
28	int version() CONST { return _version; }
29private:
30	mutable int _version;
31};
32
33TestObject::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
42TestObject::TestObject()
43{
44        _version = ++constructors;
45	//printf("%p (%d) -- TestObject() called\n", this, _version);
46}
47
48
49TestObject::~TestObject()
50{
51	//printf("%p -- ~TestObject() called\n", this);
52        ++destructors;
53}
54
55
56TestObject& TestObject::operator=(CONST TestObject& inObj)
57{
58	//printf("%p -- operator= called\n", this);
59        _version = inObj._version;
60	return *this;
61}
62
63
64
65void testRoutine() {
66    TestObject one;
67
68    void (^b)(void) = ^{ printf("my const copy of one is %d\n", one.version()); };
69}
70
71
72
73int 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