关闭"'register' storage class specifier is deprecated"警告

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

本文关键字:is deprecated 警告 specifier register 关闭 storage class      更新时间:2023-10-16

随着最近Xcode 5.1的更新,我们在代码库中得到了一堆新的警告-
这显然与clang的更新版本有关,clang现在警告在c++ 11源代码中使用register存储类说明符,因为它已在c++ 11中弃用:

/Users/me/Documents/Sources/boost/boost/log/attributes/attribute_set.hpp:288:9: 'register' storage class specifier is deprecated

现在我们想要对不能更改的代码取消警告——就像上面例子中的BOOST源一样。

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

一般来说,在选项前加上no-会关闭它。因此,如果-Wdeprecated-register启用了警告,那么-Wno-deprecated-register应该禁用它。

或者,在许多编译器上,您可以在代码中使用pragmas(或类似的)来禁用警告,同时包含特定的头文件,而将它们保留为您自己的代码启用。它们是特定于编译器的;对于Clang,它类似于

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-register"
#include "dodgy.hpp"
#pragma clang diagnostic pop

(对于GCC, pragmas是相同的,只是将clang替换为GCC。我不知道还有其他的编译器

在这里,抑制警告是错误的工具。当包含不是您的代码时,使用-isystem标志,它将不会在该代码中生成警告。

#if __cplusplus > 199711L
#define register      // Deprecated in C++11.
#endif  // #if __cplusplus > 199711L