I have a big codebase and would like to find calls to specific standard or third-party library functions. If the names of the functions are not very unique and can be present also as names of variables and inside comments, it is hard to achieve using text search. Additional complication arises if the library function is overloaded, and only one of many overloads must be found. And it is preferably not to modify the library.
One of the ways I found is by deleting the function of interest, which will result in compilation errors in every place where it is called (and no errors in case of no such calls). For example, if one wants to find all calls to sqrt(float)
but skip all sqrt(double)
then a solution is as follows:
#include <cmath>
struct A {
friend float sqrt(float) noexcept = delete;
};
int main() {
sqrt( 1.0 ); // no error for double argument
sqrt( 1.0f ); // 'deleted function call' error in Clang and MSVC
}
The solution is actually based on not-standard ability to delete already declared function. It works in Clang and MSVC, but not in GCC. Demo: https://gcc.godbolt.org/z/9h3jGMjWc
Is there a standard way to achieve the same goal?