1

Is there a way to suppress the warning message thrown by #warning from only a specific header file?

// file foo.hh
#ifndef FOO_HH
#define FOO_HH

#warning "Foo"

#endif // FOO_HH

// file main.cpp
#include "foo.hh"

int main()
{
   return 0;
}

The target compilers are GCC, Clang and Intel.

Marco Agnese
  • 349
  • 4
  • 15
  • 1
    Which compiler are you using? – Bathsheba Nov 28 '16 at 14:31
  • a small [mcve] with source & build command would help. – Jean-François Fabre Nov 28 '16 at 14:32
  • 1
    If you're using VS then dupe: http://stackoverflow.com/questions/7159348/disable-single-warning-error – EdChum Nov 28 '16 at 14:32
  • 1
    Possible duplicate of [How to disable GCC warnings for a few lines of code](http://stackoverflow.com/questions/3378560/how-to-disable-gcc-warnings-for-a-few-lines-of-code) – rocambille Nov 28 '16 at 14:33
  • 2
    There is no such pre-processor directive `#warning` defined by C++ standard (nor the C standard). When asking about non-standard compiler specific features, you should specify the compiler that you're targetting. – eerorika Nov 28 '16 at 14:36
  • There is no universal solution for multiple compilers, as warning suppression is inherently compiler-specific. You'll need to abstract the difference using macros or makefiles. – Cody Gray - on strike Nov 28 '16 at 15:10
  • I understand that there isn't any portable solution but I would like to know how to suppress them in that 3 specific cases. For example, supposing that I want to be compatible with only gcc, what is the way to do it? – Marco Agnese Nov 28 '16 at 15:21

1 Answers1

1

For GCC, you can suppress this using:

-Wno-cpp

Osama F Elias
  • 1,544
  • 1
  • 11
  • 10
  • I think this is a statement should be asked to GCC team. This is what is written in the man page of gcc: -Wno-cpp (C, Objective-C, C++, Objective-C++ and Fortran only) Suppress warning messages emitted by "#warning" directives. – Osama F Elias Mar 13 '17 at 13:46