diff --git a/CHANGES.current b/CHANGES.current index e2daa5aae..a8ab3a595 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,3 +5,8 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.3 (in progress) =========================== +2011-03-02: wsfulton + Templated smart pointers overloaded with both const and non const operator-> generated uncompilable + code when the pointee was a class with either public member variables or static methods. + Regression in 2.0.x reported as working in 1.3.40 by xantares on swig-user mailing list. + diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 756d6cbab..1e0665f66 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -313,6 +313,7 @@ CPP_TEST_CASES += \ smart_pointer_rename \ smart_pointer_simple \ smart_pointer_static \ + smart_pointer_template_const_overload \ smart_pointer_templatemethods \ smart_pointer_templatevariables \ smart_pointer_typedef \ diff --git a/Examples/test-suite/smart_pointer_template_const_overload.i b/Examples/test-suite/smart_pointer_template_const_overload.i new file mode 100644 index 000000000..be5f08a35 --- /dev/null +++ b/Examples/test-suite/smart_pointer_template_const_overload.i @@ -0,0 +1,35 @@ +%module smart_pointer_template_const_overload + +%warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) SmartPointer::operator->; // Overloaded method SmartPointer< FooImplementation >::operator ->() ignored + +%inline %{ + template class SmartPointer { + T *ptr; + public: + SmartPointer(T *t = 0) : ptr(t) {} + inline const T * operator->() const { return ptr; } + inline T * operator->() { return ptr; } + }; + + class FooImplementation { + public: + int mingy() {} + int constmingy() const {} + static int thingy() {} + static int svariable; + static const int constsvariable = 2; + int normalvariable; + }; + + void tester() { + SmartPointer p; + p->mingy(); + p->constmingy(); + p->thingy(); + int a = p->svariable; + a = p->constsvariable; + a = p->normalvariable; + } +%} + +%template(FooSmartPointer) SmartPointer; diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c index 28401f89f..8a7ecd074 100644 --- a/Source/Swig/cwrap.c +++ b/Source/Swig/cwrap.c @@ -794,14 +794,16 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas /* If smart pointer without const overload or mutable method, change self dereferencing */ if (flags & CWRAP_SMART_POINTER) { if (flags & CWRAP_SMART_POINTER_OVERLOAD) { - String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname; if (qualifier && strncmp(Char(qualifier), "q(const)", 8) == 0) { self = NewString("(*(this))->"); is_smart_pointer_overload = 1; } else if (Cmp(Getattr(n, "storage"), "static") == 0) { - self = NewStringf("(*(%s const *)this)->", cname); + String *cname = Getattr(n, "classname") ? Getattr(n, "classname") : classname; + String *ctname = SwigType_namestr(cname); + self = NewStringf("(*(%s const *)this)->", ctname); is_smart_pointer_overload = 1; + Delete(ctname); } else { self = NewString("(*this)->"); @@ -940,7 +942,9 @@ int Swig_MethodToFunction(Node *n, const_String_or_char_ptr nspace, String *clas String *ctname = SwigType_namestr(cname); String *fadd = 0; if (is_smart_pointer_overload) { - fadd = NewStringf("(%s const *)((%s const *)%s)->operator ->()", ctname, classname, pname); + String *nclassname = SwigType_namestr(classname); + fadd = NewStringf("(%s const *)((%s const *)%s)->operator ->()", ctname, nclassname, pname); + Delete(nclassname); } else { fadd = NewStringf("(%s*)(%s)->operator ->()", ctname, pname); @@ -1333,7 +1337,9 @@ int Swig_MembergetToFunction(Node *n, String *classname, int flags) { String *base = Getattr(sn, "name"); self = NewStringf("%s::", base); } else if (flags & CWRAP_SMART_POINTER_OVERLOAD) { - self = NewStringf("(*(%s const *)this)->", classname); + String *nclassname = SwigType_namestr(classname); + self = NewStringf("(*(%s const *)this)->", nclassname); + Delete(nclassname); } else { self = NewString("(*this)->"); }