[PATCH] D120258: [clangd] Add inlay hints for auto-typed parameters with one instantiation.

Trass3r via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 23 08:30:53 PST 2022


Trass3r added a comment.

In D120258#3340357 <https://reviews.llvm.org/D120258#3340357>, @sammccall wrote:

> I'll just suppress the hint here, ParamVarDecl::getLocation() appears to incorrectly point at the rparen and it's not obvious what we're hinting without a name in any case.

I guess `(auto : type)` would be ok and maybe helpful in some cases.
Though one could also argue it's not so important when you ignore the parameter anyway.

In D120258#3340390 <https://reviews.llvm.org/D120258#3340390>, @sammccall wrote:

> I haven't been able to reproduce this.
>
> I tried:
>
>   template <int> class Foo { void foo(); };
>   
>   template <int X>
>   void Foo<X>::foo() {
>       auto m = [this](auto x) {};
>       m(42);
>   }
>   
>   Foo<0> a;
>   // Foo<1> b;
>
> And I get no hints at all. (Presumably because we only traverse the primary template of `foo`, and Foo<X>::foo()::m::operator() is never instantiated, only Foo<0>::foo()::m::operator() is (with `int`).

In my case the lambda gets instantiated with different types depending on the template parameter.
Funny enough they disappear for me too if I change `auto` to `auto&&`.

Ah ok explicit instantiation made the difference:

  template <typename T>
  class Foo
  {
      void foo();
  };
  
  template <typename T>
  void Foo<T>::foo()
  {
      auto m = [](auto x) {}; // -> (auto x: short: int)
      m(T(42));
  }
  
  Foo<int> a;
  Foo<short> b;
  
  template class Foo<int>;
  template class Foo<short>;


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120258/new/

https://reviews.llvm.org/D120258



More information about the cfe-commits mailing list