2

I am using Xcode on OSX and the following code would not compile:

#import <Foundation/Foundation.h>

int main(int argc, const char *argv[]) {
    @autoreleasepool {
        NSLog(@"Hello world!");
    }
    return 0;
}

However if I remove the autoreleasepool block then the code works. I can also compile and run c and c++ code fine, but if I turn off ARC and write the autorelease the old fashion way:

#import <Foundation/Foundation.h>

int main(int argc, const char *argvc[]) {
    NSAutoreleasePool *pool = [[pool alloc] init];
    NSLog(@"Hello world!");
    [pool drain];
    return 0;
}

then the code also doesn't compile.

The full error log is shown here: http://pastebin.com/d9XYUCiG


Edit: I downgraded to XCode 5 from Xcode 5.1.1 I think and now it works.

1 Answers1

4

As @ahruss mentioned, there's a compiler bug (and you should open a radar on that, because the compiler shouldn't crash), but it's probably coming from the bug in your code:

NSAutoreleasePool *pool = [[pool alloc] init];

You meant:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Rob Napier
  • 286,113
  • 34
  • 456
  • 610