[PATCH] D70481: [clangd] Fix a crash in expected types
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 20 01:54:52 PST 2019
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman, jkorous, MaskRay.
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D70481
Files:
clang-tools-extra/clangd/ExpectedTypes.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1030,6 +1030,16 @@
SnippetSuffix("(${1:int A})"))));
}
+TEST(CompletionTest, NoCrashWithTemplateParamsAndPreferredTypes) {
+ auto Completions = completions(R"cpp(
+template <template <class> class TT> int foo() {
+ int a = ^
+}
+)cpp")
+ .Completions;
+ EXPECT_THAT(Completions, Contains(Named("TT")));
+}
+
SignatureHelp signatures(llvm::StringRef Text, Position Point,
std::vector<Symbol> IndexSymbols = {}) {
std::unique_ptr<SymbolIndex> Index;
Index: clang-tools-extra/clangd/ExpectedTypes.cpp
===================================================================
--- clang-tools-extra/clangd/ExpectedTypes.cpp
+++ clang-tools-extra/clangd/ExpectedTypes.cpp
@@ -44,12 +44,10 @@
static llvm::Optional<QualType>
typeOfCompletion(const CodeCompletionResult &R) {
const NamedDecl *D = R.Declaration;
- if (!D)
- return llvm::None;
// Templates do not have a type on their own, look at the templated decl.
- if (auto *Template = dyn_cast<TemplateDecl>(D))
+ if (auto *Template = dyn_cast_or_null<TemplateDecl>(D))
D = Template->getTemplatedDecl();
- auto *VD = dyn_cast<ValueDecl>(D);
+ auto *VD = dyn_cast_or_null<ValueDecl>(D);
if (!VD)
return llvm::None; // We handle only variables and functions below.
auto T = VD->getType();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70481.230212.patch
Type: text/x-patch
Size: 1603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191120/2e4cddf9/attachment.bin>
More information about the cfe-commits
mailing list