https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116018

--- Comment #4 from Frank Heckenbach <[email protected]> ---
I had to put the directive before the declaration and ignore redundant-decls
warnings (and in C++ use decltype instead of typedef):

#include <stdlib.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
[[gnu::unavailable ("rand should not be used because  ...reason...")]] extern
decltype (rand) rand;
#pragma GCC diagnostic pop

int main ()
{
  rand ();
}

This seems to work for this case. It doesn't seem to work with other
identifiers I'd like to make unavailable e.g. "toupper". The difference seems
to be that poison works at the time of definition and direct usage whereas
unavailable also affects indirect usage, e.g. by template instantiations
(apparently some std::format functions use it internally).

So this issue is not so urgent to me now because I can continue to poison
"toupper" as there is no conflict with any library (yet). But I'd still suggest
adding a less aggressive form of "poison" as suggested.

Reply via email to