https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71402
--- Comment #7 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
> Also, I'll add that the warning cannot be silenced with a #pragma, so I
> can't, for example, disable it for libresiprocate headers and leave it
> enabled for my code.
I think either Paolo or me fixed this in GCC 6.1. All warnings should be
affected by pragmas; otherwise it is a bug, please report it. Those bugs are
typically very easy to fix (you could even fix them yourself without any legal
paperwork involved).
In this case, I bet the warning call was:
warning ((TREE_CODE (decl) == FUNCTION_DECL)
? OPT_Wunused_function
: (TREE_READONLY (decl)
? OPT_Wunused_const_variable_
: OPT_Wunused_variable),
"%q+D defined but not used", decl);
and it should be:
warning_at (DECL_SOURCE_LOCATION (decl),
(TREE_CODE (decl) == FUNCTION_DECL)
? OPT_Wunused_function
: (TREE_READONLY (decl)
? OPT_Wunused_const_variable_
: OPT_Wunused_variable),
"%qD defined but not used", decl);
In your testcase, this works just fine:
#pragma GCC diagnostic ignored "-Wunused-variable"
class Foo
{
public:
static bool init();
};
static bool FooInit = Foo::init();
int main()
{
return 0;
}