From cbcd07a4815f546739fb1374a7f24f35e5352e17 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Tue, 21 Jan 2020 16:55:43 -0500 Subject: [PATCH] [clangd] Add C++20 concepts support to TargetFinder Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73140 --- clang-tools-extra/clangd/FindTarget.cpp | 4 ++++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index 6123ffbb76a..ca0584cbec7 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -17,6 +17,7 @@ #include "clang/AST/DeclarationName.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/ExprConcepts.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/PrettyPrinter.h" @@ -279,6 +280,9 @@ public: void VisitCallExpr(const CallExpr *CE) { Outer.add(CE->getCalleeDecl(), Flags); } + void VisitConceptSpecializationExpr(const ConceptSpecializationExpr *E) { + Outer.add(E->getNamedConcept(), Flags); + } void VisitDeclRefExpr(const DeclRefExpr *DRE) { const Decl *D = DRE->getDecl(); // UsingShadowDecl allows us to record the UsingDecl. diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp index 96e488d8a0f..0f450e8dfc2 100644 --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -339,6 +339,24 @@ TEST_F(TargetDeclTest, ClassTemplate) { {"struct Test", Rel::TemplatePattern}); } +TEST_F(TargetDeclTest, Concept) { + Code = R"cpp( + template + concept Fooable = requires (T t) { t.foo(); }; + + template requires [[Fooable]] + void bar(T t) { + t.foo(); + } + )cpp"; + Flags.push_back("-std=c++2a"); + EXPECT_DECLS( + "ConceptSpecializationExpr", + // FIXME: Should we truncate the pretty-printed form of a concept decl + // somewhere? + {"template concept Fooable = requires (T t) { t.foo(); };"}); +} + TEST_F(TargetDeclTest, FunctionTemplate) { Code = R"cpp( // Implicit specialization. -- 2.11.0