Menu

#1355 Using typedef alias in %template, where typedef includes namespace causes error

None
closed-fixed
nobody
5
2022-03-21
2014-01-09
No

With swig 2.0.11, I have the following small example:

%module(directors="1", allprotected="1") test
%include "std_vector.i"

%{
#include <vector>
class myObject
{
public :
    enum EntityType { ET_ONE, ET_TWO };
};
typedef myObject::EntityType myObjectType;
%}

#include <vector>
class myObject
{
public :
    enum EntityType { ET_ONE, ET_TWO };
};
typedef myObject::EntityType myObjectType;

// First one doesn't work, second one does
%template (objectStlVector) std::vector<myObjectType>;
//%template (objectStlVector) std::vector<myObject::EntityType>;

When I attempt to generate python wrappings for this, I get the following error:

D:\software\blue\devtools\bin\win64d\lib\swig2.0\std\std_vector.i(87) : Error: Can't copy typemap (directorout) std::vector< myObject::EntityType,std::allocator< myObject::EntityType > > = std::vector< myObject::EntityType,std::allocator< myObject::EntityType > > &DIRECTOROUT
D:\software\blue\devtools\bin\win64d\lib\swig2.0\std\std_vector.i(87) : Error: Can't copy typemap (in) std::vector< myObject::EntityType,std::allocator< myObject::EntityType > > *INPUT = std::vector< myObject::EntityType,std::allocator< myObject::EntityType > > *INOUT
D:\software\blue\devtools\bin\win64d\lib\swig2.0\std\std_vector.i(87) : Error: Can't copy typemap (in) std::vector< myObject::EntityType,std::allocator< myObject::EntityType > > &INPUT = std::vector< myObject::EntityType,std::allocator< myObject::EntityType > > &INOUT

<BR>
After playing with this small test case for a while, I did find a workaround – if I avoid using the typedef alias to instantiate my vector, all works well. That means uncommenting the commented line in the code above, while commenting the other %template.

The looks to be somewhat familiar with the “using std” issue that was run into a while back (found the thread on swig-user), except instead of being a problem with 'using', it's a problem with typedef.. This is just a guess..

Discussion

  • William Fulton

    William Fulton - 2014-01-14

    There are some quirks with enums which could do with fixing. Changing:

    typedef myObject::EntityType myObjectType;

    to:

    typedef enum myObject::EntityType myObjectType;

    Then produces code that compiles.

    Generally, the fully resolved type is recommended as the %template parameter(s) due to various corner case problems in %template.

     
  • Olly Betts

    Olly Betts - 2022-03-21
    • status: open --> closed-fixed
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2022-03-21

    This seems to have been fixed in the meantime - the example processes without warnings from swig -python -c++ -Wall test.i using SWIG 4.0.2 and the resulting code compiles successfully.

     

Log in to post a comment.