5

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?

Fedor
  • 17,146
  • 13
  • 40
  • 131
  • Are you aware of documentation generators like doxygen? – Yunnosch Dec 12 '21 at 07:54
  • Perhaps you could rename the function, temporarily. I put `xxxxx_` on the front, so that I can easily find it later. – Paul Sanders Dec 12 '21 at 08:10
  • 1
    I use visual assist to solve this issue on the daily, however it's not free and isn't always the most accurate. ClangD is another option I've found to be quite good in the past, it's free, cross-platform, more accurate and implemented for a number of editors. (I think it can so overload exclusive searching but don't quote me on that). – George Dec 12 '21 at 08:17
  • 1
    [clang cindex](https://libclang.readthedocs.io/en/latest/index.html) is quite good for doing this kind of thing, the documentation is fairly non-existant though – Alan Birtles Dec 12 '21 at 08:39

0 Answers0