Search code examples
c++gcccompiler-errorspragma

pragma GCC poison syntax for member function


In GCC (and clang) there is this option to poison a function:

#include <stdio.h>
#pragma GCC poison puts

int main() {
    puts("a");
}

What would be the syntax to poison a member function of a template class?

I tried the following options, I didn't even manage to make it work for the non-template class member.

#include <stdio.h>
#pragma GCC poison puts

struct A{
  bool operator==(A const& o){return true;}
};

#pragma GCC poison A::operator== //not working

template<class T>
struct B{
  bool operator==(B const& o){return true;}
};

#pragma GCC poison template<class T> B<T>::operator== //not working either


int main() {
    puts("a");
}

https://godbolt.org/z/rBEgjZ


Solution

  • I don't think there is such a syntax. The documentation says #pragma GCC poison is part of the preprocessor itself; indeed, the GCC documentation doesn't even mention it.

    That means it only works on things the preprocessor understands, i.e. identifier tokens. Something like A::operator== is four separate tokens: A, ::, operator, ==. Of these you could only poison A and operator; the preprocessor does not understand scopes or classes, let alone templates.