Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang warning: Value stored to 'pool' during its initialization is never read

- (void)main {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Warning goes here

    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
    while (YES) {
        NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init];
        [runLoop run];
        [subPool drain];
    }

    [pool drain];
}

I don't see why this code get such a warning, especially while it has almost exactly same structure as the main function in main.m generated by Xcode itself which does not get the same warning:

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}
like image 981
an0 Avatar asked Jun 09 '11 01:06

an0


1 Answers

I believe the issue is the while (YES) statement. Clang is seeing that as an endless loop that you'll never get outside of, so that the code below that block will never be reached.

Just changing it to the following (a BOOL variable set to YES outside of the block) will remove the warning:

int main (int argc, const char * argv[])
{

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

    NSRunLoop *runLoop = [NSRunLoop currentRunLoop];

    BOOL keepRunning = YES;

    while (keepRunning) {
        NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init];
        [runLoop run];
        [subPool drain];
    }

    [pool drain];

    return 0;
}
like image 189
NSGod Avatar answered Sep 30 '22 06:09

NSGod