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

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 12 23:39:59 PST 2023


zyn0217 wrote:

> If so, get its TemplateTypeParmDecl, find the template whose parameter it is, and see if the template has a getOnlyInstantiation.

Thanks for the suggestion! Admittedly, it looks neat and terse. However, I suspect it won't work with the present `TemplateTypeParm{Type,Decl}` models. `TemplateTypeParmDecl` per se is not tied to any `CXXRecordDecl` nor `FunctionDecl` that  the template parameter is declaring with. (For the most seemingly-relevant part, i.e. the `DeclContext` it records, is the scope that the template defines.)

> If so, find the argument type substituted for this template parameter, and replace the template parameter with this type.

I was thinking this way before getting into the details :-). Soon I realized that we had to tackle synthesized types e.g.
```cpp
template <template <class, int> typename C, typename D, int E>
void work() {
  C<D, E> complicated_type;
  // ^ Shall we perform the type substitution once again? ;)
}
```




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


More information about the cfe-commits mailing list