Because of the unstability of floating points getting compared, I want to have at least a warning when using the comparison operator.
a == b; // Here the warning shall be thrown
inline bool operator==(const float& a, const float& b)
#warning "Usage of equal on floating point variables not allowed."
Your approach with custom operator overload wont work because C++ standard forbids custom operator overloads if all their arguments have builtin types.
If you're using GCC (or clang/MinGW) you can use
-Wfloat-equal to enable the warning about those comparsions. It's the closest thing you can get.
Even if it would be possible to completely disable them, it would be a bad idea. Sometimes they are useful and completely safe. Especially if there are no computations.
Consider following code:
float f = 0; if (a >= -1 && a <= 1) f = std::asin(a); // ... if (f != 0) std::cout << "asin = " << f << '\n'; else std::cout << "Out of range.\n";
It's completely safe even though it uses