diff --git a/Examples/test-suite/cpp_enum.i b/Examples/test-suite/cpp_enum.i index a66cda1c8..8c8a0fd28 100644 --- a/Examples/test-suite/cpp_enum.i +++ b/Examples/test-suite/cpp_enum.i @@ -24,4 +24,11 @@ struct StructWithEnums { enum SOME_ENUM& enum_test8() { return some_enum; }; }; + + struct Foo + { + enum {Hi, Hello } hola; + + }; + %} diff --git a/Lib/swig.swg b/Lib/swig.swg index c51c5a67f..73a7416c3 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -403,3 +403,19 @@ static int NAME(TYPE x) { %enddef +/* Auxiliar methods for assigning unnamed type C++ variables, where + swig doesn't know the casting type, but C++ can derived it: + + struct Foo { enum {Hi, Hello } hola; }; +*/ +%insert("runtime") %{ +#ifdef __cplusplus +template +void swig_assign_unnamed(T& eval, const V& val) +{ + eval = static_cast(val); +} +#else +#define swig_assign_unnamed(eval, val) eval = val +#endif +%} diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index c4eb45cff..c0e0f0b54 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -557,7 +557,13 @@ Swig_cmemberset_call(String_or_char *name, SwigType *type, String_or_char *self) else self = NewString(self); Replaceall(self,"this",Swig_cparm_name(0,0)); if (SwigType_type(type) != T_ARRAY) { - Printf(func,"if (%s) %s%s = %s",Swig_cparm_name(0,0), self,name, Swig_wrapped_var_deref(type, Swig_cparm_name(0,1))); + if (!Strstr(type,"$unnamed")) { + Printf(func,"if (%s) %s%s = %s",Swig_cparm_name(0,0), self,name, + Swig_wrapped_var_deref(type, Swig_cparm_name(0,1))); + } else { + Printf(func,"if (%s) swig_assign_unnamed(%s%s, %s)",Swig_cparm_name(0,0), self,name, + Swig_cparm_name(0,1)); + } } Delete(self); return(func);