抑制单行的已弃用警告

Azi*_*uth 1 c++ gcc

在一个项目中,我使用(有点旧的版本)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]
Run Code Online (Sandbox Code Playgroud)

我想压制那个警告。到目前为止,我尝试的是尝试沿罪魁祸首线使用 pragma 指令:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wno-deprecated"

#include <vtkSmartPointer.h>

#pragma GCC diagnostic pop
Run Code Online (Sandbox Code Playgroud)

正如在如何抑制几个警告但并非所有警告都来自库?

但是,这不起作用,因为该命令无法识别我的选项:

warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas]
#pragma GCC diagnostic ignored "-Wno-deprecated"
Run Code Online (Sandbox Code Playgroud)

我想在这里具体说明我禁用了哪种类型的警告。不过,也欢迎给我一个不太具体的选项的答案。我尝试使用它“-Wall”,但这也不起作用(已识别但不抑制)。

使用 -Wno-deprecated 编译整个项目会抑制警告,这是我的后备选项,但不是我喜欢的选项。

我的重点是它在带有 GCC 的 Linux 下工作。我没有管理权限,不能在这里更改 VTK 版本或 GCC (4.8.5) 的版本。

Jar*_*d42 5

正如评论中的状态:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"

#include <vtkSmartPointer.h>

#pragma GCC diagnostic pop
Run Code Online (Sandbox Code Playgroud)

因为#pragma GCC diagnostic ignored忽略指定的警告标志,而不是替代它。

作为替代方案,您可以使用错误消息中报告的标志[-Wcpp]::

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"

#include <vtkSmartPointer.h>

#pragma GCC diagnostic pop
Run Code Online (Sandbox Code Playgroud)