forked from OSchip/llvm-project
[clangd] Fix inlayhints crash, don't assume functions have FunctionTypeLocs
Fixes https://github.com/clangd/clangd/issues/1140
This commit is contained in:
parent
21c028ac94
commit
6385c039b8
|
@ -258,8 +258,10 @@ public:
|
|||
bool VisitFunctionDecl(FunctionDecl *D) {
|
||||
if (auto *FPT =
|
||||
llvm::dyn_cast<FunctionProtoType>(D->getType().getTypePtr())) {
|
||||
if (!FPT->hasTrailingReturn())
|
||||
addReturnTypeHint(D, D->getFunctionTypeLoc().getRParenLoc());
|
||||
if (!FPT->hasTrailingReturn()) {
|
||||
if (auto FTL = D->getFunctionTypeLoc())
|
||||
addReturnTypeHint(D, FTL.getRParenLoc());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -811,6 +811,16 @@ TEST(TypeHints, SinglyInstantiatedTemplate) {
|
|||
ExpectedHint{": void *", "a"});
|
||||
}
|
||||
|
||||
TEST(TypeHints, Aliased) {
|
||||
// Check that we don't crash for functions without a FunctionTypeLoc.
|
||||
// https://github.com/clangd/clangd/issues/1140
|
||||
TestTU TU = TestTU::withCode("void foo(void){} extern typeof(foo) foo;");
|
||||
TU.ExtraArgs.push_back("-xc");
|
||||
auto AST = TU.build();
|
||||
|
||||
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::TypeHint), IsEmpty());
|
||||
}
|
||||
|
||||
TEST(DesignatorHints, Basic) {
|
||||
assertDesignatorHints(R"cpp(
|
||||
struct S { int x, y, z; };
|
||||
|
|
Loading…
Reference in New Issue