[PATCH] D141226: [clangd] support expanding `decltype(expr)`

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 11 07:41:53 PST 2023


sammccall added inline comments.


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandDeducedType.cpp:139
 
-  // if it's a lambda expression, return an error message
-  if (isa<RecordType>(*DeducedType) &&
-      cast<RecordType>(*DeducedType)->getDecl()->isLambda()) {
-    return error("Could not expand type of lambda expression");
+  // we shouldn't replace a dependent type, e.g.
+  //   template <class T>
----------------
v1nh1shungry wrote:
> sammccall wrote:
> > why not? replacing this with `T` seems perfectly reasonable.
> > (The fact that we don't do this with `auto t = T{}` is just because we're hitting a limitation of clang's AST)
> I'd like it too. But the `printType()` would give out a `<dependent type>`. Though I haven't looked into this, would you mind giving some suggestions about it?
Ah, there are three subtly different concepts here:
 - is this type usefully printable? There are various reasons why it may not be, it can contain DependentTy, or a canonical template parameter (`<template-param-0-0>`), or a lambda.
 - is this type dependent in the language sense - an example is some type parameter `T`. This may or may not be usefully printable. (e.g. try `template<class X> std::vector<X> y;` and hover on y)
 - is this type specifically `DependentTy`, the placeholder dependent type which we have no information about. This is never usefully printable: prints as `<dependent type>`

As a heuristic, I'm happy with saying dependent types (in the language sense) are likely not to print usefully, so don't replace them. But the comment should say so (this is a heuristic for unprintable rather than an end in itself), and probably give examples.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141226



More information about the cfe-commits mailing list