[PATCH] D157956: [clangd] don't add inlay hint for dependent type in structured binding

Vincent Hong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 15 02:23:09 PDT 2023


v1nh1shungry created this revision.
v1nh1shungry added a reviewer: nridge.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
v1nh1shungry requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Currently clangd will display useless inlay hint for dependent type in
structured binding, e.g.

  template <class T>
  void foobar(T arg) {
    auto [a/*: <dependent type>*/, b/*: <dependent type>*/] = arg;
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157956

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1333,6 +1333,11 @@
       // FIXME: It would be nice to show "T" as the hint.
       auto $var2[[var2]] = arg;
     }
+
+    template <typename T>
+    void bar(T arg) {
+      auto [a, b] = arg;
+    }
   )cpp");
 }
 
Index: clang-tools-extra/clangd/InlayHints.cpp
===================================================================
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -676,7 +676,8 @@
         // For structured bindings, print canonical types. This is important
         // because for bindings that use the tuple_element protocol, the
         // non-canonical types would be "tuple_element<I, A>::type".
-        if (auto Type = Binding->getType(); !Type.isNull())
+        if (auto Type = Binding->getType();
+            !Type.isNull() && !Type->isDependentType())
           addTypeHint(Binding->getLocation(), Type.getCanonicalType(),
                       /*Prefix=*/": ");
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157956.550220.patch
Type: text/x-patch
Size: 1198 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230815/769716e1/attachment.bin>


More information about the cfe-commits mailing list