Skip to content

while instantiating template use non reference types #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions clingwrapper/src/clingwrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,12 @@ class ApplicationStarter {

// load frequently used headers
const char* code =
"#include <algorithm>\n"
"#include <iostream>\n"
"#include <string.h>\n" // for strcpy
"#include <string>\n"
// "#include <DllImport.h>\n" // defines R__EXTERN
"#include <complex>\n"
"#include <vector>\n"
"#include <utility>\n"
"#include <memory>\n"
Expand Down Expand Up @@ -468,15 +470,20 @@ bool Cppyy::IsFunctionPointerType(TCppType_t type) {
}

// returns true if no new type was added.
bool Cppyy::AppendTypesSlow(const std::string &name,
std::vector<Cpp::TemplateArgInfo>& types) {
bool Cppyy::AppendTypesSlow(const std::string& name,
std::vector<Cpp::TemplateArgInfo>& types,
bool no_reference) {

// Add no new type if string is empty
if (name.empty()) return true;

// Try going via Cppyy::GetType first.
if (Cppyy::TCppType_t type = GetType(name, /*enable_slow_lookup=*/true)) {
types.push_back(type);
if (no_reference)
types.push_back(
Cpp::IsReferenceType(type) ? Cpp::GetNonReferenceType(type) : type);
else
types.push_back(type);
return false;
}
// Else, we might have an entire expression such as int, double.
Expand All @@ -492,6 +499,11 @@ bool Cppyy::AppendTypesSlow(const std::string &name,
TCppScope_t instance_class = Cpp::GetScopeFromType(varN);
size_t oldSize = types.size();
Cpp::GetClassTemplateInstantiationArgs(instance_class, types);
if (no_reference)
for (size_t i = 0; i < types.size(); i++)
types[i].m_Type = Cpp::IsReferenceType(types[i].m_Type)
? Cpp::GetNonReferenceType(types[i].m_Type)
: types[i].m_Type;
return oldSize == types.size();
}
return true;
Expand Down Expand Up @@ -1508,16 +1520,14 @@ Cppyy::TCppMethod_t Cppyy::GetMethodTemplate(
// CPyCppyy assumes that we attempt instantiation here
std::vector<Cpp::TemplateArgInfo> arg_types;
std::vector<Cpp::TemplateArgInfo> templ_params;
Cppyy::AppendTypesSlow(proto, arg_types);
if (Cppyy::IsClass(scope))
Cppyy::AppendTypesSlow(proto, arg_types);
else
Cppyy::AppendTypesSlow(proto, arg_types, true);
Cppyy::AppendTypesSlow(explicit_params, templ_params);

Cppyy::TCppMethod_t cppmeth = Cpp::BestTemplateFunctionMatch(unresolved_candidate_methods, templ_params, arg_types);

if(!cppmeth){
return nullptr;
}

return cppmeth;
return Cpp::BestTemplateFunctionMatch(unresolved_candidate_methods,
templ_params, arg_types);

// if it fails, use Sema to propogate info about why it failed (DeductionInfo)

Expand Down
5 changes: 3 additions & 2 deletions clingwrapper/src/cpp_cppyy.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ namespace Cppyy {
RPY_EXPORTED
TCppType_t GetType(const std::string &name, bool enable_slow_lookup = false);
RPY_EXPORTED
bool AppendTypesSlow(const std::string &name,
std::vector<Cpp::TemplateArgInfo>& types);
bool AppendTypesSlow(const std::string& name,
std::vector<Cpp::TemplateArgInfo>& types,
bool no_reference = false);
RPY_EXPORTED
TCppType_t GetComplexType(const std::string &element_type);
RPY_EXPORTED
Expand Down
Loading