Search code examples
c++gccpreprocessortranslation-unit

Does `#pragma GCC system_header` in a header file extend into another source or header file that includes it?


I need to disable all warnings inside a certain header file, and only that file only. The version of my compiler is g++-4.8. I have to use that compiler.

I looked up in the documentation of that compiler: g++-4.8 documentation support for System-Headers

It is written:

All warnings, other than those generated by #warning, are suppressed while GCC is processing a system header. Macros defined in a system header are immune to a few warnings wherever they are expanded.

There is also a directive, #pragma GCC system_header, which tells GCC to consider the rest of the current include file a system header, no matter where it was found. Code that comes before the #pragma in the file will not be affected. #pragma GCC system_header has no effect in the primary source file.

As English is my second language, it is not clear to me what that last sentence means.

I want to disable all the warnings in the entire single header file. This header file is included by many different C++ source code files *.cpp. This header file is also included by several other header files *.h, and those header files are also included by other files.

I want to know, if I put the #pragma GCC system_header in the single header file, will the effect of that #pragma directive be transferred into any file that includes that header? Because I do not want to disable any warnings in the files which include this header file. I want to disable warnings only for the structures which are defined in that header file only.

So in other words, does the effect of the #pragma GCC system_header applies to the entire translation unit (I don't want that) or only to that single header file like in a text editor?


Solution

  • It's just a reaffirmation of the main rule:

    There is also a directive, #pragma GCC system_header, which tells GCC to consider the rest of the current include file a system header

    That's it. Not other headers, not the file where you wrote #include.

    Just that file.