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_or_null<TemplateDecl>(D))
+ if (auto *Template = dyn_cast<TemplateDecl>(D))
D = Template->getTemplatedDecl();
- auto *VD = dyn_cast_or_null<ValueDecl>(D);
+ auto *VD = dyn_cast<ValueDecl>(D);
if (!VD)
return llvm::None; // We handle only variables and functions below.
auto T = VD->getType();
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;