forked from OSchip/llvm-project
[clangd] Fix hover crashing on null types
Summary: Fixes https://github.com/clangd/clangd/issues/225 Reviewers: sammccall, ilya-biryukov Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71403
This commit is contained in:
parent
d7357c52a4
commit
75b04c7af9
|
@ -242,12 +242,13 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D,
|
|||
// FIXME: handle variadics.
|
||||
}
|
||||
|
||||
llvm::Optional<std::string> printExprValue(const Expr *E, const ASTContext &Ctx) {
|
||||
llvm::Optional<std::string> printExprValue(const Expr *E,
|
||||
const ASTContext &Ctx) {
|
||||
Expr::EvalResult Constant;
|
||||
// Evaluating [[foo]]() as "&foo" isn't useful, and prevents us walking up
|
||||
// to the enclosing call.
|
||||
QualType T = E->getType();
|
||||
if (T->isFunctionType() || T->isFunctionPointerType() ||
|
||||
if (T.isNull() || T->isFunctionType() || T->isFunctionPointerType() ||
|
||||
T->isFunctionReferenceType())
|
||||
return llvm::None;
|
||||
// Attempt to evaluate. If expr is dependent, evaluation crashes!
|
||||
|
|
|
@ -506,6 +506,24 @@ void foo())cpp";
|
|||
HI.NamespaceScope = "";
|
||||
HI.Value = "&\"1234\"[0]";
|
||||
}},
|
||||
{R"cpp(// Should not crash
|
||||
template <typename T>
|
||||
struct Tmpl {
|
||||
Tmpl(int name);
|
||||
};
|
||||
|
||||
template <typename A>
|
||||
void boom(int name) {
|
||||
new Tmpl<A>([[na^me]]);
|
||||
})cpp",
|
||||
[](HoverInfo &HI) {
|
||||
HI.Name = "name";
|
||||
HI.Definition = "int name";
|
||||
HI.Kind = index::SymbolKind::Parameter;
|
||||
HI.Type = "int";
|
||||
HI.NamespaceScope = "";
|
||||
HI.LocalScope = "boom::";
|
||||
}},
|
||||
};
|
||||
for (const auto &Case : Cases) {
|
||||
SCOPED_TRACE(Case.Code);
|
||||
|
|
Loading…
Reference in New Issue