1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LLVM_LICENSE_HEADER@ 5 */ 6 7// TEST_CFLAGS -framework Foundation 8 9#import <objc/objc-auto.h> 10#import <Foundation/Foundation.h> 11#import <Block.h> 12#import "test.h" 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 0 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) = [b copy]; 70 b2(); 71} 72 73void testRoutine() { 74 TestObject one; 75 76 one.test(); 77} 78 79 80 81int main() { 82 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 83 testRoutine(); 84 objc_collect(OBJC_EXHAUSTIVE_COLLECTION|OBJC_WAIT_UNTIL_DONE); 85 [pool drain]; 86 87 if (recovered != 1) { 88 fail("didn't recover byref block variable"); 89 } 90 91 succeed(__FILE__); 92} 93