mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 14:36:46 +00:00
[clangd] Check getFunctionTypeLoc() for validity in InlayHintVisitor (#117296)
Fixes https://github.com/clangd/clangd/issues/2223
This commit is contained in:
parent
a9882bda96
commit
5518bb215b
@ -626,10 +626,15 @@ public:
|
||||
|
||||
bool VisitLambdaExpr(LambdaExpr *E) {
|
||||
FunctionDecl *D = E->getCallOperator();
|
||||
if (!E->hasExplicitResultType())
|
||||
addReturnTypeHint(D, E->hasExplicitParameters()
|
||||
? D->getFunctionTypeLoc().getRParenLoc()
|
||||
: E->getIntroducerRange().getEnd());
|
||||
if (!E->hasExplicitResultType()) {
|
||||
SourceLocation TypeHintLoc;
|
||||
if (!E->hasExplicitParameters())
|
||||
TypeHintLoc = E->getIntroducerRange().getEnd();
|
||||
else if (auto FTL = D->getFunctionTypeLoc())
|
||||
TypeHintLoc = FTL.getRParenLoc();
|
||||
if (TypeHintLoc.isValid())
|
||||
addReturnTypeHint(D, TypeHintLoc);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1576,6 +1576,22 @@ TEST(TypeHints, Aliased) {
|
||||
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type), IsEmpty());
|
||||
}
|
||||
|
||||
TEST(TypeHints, CallingConvention) {
|
||||
// Check that we don't crash for lambdas without a FunctionTypeLoc
|
||||
// https://github.com/clangd/clangd/issues/2223
|
||||
std::string Code = R"cpp(
|
||||
void test() {
|
||||
[]() __cdecl {};
|
||||
}
|
||||
)cpp";
|
||||
TestTU TU = TestTU::withCode(Code);
|
||||
TU.ExtraArgs.push_back("--target=x86_64-w64-mingw32");
|
||||
TU.PredefineMacros = true; // for the __cdecl
|
||||
auto AST = TU.build();
|
||||
|
||||
EXPECT_THAT(hintsOfKind(AST, InlayHintKind::Type), IsEmpty());
|
||||
}
|
||||
|
||||
TEST(TypeHints, Decltype) {
|
||||
assertTypeHints(R"cpp(
|
||||
$a[[decltype(0)]] a;
|
||||
|
Loading…
x
Reference in New Issue
Block a user