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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:46:20  来源:igfitidea点击:

Turning off the "'register' storage class specifier is deprecated" warning

c++xcodec++11boostxcode5

提问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 registerstorage class specifier in C++11 sources as it has been deprecated with C++11:

随着最近的 Xcode 5.1 更新,我们在代码库中收到了一堆新警告——
这显然与更新版本的 clang 有关,该版本现在警告registerC++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-registerenables the warning, then -Wno-deprecated-registershould 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 clangwith GCC. I don't know about any other compilers.)

(对于 GCC,编译指示是相同的,只是替换clangGCC。我不知道任何其他编译器。)

回答by R. Martinho Fernandes

Suppressing the warning is the wrong tool here. Use the -isystemflag 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