在一个项目中,我使用了(有点旧的)VTK,它在 GCC 上产生了不推荐使用的警告:
In file included from <path STL>/backward/strstream:51:0,
from <path VTK>/vtkIOStream.h:112,
from <path VTK>/vtkSystemIncludes.h:40,
from <path VTK>/vtkIndent.h:24,
from <path VTK>/vtkObjectBase.h:43,
from <path VTK>/vtkSmartPointerBase.h:26,
from <path VTK>/vtkSmartPointer.h:23,
from <some file in my project>
<path STL>/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
我想取消该警告。到目前为止,我尝试的是尝试沿着罪魁祸首行使用 pragma 指令:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wno-deprecated"
#include <vtkSmartPointer.h>
#pragma GCC diagnostic pop
作为对 How to suppress several warnings but not all of them coming from libraries? 的回答中的建议
但这不起作用,因为该命令无法识别我的选项:
warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas]
#pragma GCC diagnostic ignored "-Wno-deprecated"
我想在这里具体说明我禁用了哪种类型的警告。不过,也欢迎给我一个不太具体的选择的答案。我尝试使用它“-Wall”,但这也不起作用(识别但不抑制)。
使用 -Wno-deprecated 编译整个项目会抑制警告,这是我的后备选项,但不是我喜欢的选项。
我的重点是它可以在带有 GCC 的 Linux 下运行。我没有管理权限,无法更改此处的 VTK 版本或 GCC (4.8.5) 的版本。
最佳答案
如评论中所述:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
#include <vtkSmartPointer.h>
#pragma GCC diagnostic pop
因为 #pragma GCC diagnostic ignored
是忽略指定的警告标志,而不是替换它。
作为替代方案,您可以使用错误消息中报告的标志:[-Wcpp]
:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"
#include <vtkSmartPointer.h>
#pragma GCC diagnostic pop
关于c++ - 抑制单行的弃用警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54573282/