[PATCH] D154623: [clangd][c++20]Check for correct auto location in DeducedTypeVisitor

Jens Massberg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 6 09:38:00 PDT 2023


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

In case of a constrained auto the correct location has to chosen.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154623

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -477,6 +477,16 @@
          HI.Kind = index::SymbolKind::TypeAlias;
          HI.Definition = "/* not deduced */";
        }},
+      // constrained auto
+      {R"cpp(
+        template <class T> concept F = true;
+        F [[au^to]] x = 1;
+        )cpp",
+       [](HoverInfo &HI) {
+         HI.Name = "auto";
+         HI.Kind = index::SymbolKind::TypeAlias;
+         HI.Definition = "int";
+       }},
       // auto on lambda
       {R"cpp(
         void foo() {
@@ -1314,7 +1324,7 @@
 
     Annotations T(Case.Code);
     TestTU TU = TestTU::withCode(T.code());
-    TU.ExtraArgs.push_back("-std=c++17");
+    TU.ExtraArgs.push_back("-std=c++20");
     // Types might be different depending on the target triplet, we chose a
     // fixed one to make sure tests passes on different platform.
     TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
Index: clang-tools-extra/clangd/AST.cpp
===================================================================
--- clang-tools-extra/clangd/AST.cpp
+++ clang-tools-extra/clangd/AST.cpp
@@ -482,7 +482,11 @@
   //- auto* i = &a;
   bool VisitDeclaratorDecl(DeclaratorDecl *D) {
     if (!D->getTypeSourceInfo() ||
-        D->getTypeSourceInfo()->getTypeLoc().getBeginLoc() != SearchedLocation)
+        !D->getTypeSourceInfo()->getTypeLoc().getContainedAutoTypeLoc() ||
+        D->getTypeSourceInfo()
+                ->getTypeLoc()
+                .getContainedAutoTypeLoc()
+                .getNameLoc() != SearchedLocation)
       return true;
 
     if (auto *AT = D->getType()->getContainedAutoType()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154623.537769.patch
Type: text/x-patch
Size: 1807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230706/07b26c5e/attachment.bin>


More information about the cfe-commits mailing list