Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress GCC warnings

I have code:

#ifdef Q_OS_LINUX
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcomment"
#include "header.h"
#pragma GCC diagnostic pop
#endif

And I want to supress GCC warning messages related to header.h and all headers included from header.h. But I still have '-Wcomment' warnings related to headers included from header.h. How can I avoid that? Thanks

gcc 4.8.2

edit: The Warning I get looks like this:

/------ Set Analog Output for 8022/8026 --------- /Exp8K WORD CALLBACK AnalogOutHex_8K(DWORD dwBuf[], float fBuf[], warning: "/" within comment [-Wcomment] No other pragmas surely. -Wall doesn't work

like image 533
user3243625 Avatar asked Oct 29 '25 05:10

user3243625


2 Answers

If you can modify header.h, you could define it to be a system header using #pragma GCC system_header. Otherwise, you could add it to your gcc command line using -isystem.

All warnings, other than those generated by ‘#warning’ (see Diagnostics), are suppressed while GCC is processing a system header.

like image 76
mrks Avatar answered Oct 30 '25 19:10

mrks


GCC warnings that are emitted by the preprocessor cannot be suppressed with any pragma when compiling C++, they can only be suppressed by pragmas when compiling C. You're compiling as C++ (and shouldn't have tagged your question as C too). Here's a simple test case:

#pragma GCC diagnostic ignored "-Wcomment"
/* /* */

This warns in C++ mode, but not in C mode.

Given that pragmas just won't work, you should take some other approach. If you can modify the header, just change the comment. If you cannot change the header, you can mark the specific directory the header is in as a system header directory (use the -isystem command-line option).


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!