xcode 关闭“不推荐使用‘注册’存储类说明符”警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22422741/
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
Turning off the "'register' storage class specifier is deprecated" warning
提问by Jay
With the recent Xcode 5.1 update we're getting a bunch of new warnings in our code base -
this is apparently related to an updated version of clang that now warnsabout usages of the register
storage class specifier in C++11 sources as it has been deprecated with C++11:
随着最近的 Xcode 5.1 更新,我们在代码库中收到了一堆新警告——
这显然与更新版本的 clang 有关,该版本现在警告register
C++11 源代码中存储类说明符的使用,因为它一直是不推荐使用 C++11:
/Users/me/Documents/Sources/boost/boost/log/attributes/attribute_set.hpp:288:9: 'register' storage class specifier is deprecated
Now we'd like to suppress the warning for code that we cannot change - like the BOOST sources in the example above.
现在我们想抑制我们无法更改的代码的警告 - 就像上面示例中的 BOOST 源一样。
I could find the compiler flag to turn the warning on (-Wdeprecated-register
) but is there an opposite to disable the warning from the Xcode settings..?
我可以找到编译器标志来打开 ( -Wdeprecated-register
)警告,但是是否有相反的方法可以从 Xcode 设置中禁用警告..?
回答by Mike Seymour
In general, prepending no-
to an option turns it off. So if -Wdeprecated-register
enables the warning, then -Wno-deprecated-register
should disable it.
通常,no-
在选项前添加会将其关闭。所以如果-Wdeprecated-register
启用警告,那么-Wno-deprecated-register
应该禁用它。
Alternatively, on many compilers you can use pragmas (or similar) in your code, to disable warnings while including particular headers while leaving them enabled for your own code. They are compiler-specific; for Clang, it's something like
或者,在许多编译器上,您可以在代码中使用编译指示(或类似的)来禁用警告,同时包含特定的头文件,同时为您自己的代码启用它们。它们是特定于编译器的;对于 Clang,它就像
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-register"
#include "dodgy.hpp"
#pragma clang diagnostic pop
(For GCC, the pragmas are the same, only replacing clang
with GCC
. I don't know about any other compilers.)
(对于 GCC,编译指示是相同的,只是替换clang
为GCC
。我不知道任何其他编译器。)
回答by R. Martinho Fernandes
Suppressing the warning is the wrong tool here. Use the -isystem
flag when including code that is not yours and it will generate no warnings in that code.
在这里抑制警告是错误的工具。-isystem
在包含不属于您的代码时使用该标志,它不会在该代码中生成任何警告。
回答by Adamski
This also works
这也有效
#if __cplusplus > 199711L
#define register // Deprecated in C++11.
#endif // #if __cplusplus > 199711L