From 4ef5e766615930ac3ddfa992da0ad5799e90e6df Mon Sep 17 00:00:00 2001 From: maximusron Date: Thu, 4 Apr 2024 12:30:53 +0200 Subject: [PATCH] Check scope before casting to CXXRecordDecl --- lib/Interpreter/CppInterOp.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Interpreter/CppInterOp.cpp b/lib/Interpreter/CppInterOp.cpp index cd5d30175..269b585a6 100644 --- a/lib/Interpreter/CppInterOp.cpp +++ b/lib/Interpreter/CppInterOp.cpp @@ -727,18 +727,20 @@ namespace Cpp { if (auto* TD = dyn_cast(D)) D = GetScopeFromType(TD->getUnderlyingType()); - if (auto* CXXRD = dyn_cast_or_null(D)) { + if (D && isa(D)) { + auto* CXXRD = dyn_cast(D); getSema().ForceDeclarationOfImplicitMembers(CXXRD); - for (Decl* DI : CXXRD->decls()) { - if (auto* MD = dyn_cast(DI)) - methods.push_back(MD); - else if (auto* USD = dyn_cast(DI)) - if (auto* MD = dyn_cast(USD->getTargetDecl())) + for (Decl* DI : CXXRD->decls()) { + if (auto* MD = dyn_cast(DI)) methods.push_back(MD); + else if (auto* USD = dyn_cast(DI)) + if (auto* MD = dyn_cast(USD->getTargetDecl())) + methods.push_back(MD); } } } } + void GetFunctionTemplatedDecls(TCppScope_t klass, std::vector& methods) { @@ -748,7 +750,8 @@ namespace Cpp { if (auto* TD = dyn_cast(D)) D = GetScopeFromType(TD->getUnderlyingType()); - if (auto* CXXRD = dyn_cast_or_null(D)) { + if (D && isa(D)) { + auto* CXXRD = dyn_cast(D); getSema().ForceDeclarationOfImplicitMembers(CXXRD); for (Decl* DI : CXXRD->decls()) { if (auto* MD = dyn_cast(DI)) @@ -760,6 +763,7 @@ namespace Cpp { } } } + bool HasDefaultConstructor(TCppScope_t scope) { auto *D = (clang::Decl *) scope; @@ -1009,7 +1013,7 @@ namespace Cpp { return {}; } - + TCppFunction_t BestTemplateFunctionMatch(const std::vector& candidates, const std::vector& explicit_types,