This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: dubious warning about unused object
> What I (wanted to) ask was if there is either a way to teach g++ the
> necessary knowledge (at least for me that seems like nearly
> undoable) or if there are other ways to get rid of the (in effect)
> false warnings.
And I was trying to tell you that the warnings are not false. Maybe
they are misworded, but they occur exactly in the cases when they
should occur, according to the documentation.
> The other question was if, in the presence of these not so uncommon
> techniques, it really makes sense that g++ tries to warn.
The compiler must warn in these cases, because that's how the -Wunused
option works. The questions is indeed whether users of g++ should pass
-Wunused to g++.
> I don't have access to the info docs just now, but I'm pretty sure
> that there is only __attribute__((unused)) but no
> __attribute__((used)). And the latter, or an attribute with the same
> effect, would be needed, as marking something unused when in fact is
> isn't is IMO confusing, to say the least.
You would have to write __attribute__((unused)), because that tells
the compiler not to emit the warning. Because it might cause confusion
to a reader, and because it is a C++ extension, you should wrap it in
a macro:
#ifdef __GNUC__
/* GCC gives unused-warnings for the semaphores, because they
are not referenced in the block where they are declared. The
attribute avoids the warning. */
#define SEMAPHORE(x) Semaphore __attribute__((unused)) x
#else
#define SEMAPHORE(x) Semaphore x
#endif
Regards,
Martin