[llvm-branch-commits] [clang-tools-extra] 9706568 - [clangd] Fix DocumentOutline for concepts
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jun 23 14:24:30 PDT 2020
Author: Kadir Cetinkaya
Date: 2020-06-23T14:23:12-07:00
New Revision: 97065683c6a965be9bc3dc06b0264940ed75c4af
URL: https://github.com/llvm/llvm-project/commit/97065683c6a965be9bc3dc06b0264940ed75c4af
DIFF: https://github.com/llvm/llvm-project/commit/97065683c6a965be9bc3dc06b0264940ed75c4af.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
(cherry picked from commit fb3d9153c01b9a560680465190d6ecd804e4c486)
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 llvm-branch-commits
mailing list