关闭"'寄存器'存储类说明符已被弃用"警告

Jay*_*Jay 17 c++ xcode boost c++11 xcode5

随着最近我们得到了一堆在我们的代码库的新警告的Xcode 5.1更新-
这显然是与那铿锵的更新版本现在警告有关的用法register在C++ 11个源的存储类说明因为它一直不推荐使用C++ 11:

/Users/me/Documents/Sources/boost/boost/log/attributes/attribute_set.hpp:288:9: 'register' storage class specifier is deprecated
Run Code Online (Sandbox Code Playgroud)

现在我们要禁止对我们无法更改的代码发出警告 - 就像上面示例中的BOOST源代码一样.

我可以找到编译器标志来打开(-Wdeprecated-register)的警告,但有相反的禁用Xcode设置警告..?

Mik*_*our 25

通常,前置no-选项会将其关闭.因此,如果-Wdeprecated-register启用警告,-Wno-deprecated-register则应禁用它.

或者,在许多编译器上,您可以在代码中使用编译指示(或类似),在包含特定标头的同时禁用警告,同时为您自己的代码启用它们.它们是特定于编译器的; 对于Clang来说,它就像是

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-register"
#include "dodgy.hpp"
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)

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

  • 太棒了 - `-Wno-deprecated-register`就行了! (2认同)

R. *_*des 9

在这里取消警告是错误的工具.-isystem在包含不属于您的代码时使用该标志,它将不会在该代码中生成警告.


Ada*_*ski 6

这也有效

#if __cplusplus > 199711L
#define register      // Deprecated in C++11.
#endif  // #if __cplusplus > 199711L
Run Code Online (Sandbox Code Playgroud)