With the update to swig 2.0.12, swig now generates invalid C++ code for a template class having a std::map as template argument. Swig generates invalid C++ for the following C++/swig code:
=== wrappedmap.i ===
%module wrappedmap
%include <stl.i></stl.i>
template<typename t="">
class Wrap {
public:
T* operator->(void) const;
};</typename>
%{
template<typename t="">
class Wrap {
public:
T* operator->(void) const { return NULL; }
};
%}</typename>
%template(StringDoubleMap) std::map<std::string, double="">;
%template(WrappedMap) Wrap< std::map<std::string, double=""> >;
======</std::string,></std::string,>
$ swig -version
SWIG Version 2.0.12
Compiled with g++ [i686-pc-linux-gnu]
Configured options: +pcre
Please see http://www.swig.org for reporting bugs and further information
$ swig -c++ -python -o wrappedmap.cpp wrappedmap.i && g++ -fPIC -c wrappedmap.cpp -I/usr/include/python2.7
wrappedmap.cpp: In function 'PyObject _wrap_WrappedMap_erase__SWIG_1(PyObject, PyObject)':
wrappedmap.cpp:8108:293: error: 'std_map_Sl_std_string_Sc_double_Sc_std_less_Sl_std_string_Sg__Sc_std_allocator_Sl_std_pair_Sl_std_string_SS_const_Sc_double_Sg__Sg__Sg__erase__SWIG_1' was not declared in this scope
wrappedmap.cpp: In function 'PyObject _wrap_WrappedMap_erase__SWIG_2(PyObject, PyObject)':
wrappedmap.cpp:8159:298: error: 'std_map_Sl_std_string_Sc_double_Sc_std_less_Sl_std_string_Sg__Sc_std_allocator_Sl_std_pair_Sl_std_string_SS_const_Sc_double_Sg__Sg__Sg__erase__SWIG_2' was not declared in this scope
Grepping on the swig generated code reveals the following:
$ grep -n std_map_Sl_std_string_._Sg__erase wrappedmap.cpp
5172:SWIGINTERN void std_map_Sl_std_string_Sc_double_Sg__erase__SWIG_1(std::map< std::string,double > self,std::map< std::string,double >::iterator position){ self->erase(position); }
5173:SWIGINTERN void std_map_Sl_std_string_Sc_double_Sg__erase__SWIG_2(std::map< std::string,double > self,std::map< std::string,double >::iterator first,std::map< std::string,double >::iterator last){ self->erase(first, last); }
6974: std_map_Sl_std_string_Sc_double_Sg__erase__SWIG_1(arg1,arg2);
7025: std_map_Sl_std_string_Sc_double_Sg__erase__SWIG_2(arg1,arg2,arg3);
8108: std_map_Sl_std_string_Sc_double_Sc_std_less_Sl_std_string_Sg__Sc_std_allocator_Sl_std_pair_Sl_std_string_SS_const_Sc_double_Sg__Sg__Sg__erase__SWIG_1((std::map< std::string,double,std::less< std::string >,std::allocator< std::pair< std::string const,double > > >)(arg1)->operator ->(),arg2);
8159: std_map_Sl_std_string_Sc_double_Sc_std_less_Sl_std_string_Sg__Sc_std_allocator_Sl_std_pair_Sl_std_string_SS_const_Sc_double_Sg__Sg__Sg__erase__SWIG_2((std::map< std::string,double,std::less< std::string >,std::allocator< std::pair< std::string const,double > > >*)(arg1)->operator ->(),arg2,arg3);
This is defect is not present in swig 2.0.11:
$ swig -version
SWIG Version 2.0.11
Compiled with g++ [i686-pc-linux-gnu]
Configured options: +pcre
Please see http://www.swig.org for reporting bugs and further information
$ swig -c++ -python -o wrappedmap.cpp wrappedmap.i && g++ -fPIC -c wrappedmap.cpp -I/usr/include/python2.7
$ ls
wrappedmap.cpp wrappedmap.i wrappedmap.o wrappedmap.py
Here is the compiler error and the grep output without formatting:
$ swig -c++ -python -o wrappedmap.cpp wrappedmap.i && g++ -fPIC -c wrappedmap.cpp -I/usr/include/python2.7wrappedmap.cpp: In function 'PyObject* _wrap_WrappedMap_erase__SWIG_1(PyObject*, PyObject*)':wrappedmap.cpp:8108:293: error: 'std_map_Sl_std_string_Sc_double_Sc_std_less_Sl_std_string_Sg__Sc_std_allocator_Sl_std_pair_Sl_std_string_SS_const_Sc_double_Sg__Sg__Sg__erase__SWIG_1' was not declared in this scopewrappedmap.cpp: In function 'PyObject* _wrap_WrappedMap_erase__SWIG_2(PyObject*, PyObject*)':wrappedmap.cpp:8159:298: error: 'std_map_Sl_std_string_Sc_double_Sc_std_less_Sl_std_string_Sg__Sc_std_allocator_Sl_std_pair_Sl_std_string_SS_const_Sc_double_Sg__Sg__Sg__erase__SWIG_2' was not declared in this scope$ grep -n --color std_map_Sl_std_string_.*_Sg__erase wrappedmap.cpp5172:SWIGINTERN void std_map_Sl_std_string_Sc_double_Sg__erase__SWIG_1(std::map< std::string,double > *self,std::map< std::string,double >::iterator position){ self->erase(position); }5173:SWIGINTERN void std_map_Sl_std_string_Sc_double_Sg__erase__SWIG_2(std::map< std::string,double > *self,std::map< std::string,double >::iterator first,std::map< std::string,double >::iterator last){ self->erase(first, last); }6974: std_map_Sl_std_string_Sc_double_Sg__erase__SWIG_1(arg1,arg2);7025: std_map_Sl_std_string_Sc_double_Sg__erase__SWIG_2(arg1,arg2,arg3);8108: std_map_Sl_std_string_Sc_double_Sc_std_less_Sl_std_string_Sg__Sc_std_allocator_Sl_std_pair_Sl_std_string_SS_const_Sc_double_Sg__Sg__Sg__erase__SWIG_1((std::map< std::string,double,std::less< std::string >,std::allocator< std::pair< std::string const,double > > >*)(arg1)->operator ->(),arg2);8159: std_map_Sl_std_string_Sc_double_Sc_std_less_Sl_std_string_Sg__Sc_std_allocator_Sl_std_pair_Sl_std_string_SS_const_Sc_double_Sg__Sg__Sg__erase__SWIG_2((std::map< std::string,double,std::less< std::string >,std::allocator< std::pair< std::string const,double > > >*)(arg1)->operator ->(),arg2,arg3);Your input code is complete junk. Use the 'Formatting Help' button to learn how to put the code into the bug tracker and edit your bug report.
I think the code that was posted looked like the following:
The problem is to do with erase which is overloaded in the definition of std::map including in a %extend. The bug comes about with std::map as it is a template with default arguments and the usage in a smart pointer.
Fixed for SWIG-3.0.0.
Yes, that was the code. I tried to format the code, and I am sure I posted it again ... but it does not seem so.