Menu

#329 Go Module Generates Code For Template Member Functions

closed-fixed
None
5
2012-10-02
2012-09-29
Nigel Choi
No

The Go module generates incorrect cxx code if a base class has templetized member functions. Consider this in example.h :

class Top {
public:
template<typename T> T cast() const {
return dynamic_cast<T>(this);
}
};

class Sub : public Top {
};

And this example.i

%module example
%{
#include "example.h"
%}
%include "example.h"

Running
swig -go -c++ example.i

Will produce code that looks like:

void
_wrap_Sub_cast(void *swig_v)
{
Sub *arg1 = (Sub *) 0 ;
T result;
...

And compiler error:

example_wrap.cxx:333:3: error: use of undeclared identifier 'T'
T result;
^

The simple fix is a one-liner applied on top of 2.0.8 . It's also attached.

--- a/Source/Modules/go.cxx
+++ b/Source/Modules/go.cxx
@@ -1958,7 +1958,7 @@ private:
}

String *type = Getattr(ni, "nodeType");
- if (Strcmp(type, "constructor") == 0 || Strcmp(type, "destructor") == 0 || Strcmp(type, "enum") == 0 || Strcmp(type, "using") == 0 || Strcmp(type, "classforward") == 0) {
+ if (Strcmp(type, "constructor") == 0 || Strcmp(type, "destructor") == 0 || Strcmp(type, "enum") == 0 || Strcmp(type, "using") == 0 || Strcmp(type, "classforward") == 0 || Strcmp(type, "template") == 0) {
continue;
}
String *storage = Getattr(ni, "storage");

Discussion

  • Nigel Choi

    Nigel Choi - 2012-09-29

    Patch

     
  • Nigel Choi

    Nigel Choi - 2012-09-29
    • assigned_to: nobody --> ianlancetaylor
     
  • Nigel Choi

    Nigel Choi - 2012-09-29

    Ian, knowing that you authored the Go module I assigned this to you. Please let me know if this is done correctly, and if I should assign this to someone else to have the patch reviewed and applied. Thank you.

     
  • Ian Lance Taylor

    Patch committed.

    Thanks.

     
  • Ian Lance Taylor

    • status: open --> closed-fixed
     

Log in to post a comment.