This revision was automatically updated to reflect the committed changes. Closed by commit rGfb3d9153c01b: [clangd] Fix DocumentOutline for concepts (authored by kadircet).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D73056/new/ https://reviews.llvm.org/D73056 Files: clang-tools-extra/clangd/FindSymbols.cpp clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp +++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp @@ -449,6 +449,15 @@ 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( Index: clang-tools-extra/clangd/FindSymbols.cpp =================================================================== --- clang-tools-extra/clangd/FindSymbols.cpp +++ clang-tools-extra/clangd/FindSymbols.cpp @@ -193,8 +193,11 @@ 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;
Index: clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp +++ clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp @@ -449,6 +449,15 @@ 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( Index: clang-tools-extra/clangd/FindSymbols.cpp =================================================================== --- clang-tools-extra/clangd/FindSymbols.cpp +++ clang-tools-extra/clangd/FindSymbols.cpp @@ -193,8 +193,11 @@ 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits