[PATCH] D154853: [clangd][c++20]Consider the constraint of a constrained auto in FindTarget.

Jens Massberg via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 11 01:10:26 PDT 2023


massberg updated this revision to Diff 538952.
massberg added a comment.

clang-format code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154853

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.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
@@ -487,6 +487,46 @@
          HI.Kind = index::SymbolKind::TypeAlias;
          HI.Definition = "int";
        }},
+      // constraint of constrained auto
+      {R"cpp(
+        template <class T> concept Fooable = true;
+        [[Foo^able]] auto x = 1;
+        )cpp",
+       [](HoverInfo &HI) {
+         HI.NamespaceScope = "";
+         HI.Name = "Fooable";
+         HI.Kind = index::SymbolKind::Concept;
+         HI.Definition = "template <class T>\n"
+                         "concept Fooable = true";
+       }},
+      {R"cpp(
+        template <class T> concept Fooable = true;
+        template<[[Fooa^ble]] auto x> void Foo() {}
+        )cpp",
+       [](HoverInfo &HI) {
+         HI.NamespaceScope = "";
+         HI.Name = "Fooable";
+         HI.Kind = index::SymbolKind::Concept;
+         HI.Definition = "template <class T>\n"
+                         "concept Fooable = true";
+       }},
+      // concept
+      {R"cpp(
+        template <typename T>
+        concept Fooable = requires (T t) { t.foo(); };
+
+        template <typename T> requires [[Fo^oable]]<T>
+        void bar(T t) {
+          t.foo();
+        }
+        )cpp",
+       [](HoverInfo &HI) {
+         HI.NamespaceScope = "";
+         HI.Name = "Fooable";
+         HI.Kind = index::SymbolKind::Concept;
+         HI.Definition = "template <typename T>\n"
+                         "concept Fooable = requires(T t) { t.foo(); }";
+       }},
       // auto on lambda
       {R"cpp(
         void foo() {
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -572,6 +572,23 @@
   )cpp";
   EXPECT_DECLS("ConceptSpecializationExpr",
                {"template <typename T, typename U> concept Fooable = true"});
+
+  // Constrained auto
+  Code = R"cpp(
+    template <typename T>
+    concept Fooable = true;
+
+    [[Fooable]] auto i = 42;
+  )cpp";
+  EXPECT_DECLS("AutoTypeLoc", {"template <typename T> concept Fooable = true"});
+
+  Code = R"cpp(
+    template <typename T>
+    concept Fooable = true;
+
+    template<[[Fooable]] auto x> void Foo() {}
+  )cpp";
+  EXPECT_DECLS("AutoTypeLoc", {"template <typename T> concept Fooable = true"});
 }
 
 TEST_F(TargetDeclTest, Coroutine) {
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -471,6 +471,12 @@
       void VisitObjCInterfaceType(const ObjCInterfaceType *OIT) {
         Outer.add(OIT->getDecl(), Flags);
       }
+      void VisitAutoType(const AutoType *T) {
+        if (T->isConstrained()) {
+          Outer.add(T->getTypeConstraintConcept(), Flags);
+        }
+        TypeVisitor<Visitor>::VisitAutoType(T);
+      }
     };
     Visitor(*this, Flags).Visit(T.getTypePtr());
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154853.538952.patch
Type: text/x-patch
Size: 3243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230711/968b7be5/attachment.bin>


More information about the cfe-commits mailing list