A more standard __attribute__((warning("msg"))

498 Views Asked by At

In my C++ library, I have a function that is still there, 1) for debugging 2) for small operations. The function is basically a very slow fallback of more efficient versions. (think of a loop of individual assignments vs memcpy for example)>

For this reason, I would like to emit a warning as soon the function is invoked instantiated directly or indirectly. Without a warning, it is not easy to test if the function is being invoked instantiated because the function might be called instantiated through several layers of template code.

I found that GCC's __attribute__((warning("slow function!"))) does the job quite well.

template<class T> 
__attribute__((warning("careful this fun is very slow, redesign your algorithm"))) 
void slow_function(T){...}

However, it is not standard or compatible with clang.

Is there a better alternative for this kind of compile-time warning?

It looks like there is a standard [[deprecated("msg")]] attribute that also does the job, the problem is that it is confusing because there is nothing deprecated about this function, it is there for convenience.

There is also, I found recently, a #pragma poison that might be applicable here, but I don't understand how it is used, besides the function is actually a member function of a template class, the examples do not consider this case. https://www.fluentcpp.com/2018/09/04/function-poisoning-in-cpp/

0

There are 0 best solutions below