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