[PATCH] D119537: [clangd] Treat 'auto' params as deduced if there's a single instantiation.

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 14 01:13:26 PST 2022


nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Very neat! A few minor suggestions but generally looks good.



================
Comment at: clang-tools-extra/clangd/AST.cpp:519
+      if (Spec->getTemplateSpecializationKind() != TSK_ImplicitInstantiation)
+        continue;
+      // Find the type for this specialization.
----------------
Should we `break` in this case? Otherwise there could be an explicit specialization with a second type


================
Comment at: clang-tools-extra/clangd/AST.cpp:545
+  // TemplateTypeParmTypes for implicit TTPs, instead of AutoTypes.
+  // Also we don't look very hard, just stripping const, references, pointers.
+  static TemplateTypeParmTypeLoc findContainedAutoTTPLoc(TypeLoc TL) {
----------------
Maybe call out an example like `vector<auto>` as a future nice-to-handle?


================
Comment at: clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp:88
+              StartsWith("fail: Could not deduce"));
+  EXPECT_EQ(apply("auto X = [](^auto){return 0;}; int Y = X(42);"),
+            "auto X = [](int){return 0;}; int Y = X(42);");
----------------
Maybe add a conflicting-deduction case? (I know the GetDeducedType test already has one, but here it would be especially wrong.)

Also, should we perhaps disable this in header files (maybe excepting function-local symbols), since an including source file could have additional instantiations?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119537



More information about the cfe-commits mailing list