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#import <Block.h>
8#import <stdio.h>
9#import <stdlib.h>
10
11// CONFIG C++
12
13int recovered = 0;
14
15
16
17int constructors = 0;
18int destructors = 0;
19
20#define CONST const
21
22class TestObject
23{
24public:
25	TestObject(CONST TestObject& inObj);
26	TestObject();
27	~TestObject();
28
29	TestObject& operator=(CONST TestObject& inObj);
30
31        void test(void);
32
33	int version() CONST { return _version; }
34private:
35	mutable int _version;
36};
37
38TestObject::TestObject(CONST TestObject& inObj)
39
40{
41        ++constructors;
42        _version = inObj._version;
43	//printf("%p (%d) -- TestObject(const TestObject&) called", this, _version);
44}
45
46
47TestObject::TestObject()
48{
49        _version = ++constructors;
50	//printf("%p (%d) -- TestObject() called\n", this, _version);
51}
52
53
54TestObject::~TestObject()
55{
56	//printf("%p -- ~TestObject() called\n", this);
57        ++destructors;
58}
59
60#if 1
61TestObject& TestObject::operator=(CONST TestObject& inObj)
62{
63	//printf("%p -- operator= called", this);
64        _version = inObj._version;
65	return *this;
66}
67#endif
68
69void TestObject::test(void)  {
70    void (^b)(void) = ^{ recovered = _version; };
71    void (^b2)(void) = Block_copy(b);
72    b2();
73    Block_release(b2);
74}
75
76
77
78void testRoutine() {
79    TestObject one;
80
81
82    one.test();
83}
84
85
86
87int main(int argc, char *argv[]) {
88    testRoutine();
89    if (recovered == 1) {
90        printf("%s: success\n", argv[0]);
91        exit(0);
92    }
93    printf("%s: *** didn't recover byref block variable\n", argv[0]);
94    exit(1);
95}
96