1/*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LLVM_LICENSE_HEADER@
5 */
6
7#import <Foundation/Foundation.h>
8
9static int globalCount = 0;
10
11@interface Foo : NSObject {
12    int ivarCount;
13}
14
15- (void) incrementCount;
16@end
17
18@implementation Foo
19- (void) incrementCount
20{
21    int oldValue = ivarCount;
22
23    void (^incrementBlock)()  = ^(){ivarCount++;};
24    incrementBlock();
25    if( (oldValue+1) != ivarCount )
26        NSLog(@"Hey, man.  ivar was not incremented as expected.  %d %d", oldValue, ivarCount);
27    }
28@end
29
30
31int main (int argc, const char * argv[]) {
32    int localCount = 0;
33
34    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
35
36    [[[[Foo alloc] init] autorelease] incrementCount];
37
38    void (^incrementLocal)() = ^(){
39        |localCount| // comment this out for an exciting compilation error on the next line (that is correct)
40        localCount++;
41    };
42
43    incrementLocal();
44    if( localCount != 1 )
45        NSLog(@"Hey, man.  localCount was not incremented as expected.  %d", localCount);
46
47    void (^incrementGlobal)() = ^() {
48        |globalCount| // this should not be necessary
49        globalCount++;
50    };
51    incrementGlobal();
52    if( globalCount != 1 )
53        NSLog(@"Hey, man.  globalCount was not incremented as expected.  %d", globalCount);
54
55    [pool drain];
56    return 0;
57}
58