NB. This may be in the C++ parser rather than anything Python-specific, but I've only tested in Python.
I've been trying to hide a C++ operator<< function (2 args unbound, i.e. not a class method) using the SWIG %ignore directive. It seems that if this stream function is declared as a friend in the class to be streamed, inside a namespace, then the %ignore matching fails, even in the case of an exact textual match. Here's an example hepmc.i file, with the C++ code to be mapped represented inline:
-----
%module hepmc
// These don't work:
namespace HepMC {
%ignore operator<<;
%ignore operator<<(std::ostream&, const GenParticle&);
}
%ignore HepMC::operator<<;
%ignore HepMC::operator<<(std::ostream&, const GenParticle&);
// This works:
//%ignore operator<<;
//%ignore operator<<(std::ostream&, const GenParticle&);
/////////////////////////////////////////
// Equiv to: %include "HepMC/GenParticle.h"
namespace HepMC {
class GenParticle {
// [...]
friend std::ostream& operator<<( std::ostream&, const GenParticle& );
};
std::ostream& operator<<( std::ostream& os, const GenParticle& gp) {
os << gp.foo();
return os;
}
}
/////////////////////////////////////////
-----
The above results in an error " Warning(503): Can't wrap 'operator <<' unless renamed to a valid identifier." referring specifically to the friend statement, unless the "coarse match" %ignores under the "This works" comment are included. The equivalent %ignores which are specific, one way or another, about the namespace don't match the operator<< referred to in the friend statement.
Note that this bug seems to be specific to the friend statement --- if you remove the friend declaration in GenParticle, the %ignore works properly.
Reproducible with current git master.
Fixed by a6ab9145115aa124ff9c98e2b3c39fde9f205760.
All 6 of the %ignore directives shown now work.