Skip to content

Commit

Permalink
Check scope before casting to CXXRecordDecl
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronj0 committed Apr 4, 2024
1 parent c6d098b commit 4ef5e76
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/Interpreter/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,18 +727,20 @@ namespace Cpp {
if (auto* TD = dyn_cast<TypedefNameDecl>(D))
D = GetScopeFromType(TD->getUnderlyingType());

if (auto* CXXRD = dyn_cast_or_null<CXXRecordDecl>(D)) {
if (D && isa<CXXRecordDecl>(D)) {
auto* CXXRD = dyn_cast<CXXRecordDecl>(D);
getSema().ForceDeclarationOfImplicitMembers(CXXRD);
for (Decl* DI : CXXRD->decls()) {
if (auto* MD = dyn_cast<CXXMethodDecl>(DI))
methods.push_back(MD);
else if (auto* USD = dyn_cast<UsingShadowDecl>(DI))
if (auto* MD = dyn_cast<CXXMethodDecl>(USD->getTargetDecl()))
for (Decl* DI : CXXRD->decls()) {
if (auto* MD = dyn_cast<CXXMethodDecl>(DI))
methods.push_back(MD);
else if (auto* USD = dyn_cast<UsingShadowDecl>(DI))
if (auto* MD = dyn_cast<CXXMethodDecl>(USD->getTargetDecl()))
methods.push_back(MD);
}
}
}
}


void GetFunctionTemplatedDecls(TCppScope_t klass,
std::vector<TCppFunction_t>& methods) {
Expand All @@ -748,7 +750,8 @@ namespace Cpp {
if (auto* TD = dyn_cast<TypedefNameDecl>(D))
D = GetScopeFromType(TD->getUnderlyingType());

if (auto* CXXRD = dyn_cast_or_null<CXXRecordDecl>(D)) {
if (D && isa<CXXRecordDecl>(D)) {
auto* CXXRD = dyn_cast<CXXRecordDecl>(D);
getSema().ForceDeclarationOfImplicitMembers(CXXRD);
for (Decl* DI : CXXRD->decls()) {
if (auto* MD = dyn_cast<FunctionTemplateDecl>(DI))
Expand All @@ -760,6 +763,7 @@ namespace Cpp {
}
}
}


bool HasDefaultConstructor(TCppScope_t scope) {
auto *D = (clang::Decl *) scope;
Expand Down Expand Up @@ -1009,7 +1013,7 @@ namespace Cpp {

return {};
}

TCppFunction_t
BestTemplateFunctionMatch(const std::vector<TCppFunction_t>& candidates,
const std::vector<TemplateArgInfo>& explicit_types,
Expand Down

0 comments on commit 4ef5e76

Please sign in to comment.