<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/107625>107625</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] misc-include-header Not directly included & not directly used issue
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mnorfolk03
      </td>
    </tr>
</table>

<pre>
    The misc-include-header check for clang tidy is not properly identifying which header provides a particular function.

I believe this likely due to the function having an overload defined in different files.


Reproducibility:


```cpp
// clang_tidy_issue.cpp
#include "clang_tidy_issue.h"
#include <unistd.h>

int main() {
    time("hello", [] { sleep(1); });
}

```

```cpp
// clang_tidy_issue.h
#pragma once
#include <chrono>
#include <functional>
#include <string>

inline size_t time(const std::string& prefix, std::function<void()> func) {
    auto thread_local timer_start = std::chrono::high_resolution_clock::now();
    func();
    auto thread_local timer_stop = std::chrono::high_resolution_clock::now();
 const size_t dur = std::chrono::duration_cast<std::chrono::nanoseconds>(timer_stop - timer_start).count();
    printf("[%s] took %ld nanos", prefix.c_str(), dur);
    return dur;
}
```

```
$ clang-tidy-18 --checks=misc-include-cleaner clang_tidy_issue.cpp
...
2 warnings generated.
/scratch/mnorfolk/Code/Clion/CppTesting/clang_tidy/clang_tidy_issue.cpp:5:1: warning: included header clang_tidy_issue.h is not used directly [misc-include-cleaner]
    5 | #include "clang_tidy_issue.h"
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    6 | #include <unistd.h>
/scratch/mnorfolk/Code/Clion/CppTesting/clang_tidy/clang_tidy_issue.cpp:9:5: warning: no header providing "time" is directly included [misc-include-cleaner]
    6 | #include <unistd.h>
    7 | 
    8 | int main() {
    9 |     time("hello", [] { sleep(1); });
      | ^
```

---

In this example, I believe it is trying to find the `time_t time( time_t *arg );` function defined in `<time.h>`
https://en.cppreference.com/w/c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