-2

I have a project which uses tinyxml2 library. I have a very long list of compiler options where the -Werror=zero-as-null-pointer-constant is listed among others. So, everywhere I include the tinyxml2.h I have the errors: 0 used as null pointer, however my code does not have such problems. Is there a way to disable some compiler options for the includes because I can't control them?

P.S. If it is impossible to do via gcc/clang options, perhaps it is possible to do via cmake? Or I would like to know both ways if they are exist.

VP.
  • 15,509
  • 17
  • 91
  • 161
  • 2
    Both GCC and Clang have *pragmas* to (possibly temporarily) disable warnings. [The GCC online documentation](https://gcc.gnu.org/onlinedocs/) might be a good place to start looking. – Some programmer dude Sep 24 '17 at 08:42
  • 3
    ... And if you don't want to litter all of *your* code with pragmas, create a header that simply includes `tinyxml2.h` and include *that* in your source. Then you can add support for more compilers if needed, all at a single place. – StoryTeller - Unslander Monica Sep 24 '17 at 08:43

2 Answers2

2

You could use suppression pragmas.

This is supported for GCC and VC++ compilers, and it looks like this:

#pragma warning(push)
#pragma warning(disable : 4244)
#pragma warning(disable : 4127)
#pragma warning(disable : 4512)
#include <boost/python.hpp>
#pragma warning(pop)

Here are the detailed specs:

Daniel Trugman
  • 8,186
  • 20
  • 41
1

You can mark the include directory for tinyxml2 as a system include directory, which will suppress the warnings coming from there.

With GCC/Clang, you can do this with -isystem instead of -I, or with the keyword SYSTEM when you add include directories in CMake.

For instance

include_directories(SYSTEM ${SOME_INCLUDE_DIR})

or, better,

target_include_directories(myExe SYSTEM ${SOME_INCLUDE_DIR}) 
oLen
  • 5,177
  • 1
  • 32
  • 48
  • To be clear, warnings being suppressed is one of the effects of marking a directory as a system include directory, but not the only one. –  Sep 24 '17 at 08:54