GCC_WARN_SHADOW = YES 的单行异常?
我有这样的代码:
id error;
// a bunch of stuff, including using error
Finalization finalization = ^(int status) {
id error; // <--- Declaration shadows a local variable
// a bunch of stuff, using error
}
// a bunch of stuff, using error
我使用 GCC_WARN_SHADOW
因为这是我在代码中的每种情况下都想要的,除了这个。在这种情况下,它给了我一个我想要抑制的警告。
有没有一种方法可以抑制这个阴影警告,而无需关闭 GCC_WARN_SHADOW 或将内部错误重命名为其他内容?有什么方法来标记错误声明吗?
如果重要的话,我正在将 clang 与 Xcode 4 一起使用。
I have this code:
id error;
// a bunch of stuff, including using error
Finalization finalization = ^(int status) {
id error; // <--- Declaration shadows a local variable
// a bunch of stuff, using error
}
// a bunch of stuff, using error
I use GCC_WARN_SHADOW
because it's what I want in every case in my code except this one. In this case, it gives me a warning that I want to suppress.
Is there a way to suppress this one shadow warning without turning off GCC_WARN_SHADOW
or renaming the inner error to something else? Some way to mark that declaration of error?
I'm using clang with Xcode 4, if it matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,作为一个观点,在内部块中隐藏局部变量确实是很糟糕的业力(在函数中隐藏全局变量已经足够糟糕了)。现在,“错误”可以在一个函数中取两个不同的值,直到读你的代码的人弄清楚它为止,他们都会不断地敲头。我在现实生活中在开发应用程序的付费专业人士中看到过这个问题。我真的建议重命名内部错误变量。
回答你的问题,你可以 使用 GCC/clang 编译器编译指示来抑制警告。
First, as a matter of opinion, it's really bad karma to shadow a local variable within an inner block (its bad enough shadowing a global variable in a function). Now "error" can take two different values within a function, and until whomever is reading your code figures it out, they will bang their head quite incessantly. I have seen this issue in real life among paid professionals developing apps. I really suggest renaming the inner error variable.
Answering your question, you can use the GCC/clang compiler pragma to suppress a warning.