How can I hide "defined but not used" warnings in GCC?

user34537 picture user34537 · Dec 22, 2008 · Viewed 90.3k times · Source

I have a bunch of compile time asserts, such as:

CASSERT(isTrue) or CASSERT2(isTrue, prefix_)

When compiling with GCC I get many warnings like 'prefix_LineNumber' defined but not used. Is there a way I can hide warnings for compile time asserts? I had no luck searching the GCC documentation. I thought I might have the var automatically used globally inside the same macro but I couldn't think of any way to do it.

Does anyone know of a way to hide that warning in GCC?

Answer

Arnaud picture Arnaud · Mar 4, 2009

Just saw this thread while searching for solutions to this problem. I post here for completeness the solution I found...

The GCC compiler flags that control unused warnings include:

-Wunused-function
-Wunused-label
-Wunused-parameter
-Wunused-value
-Wunused-variable
-Wunused (=all of the above)

Each of these has a corresponding negative form with "no-" inserted after the W which turns off the warning (in case it was turned on by -Wall, for example). Thus, in your case you should use

-Wno-unused-function

Of course this works for the whole code, not just compile-time asserts. For function-specific behaviour, have a look at Function attributes.