This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Disable warnings in unused header code?
- From: Sam Hocevar <sam at hocevar dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 5 Mar 2012 17:33:58 +0100
- Subject: Disable warnings in unused header code?
Is there a way to disable warnings for code that is not actually
used? Suppose I have this class:
template<typename T> struct Foo
{
inline Foo(T x) : x(x) {}
T x;
};
I would like to provide functions such as this in a public header:
static inline bool operator >=(Foo<unsigned> const &a, Foo<int> const &b)
{
return a.x >= b.x;
}
The user can then have "Foo<unsigned> a, b" and test "a >= b".
But they can also test "a >= 10" thanks to the implicit conversion
constructor.
My problem is that g++ emits a signed/unsigned mismatched comparison
warning with -W even when the function is not used. I do want the
warning to trigger when the function is actually used, so that the user
can knowingly decide to use, and maybe disable the warning.
I have tried using __attribute__((always_inline)), as well as several
combinations of optimisation flags, with no luck.
Do I have other options?
Regards,
--
Sam.