xcode return 语句永远不会被执行警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26254857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Return statement will never be executed warning
提问by Injectios
I've recently come across with double return
statement (one of them was added by mistake) in our project and wondering why compiler
doesn't show a warning for that?!
我最近return
在我们的项目中遇到了双重声明(其中一个被错误添加),想知道为什么compiler
不显示警告?!
Ok, I added -Wunreachable-code
to other warning flags, but still no luck.
好的,我添加-Wunreachable-code
了其他警告标志,但仍然没有运气。
Got warning - with a code to execute after return
statement:
收到警告 - 在return
语句后执行代码:
Didn't get warning but still second return
statement will never be executed.
没有收到警告,但仍然return
永远不会执行第二条语句。
Even if I add something like this, still no warning
即使我添加了这样的东西,仍然没有警告
Is there extra warning flag for that, or compiler isn't smart enough?
是否有额外的警告标志,或者编译器不够智能?
采纳答案by fluidsonic
Good catch!
接得好!
-Wunreachable-code
does not report a warning and there is no other warning flag which would do.
Not even the Static Analyzer catches this mistake!
-Wunreachable-code
不报告警告,并且没有其他警告标志可以这样做。
甚至静态分析器都没有发现这个错误!
(Tested with XCode 6.1 GM 2)
(使用 XCode 6.1 GM 2 测试)
回答by Albert Renshaw
Wrap your code in pragma flags that will suppress that warning between the push and pop
将您的代码包装在 pragma 标志中,这将抑制 push 和 pop 之间的警告
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunreachable-code"
//Your code goes here
#pragma GCC diagnostic pop
回答by atulkhatri
Use -Wno-unreachable-code
for your file in Build Phases.
使用-Wno-unreachable-code
在构建阶段您的文件。
回答by Shaun Kelly
Try this...
尝试这个...
-(NSString*) makeSomeStringForMe {
NSString *someString = @"some string";
return someString;
}