[clang-tools-extra] [clangd] Resolve the dependent type from its single instantiation. Take 1 (PR #71279)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 12 23:05:23 PST 2023


https://github.com/HighCommander4 commented:

Thanks very much for looking at this!

I'm wondering if it's possible to achieve the same results (and also solve your `CXXUnresolvedConstructExpr` issue) with a more targeted change that may also be simpler.

While I haven't experimented with this approach to verify that it's feasible, here's what I had in mind:

 * In a suitable place where we simplify dependent types (I'm thinking around [here](https://searchfox.org/mozilla-central/rev/fe8b30e982c86d26ccf1f14d825c0de870b91f27/build/clang-plugin/mozsearch-plugin/from-clangd/HeuristicResolver.cpp#59)), check if the type is a `TemplateTypeParmType`.
 * If so, get its `TemplateTypeParmDecl`, find the template whose parameter it is, and see if the template has a `getOnlyInstantiation`. If so, find the argument type substituted for this template parameter, and replace the template parameter with this type.

As a bonus, the "default argument heuristic" discussed [here](https://github.com/clangd/clangd/discussions/1056) could be implemented in the same place. (Even if the template doesn't have exactly one instantiation, if the template parameter has a default argument, replace the template parameter with the default argument.)

I _think_ this should handle the cases in this testcase without the need for any Visitor, though it's definitely possible I'm overlooking something.

https://github.com/llvm/llvm-project/pull/71279


More information about the cfe-commits mailing list