[clang-tools-extra] fb3d915 - [clangd] Fix DocumentOutline for concepts
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 20 11:20:33 PST 2020
Author: Kadir Cetinkaya
Date: 2020-01-20T20:20:27+01:00
New Revision: fb3d9153c01b9a560680465190d6ecd804e4c486
URL: https://github.com/llvm/llvm-project/commit/fb3d9153c01b9a560680465190d6ecd804e4c486
DIFF: https://github.com/llvm/llvm-project/commit/fb3d9153c01b9a560680465190d6ecd804e4c486.diff
LOG: [clangd] Fix DocumentOutline for concepts
Summary: Fixes https://github.com/clangd/clangd/issues/256
Reviewers: kbobyrev
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73056
Added:
Modified:
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp
index 4c92c8896b9d..1ce4222b5764 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -193,8 +193,11 @@ class DocumentOutline {
enum class VisitKind { No, OnlyDecl, DeclAndChildren };
void traverseDecl(Decl *D, std::vector<DocumentSymbol> &Results) {
- if (auto *Templ = llvm::dyn_cast<TemplateDecl>(D))
- D = Templ->getTemplatedDecl();
+ if (auto *Templ = llvm::dyn_cast<TemplateDecl>(D)) {
+ // TemplatedDecl might be null, e.g. concepts.
+ if (auto *TD = Templ->getTemplatedDecl())
+ D = TD;
+ }
auto *ND = llvm::dyn_cast<NamedDecl>(D);
if (!ND)
return;
diff --git a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
index 8eebb190edae..eba920a7a452 100644
--- a/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
@@ -449,6 +449,15 @@ TEST_F(DocumentSymbolsTest, DeclarationDefinition) {
SymNameRange(Main.range("def")))));
}
+TEST_F(DocumentSymbolsTest, Concepts) {
+ CDB.ExtraClangFlags = {"-std=c++2a"};
+ std::string FilePath = testPath("foo.cpp");
+ addFile(FilePath,
+ "template <typename T> concept C = requires(T t) { t.foo(); };");
+
+ EXPECT_THAT(getSymbols(FilePath), ElementsAre(WithName("C")));
+}
+
TEST_F(DocumentSymbolsTest, ExternSymbol) {
std::string FilePath = testPath("foo.cpp");
addFile(testPath("foo.h"), R"cpp(
More information about the cfe-commits
mailing list