[PATCH] D138300: [clangd] Support type hints for `decltype(expr)`
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 16 19:19:14 PST 2022
nridge added inline comments.
================
Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:1155
+ // FIXME: Nice to show `: int &`
+ decltype((i)) $a[[a]] = i;
+ )cpp",
----------------
v1nh1shungry wrote:
> The only concern I have is how to deal with this situation.
>
> When I wrote this patch I thought maybe I could remove the `&` and figure out the underlying type of `decltype(0)` recursively and then add the `&` back. But at that time I couldn't find a way to get the referenced type or the pointee type.
This is a problem we already have for `auto`. For example, if you write:
```
auto i = decltype(0)();
```
the type hint for the `auto` is `decltype(0)`.
The reason is that we are printing the type with `TypeHintPolicy`, which has `PrintCanonicalTypes=false` (the default). This means the type is printed without "type sugar" (e.g. decltype, typedefs) being replaced with their "underlying type".
We could alternatively print it with `PrintCanonicalTypes=true`, which would make the hint given in this case better, but it would make other cases worse (e.g. replacing `std::string` with `std::basic_string<...>`).
For the purposes of this patch, I think it's fine to just live with whatever type is printed with the current printing policy.
If we want to make improvements in this area, we can do that in a separate patch, and in a way that affects both `auto` and `decltype(expr)`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138300/new/
https://reviews.llvm.org/D138300
More information about the cfe-commits
mailing list