[PATCH] D102148: [clangd] Type hints for variables with 'auto' type
Nathan Ridge via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 6 19:05:55 PDT 2021
nridge added inline comments.
================
Comment at: clang-tools-extra/clangd/InlayHints.cpp:81
+ if (auto *AT = D->getType()->getContainedAutoType()) {
+ if (!D->getType()->isDependentType()) {
+ addInlayHint(D->getLocation(), InlayHintKind::TypeHint,
----------------
nridge wrote:
> sammccall wrote:
> > why this check vs checking whether AT is deduced?
> > (thus fixing the dependent `T` testcase)
> > At first I assumed this was the usual "AutoType in AST doesn't store the deduced type" problem, but shouldn't it work properly if we're starting at the variable type?
> Not sure if I'm understanding the suggestion correctly, but if I make the condition `AT->isDeduced()`, I get an unwanted `auto` hint for `var1` in `TypeHints.DependentType` as well (and moreover, the hint for `var2` is also `auto` instead of the desired `T`).
> and moreover, the hint for `var2` is also `auto` instead of the desired `T`
I've looked into this a bit further, and it looks to me like the `T` isn't even stored in the AST. The type is just recorded as `auto` (and that's what e.g. hover shows too).
I suspect the `auto` is only filled in **after** instantiation (i.e. once the initializer expression has a concrete type).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102148/new/
https://reviews.llvm.org/D102148
More information about the cfe-commits
mailing list