#1135 invalid parenthesis around template argument

closed-fixed
nobody
python (259)
5
2011-07-28
2011-02-24
Michel Zou
No

Hi,
Current swig (2.0.2) doesn't like this smart pointer pattern :

%module example

%inline %{

template <class T>
class SmartPointer
{
public:
inline const T * operator -> () const {}
inline T * operator -> () {}
};

class FooImplementation
{
public:
static void Bar();
};

%}

%template(FooImplementationSmartPointer) SmartPointer<FooImplementation>;

I get this error :
common_wrap.cpp: In function ‘PyObject* _wrap_FooImplementationSmartPointer_Bar(PyObject*, PyObject*)’:
common_wrap.cpp:2988: error: template argument 1 is invalid
common_wrap.cpp:2988: error: expected ‘)’ before ‘const’
common_wrap.cpp:2988: error: expected ‘)’ before ‘;’ token
make[1]: *** [_common_la-common_wrap.lo] Error 1

The following code is generated :
SWIGINTERN PyObject *_wrap_FooImplementationSmartPointer_Bar(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
SmartPointer< FooImplementation > *arg1 = (SmartPointer< FooImplementation > *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;

if (!PyArg_ParseTuple(args,(char *)"O:FooImplementationSmartPointer_Bar",&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_SmartPointerT_FooImplementation_t, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "FooImplementationSmartPointer_Bar" "', argument " "1"" of type '" "SmartPointer< FooImplementation > *""'");
}
arg1 = reinterpret_cast< SmartPointer< FooImplementation > * >(argp1);
(*(SmartPointer<(FooImplementation)> const *)arg1)->Bar();
resultobj = SWIG_Py_Void();
return resultobj;
fail:
return NULL;
}

We can see the following line is incorrect :
(*(SmartPointer<(FooImplementation)> const *)arg1)->Bar();

Regards.

Discussion

  • Michel Zou
    Michel Zou
    2011-02-24

    • labels: 505206 --> python
     
  • Michel Zou
    Michel Zou
    2011-07-28

    • status: open --> open-fixed
     
  • Michel Zou
    Michel Zou
    2011-07-28

    It has been fixed in 2.0.3

     
  • William Fulton
    William Fulton
    2011-07-28

    Closing

     
  • William Fulton
    William Fulton
    2011-07-28

    • status: open-fixed --> closed-fixed