1

In a project, I use (a somewhat old version of) VTK, which produces a deprecated warning on 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]

I want to suppress that warning. What I tried so far was trying to use pragma directives along the culprit line:

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

#include <vtkSmartPointer.h>

#pragma GCC diagnostic pop

as recommended in an answer to How to suppress several warnings but not all of them coming from libraries?

This however does not work because the command does not recognize my option:

warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas]
#pragma GCC diagnostic ignored "-Wno-deprecated"

I wanted to be specific here with what type of warning I disable. An answer that gives me a less specific option would also be welcome, though. I tried with it "-Wall", but that doesn't work either (recognized but does not suppress).

Compiling the whole project with -Wno-deprecated suppresses the warning, and this is my fallback option, but not one I like to go with.

Emphasis of mine is that it works under Linux with GCC. I have no administration rights, can't change the VTK version here or the version of GCC (4.8.5).

Aziuth
  • 3,652
  • 3
  • 18
  • 36

1 Answers1

6

As state in comment:

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

#include <vtkSmartPointer.h>

#pragma GCC diagnostic pop

as #pragma GCC diagnostic ignored is to ignore specified warning flag, not substitute it.

As alternative you can use the flag reported in error message: [-Wcpp]:

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

#include <vtkSmartPointer.h>

#pragma GCC diagnostic pop
Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • Ah of course, I did a double negation. Now I feel somewhat stupid :). Thanks. – Aziuth Feb 07 '19 at 15:22
  • Sorry to bother you again, but right now I'm using exactly your code, that is the first block with ignoring -Wdeprecated, but it still produces the warning, and it does so exactly where I use those. And as I compile with -Wunknown-pragmas, I am also sure that it recognizes it. Do you happen to know other reasons why it not might work? – Aziuth Feb 08 '19 at 15:37
  • Can you try second snippet ? From [gcc/Diagnostic-Pragmas](https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html) *"Note that not all diagnostics are modifiable. Use -fdiagnostics-show-option to determine which diagnostics are controllable and which option controls them."* – Jarod42 Feb 08 '19 at 16:29
  • Doesn't work either. I also tried to remove -W and -Wall. The warning says " 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]" so I assume it is caused by -Wcpp, but again, the second snippet doesn't work either for some reason. – Aziuth Feb 08 '19 at 16:54
  • I did another test to be sure, in which I used `#pragma GCC diagnostic ignored` four times to remove -Wdeprecated, -Wcpp, -Wall and -W just to be sure, followed by a simple `#warning test`. It is triggered. My Makefile currently sets `CXXFLAGS = -std=c++11 -fdiagnostics-show-option -O2 -Wall -W -D_REENTRANT $(DEFINES)` (with DEFINES having only flags relevant to Qt and OpenGL) – Aziuth Feb 08 '19 at 16:59
  • 1
    The second suggestion will not work for g++: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80650 – Paul Childs Dec 06 '19 at 03:21