diff --git a/Lib/swig.swg b/Lib/swig.swg index bccdf10d1..6f40a8fe9 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -632,7 +632,7 @@ namespace std { #ifdef __cplusplus %insert("runtime") %{ #ifdef __cplusplus -template class SwigValueWrapper { +template class SwigValueWrapper { T *tt; public: SwigValueWrapper() : tt(0) { } @@ -644,7 +644,21 @@ public: T *operator&() { return tt; } private: SwigValueWrapper& operator=(const SwigValueWrapper& rhs); -}; +};%} + +/* + * SwigValueInit() is a generic initialisation solution as the following approach: + * + * T c_result = T(); + * + * doesn't compile for all types for example: + * + * unsigned int c_result = unsigned int(); + */ +%insert("runtime") %{ +template T SwigValueInit() { + return T(); +} #endif %} #endif diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx index a348983b7..d8b9fe0a3 100644 --- a/Source/Modules/csharp.cxx +++ b/Source/Modules/csharp.cxx @@ -3184,7 +3184,7 @@ public: if (!is_void && !ignored_method) { if (!SwigType_isclass(returntype)) { if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { - String *construct_result = NewStringf("= %s()", SwigType_lstr(returntype, 0)); + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); Delete(construct_result); } else { diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx index bb160b733..601b026ba 100644 --- a/Source/Modules/java.cxx +++ b/Source/Modules/java.cxx @@ -3293,7 +3293,7 @@ public: if (!is_void && (!ignored_method || pure_virtual)) { if (!SwigType_isclass(returntype)) { if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) { - String *construct_result = NewStringf("= %s()", SwigType_lstr(returntype, 0)); + String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0)); Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL); Delete(construct_result); } else {