forked from OSchip/llvm-project
[clangd] Fix crash hovering on non-decltype trailing return
Summary: More specifically, hovering on "auto" in auto main() -> int { return 0; } Signed-off-by: Marc-Andre Laperle <malaperle@gmail.com> Reviewers: ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D54553 llvm-svn: 347119
This commit is contained in:
parent
b5c1d69e40
commit
f975400838
|
@ -605,6 +605,7 @@ public:
|
|||
// Handle auto return types:
|
||||
//- auto foo() {}
|
||||
//- auto& foo() {}
|
||||
//- auto foo() -> int {}
|
||||
//- auto foo() -> decltype(1+1) {}
|
||||
//- operator auto() const { return 10; }
|
||||
bool VisitFunctionDecl(FunctionDecl *D) {
|
||||
|
@ -624,12 +625,13 @@ public:
|
|||
const AutoType *AT = D->getReturnType()->getContainedAutoType();
|
||||
if (AT && !AT->getDeducedType().isNull()) {
|
||||
DeducedType = AT->getDeducedType();
|
||||
} else {
|
||||
} else if (auto DT = dyn_cast<DecltypeType>(D->getReturnType())) {
|
||||
// auto in a trailing return type just points to a DecltypeType and
|
||||
// getContainedAutoType does not unwrap it.
|
||||
const DecltypeType *DT = dyn_cast<DecltypeType>(D->getReturnType());
|
||||
if (!DT->getUnderlyingType().isNull())
|
||||
DeducedType = DT->getUnderlyingType();
|
||||
} else if (!D->getReturnType().isNull()) {
|
||||
DeducedType = D->getReturnType();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -835,6 +835,14 @@ TEST(Hover, All) {
|
|||
)cpp",
|
||||
"",
|
||||
},
|
||||
{
|
||||
R"cpp(// simple trailing return type
|
||||
^auto main() -> int {
|
||||
return 0;
|
||||
}
|
||||
)cpp",
|
||||
"int",
|
||||
},
|
||||
{
|
||||
R"cpp(// auto function return with trailing type
|
||||
struct Bar {};
|
||||
|
|
Loading…
Reference in New Issue