You can run into this warning if you have a %rename
directive that appears before a %template
directive for instantiating a function like so:
%module some_module
%rename("%(undercase)s", %$isfunction) "";
// equivalently %rename("%(utitle)s", %$isfunction) "";
%inline %{
template<class T>
void MyFunction(){}
%}
// ...
%template(MyIntFunction) MyFunction<int>;
warning 503: Can't wrap 'my_function< int >' unless renamed to a valid identifier
And you cannot try to anticipate the rename in your %template
:
%template(MyIntFunction) my_function<int>;
Because then you'll get
error : Template 'myfunction' undefined.
Which is very frustrating if you're applying global renaming rules, and you really only need to "ignore renaming" for just a few things. Unlike typemaps, rename directives live for all-time. It'd be nice to be able to turn them off, even temporarily.
The only workaround for this I've come up with is to go back to the %rename
and update it to explicitly only match (or rather, not match) the template functions you've declared inline. Like so:
// don't rename functions starting with "MyFunction"
%rename("%(undercase)s", %$isfunction, notregexmatch$name="^MyFunction") "";
It's not perfect, but it's a workaround.
(This was all done in SWIG 4.0)