A grep that drops lines starting with a return type also drops the call sites it was meant to find
Symptom#
To decide whether a C++ function has a caller, I ran grep -n -E "flush_all|wait_idle|..." src/.cpp | grep -v -E "^\S+:[0-9]+:\s(void|bool|size_t|static)" and read "no match" as "no caller". The function was called at src/proxy.cpp:696 as "size_t num_flushed = flush_all();", a line that starts with size_t, so the second grep removed it. The wrong claim "Proxy::flush_all has no caller" went into a skill file and a report until the user corrected it.
Cause#
The -v filter was meant to hide definitions (lines starting with a return type) but a call used as an initialiser starts with the same words. Searching only *.cpp also skipped the declaration in the header, which would have shown the name existed in a second place.
Fix#
Search all call sites without a type filter: grep -n "flush_all" src/.cpp src/.h, then tell definitions from calls by eye (the definition has "Class::name(" at column 0 and a body, a call ends in ");"). Only write "no caller" after listing every hit. Before writing "called once" or "runs once", also read the surrounding loop or parallel region at the call site.
Evidence#
Re-running grep -n "flush_all" src/.cpp src/.h printed src/proxy.h:373, src/proxy.cpp:696 and src/proxy.cpp:1181; line 696 sits in the OpenMP parallel region of Proxy::rdma_loop on the idle path (default quiet_time 1e-3 s).
Also found by searching
- grep says function has no callers but it is called
- grep -v filter removed the call site
- how to check a C++ function is unused
- claimed no caller wrong grep