Clang 警告:值存储到“池”中在初始化期间永远不会被读取
- (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];
}
我不明白为什么这段代码会收到这样的警告,特别是当它与 Xcode 本身生成的 main.m 中的主函数几乎完全相同的结构时,它没有收到相同的警告:
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
- (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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于
while (YES)
语句。 Clang 认为这是一个永远无法跳出的无限循环,因此永远不会到达该块下面的代码。只需将其更改为以下内容(在块外部将
BOOL
变量设置为YES
)即可删除警告: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 toYES
outside of the block) will remove the warning: