Skip to content

Commit 686fae1

Browse files
fix: resolve namespace while instantiating templates in a namespace (#151)
Enables instantiating templates `f` with type `t` without explicitly specifying the namespace in type `t`, if `f` and `t` belong to the same namespace.
1 parent e2fa42a commit 686fae1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clingwrapper/src/clingwrapper.cxx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ bool split_comma_saparated_types(const std::string& name,
555555

556556
// returns true if no new type was added.
557557
bool Cppyy::AppendTypesSlow(const std::string& name,
558-
std::vector<Cpp::TemplateArgInfo>& types) {
558+
std::vector<Cpp::TemplateArgInfo>& types, Cppyy::TCppScope_t parent) {
559559

560560
// Add no new type if string is empty
561561
if (name.empty())
@@ -593,6 +593,16 @@ bool Cppyy::AppendTypesSlow(const std::string& name,
593593
if (is_integral(i))
594594
integral_value = strdup(i.c_str());
595595
types.emplace_back(type, integral_value);
596+
} else if (parent && (Cpp::IsNamespace(parent) || Cpp::IsClass(parent))) {
597+
if (Cppyy::TCppType_t type = Cppyy::GetTypeFromScope(Cppyy::GetNamed(name, parent))) {
598+
const char* integral_value = nullptr;
599+
if (is_integral(i))
600+
integral_value = strdup(i.c_str());
601+
types.emplace_back(type, integral_value);
602+
} else {
603+
types.clear();
604+
return true;
605+
}
596606
} else {
597607
types.clear();
598608
return true;

clingwrapper/src/cpp_cppyy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ namespace Cppyy {
9393
TCppType_t GetType(const std::string &name, bool enable_slow_lookup = false);
9494
RPY_EXPORTED
9595
bool AppendTypesSlow(const std::string &name,
96-
std::vector<Cpp::TemplateArgInfo>& types);
96+
std::vector<Cpp::TemplateArgInfo>& types, Cppyy::TCppScope_t parent = nullptr);
9797
RPY_EXPORTED
9898
TCppType_t GetComplexType(const std::string &element_type);
9999
RPY_EXPORTED

0 commit comments

Comments
 (0)