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

    <tr>
        <th>Summary</th>
        <td>
            Apply spelling strategies to IWYU specified spellings
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-include-cleaner
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          sam-mccall
      </td>
    </tr>
</table>

<pre>
    Given a library like gtest that marks internal headers:

```
// gmock-matchers.h
// IWYU pragma: private: include "gtest/gtest.h"
```

These are considered verbatim spellings, and this provider is satisfied exactly if the `#include` directive is spelled this way.

Now when this is imported into a codebase with a specific include spelling style, it may be included differently, and include-cleaner doesn't recognize it:
```
// my/test.cc
#include "third_party/gtest/gtest.h" // unused
int x = some_internal_gtest_thing; // missing include: include gtest/gtest.h
```

In practice, the suggested fixes "work" on a technical level - the include path does satisfy the gtest/gtest.h spelling. This is because it's the style used by gtest headers to include each other, so it has to be set up to work.

However, it's incorrect on a style level: per codebase conventions, the include is spelled correctly and used, and gtest/gtest.h should not be included.

---

One possible fix, reusing existing spelling strategy infra

 - assume that a custom spelling strategy takes precedence over verbatim spelling (currently it's the reverse)
 - when computing spelling, do header search to resolve the verbatim spelling, and feed the result into the custom speller
 - if the custom speller produces a result, use that, otherwise use the verbatim spelling

This means doing IO (a bunch of stats) each time we try to spell a verbatim header.
This may be affordable, either we're only computing a few (actual edits) or we're doing a lot (clangd indexing) but expect relatively few distinct verbatim paths and so caching amortizes the cost.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0Vk1v4zYQ_TXyZWDDofwRH3zY7SLtXrqXLYqeghE5lthQpMAZ2dH--oKUFNtJChi2ZIozb-a9eRQy29oTHYvt10KpFzQ2apJCqWL7bYG9NCEeGdtlqzU6t6iCGY6_2zN5QHC2ihgHcPaFoBZiAWlQoMX4wmC9UP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