[PATCH] D128204: [clangd] Add fix-it for inserting IWYU pragma: keep

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 22 02:24:33 PDT 2022

njames93 added a comment.

In D128204#3600973 <https://reviews.llvm.org/D128204#3600973>, @kadircet wrote:

>> One of the main issues I have is due to templates not being instantiated which can result in symbols that are actually used not being picked up as the template instantiation that uses them isn't actually instantiated.
> I guess you're talking about having the template pattern in the main file, but all the instantiations are in dependents of the code. My mental model was around making the dependents have the include for the type, instead of having it in the file providing the template pattern (header).  Does that make sense?
> This kind of breaks down when there's actually some types used by all the instantiations, as you'd want them to be included by the header. But I think we should be able to diagnose these cases, as usage of this type should be non-dependent (at least in the cases I can think of), so this sounds like a bug/improvement.

A specific example i encountered is `clang/Tooling/DiagnosticsYaml.h` Which defines template specializations for inputting/outputting yaml io. That file must be included if you ever want to emit diagnostics as YAML, but the typical use case is to just use the operator<< on a yaml stream. This function internally will use those specializations, but as clangd doesn't look into the function calls and expand all those instantiations, they are treated as being unused(There's many bugs already related to this) and as such the header is marked as being unused.

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list