Hello,
Say I have this config setup:
class Base1
{
public:
Base1();
}
class Base2
{
public:
Base2();
protected:
Base2(Base1& other); // copyctor
}
class Derived : public Base1, public Base2
{
public:
Derived();
};
If I try to swig this code with -copyctor enabled, then
SWIG will generate a call to the copy constructor of
Derived. However, Derived does not have a copy
constructor, so this leads to a compilation error.
-Matthias
I checked this with trunk r12766 and it seems it's since been fixed. I had to add ";" after "}" for the first two classes, then wrap the snippet in %inline { [...] }, saved as 1485859.i, then processed with:
./preinst-swig -copyctor -python -c++ -module tmp 1485859.i
g++ -fPIC -I /usr/include/python2.6 -Wall -W -shared -o tmp.so 1485859_wrap.cxx
The generated code from the testcase as shown does indeed compile under g++-4.4.3 for swig-1.3.31 and 2.0.4. Looks like there is a mistake in the original code. If
Base2(Base1& other); // copyctor
is replaced with
Base2(Base2& other); // non-const copyctor
then a copy constructor is generated resulting in a compiler error in the wrappers:
example_wrap.cxx:327: error: no matching function for call to ‘Derived::Derived(const Derived&)’
example_wrap.cxx:231: note: candidates are: Derived::Derived()
example_wrap.cxx:229: note: Derived::Derived(Derived&)
Still fails with current git master (7ab24e7e865e0f1281f002fefdaba11b80416ea2), though the error now seems to be slightly different:
Reproduced with 8a24c19d2621e0de6a4429a039dc75d3a761acd4.
Reproduced with 595009cf2ff952d963a663113e82b032c4fa770f.
Reproduced with 5e1a37c6c562b7cb62c62e439c5b6b647e6d6df5 (retested because that commit fixes a copyctor bug).
This bug is a problem with non-const copy constructors in an inheritance chain. SWIG always assumed the implicit copy constructor was defined with a const reference parameter. For reference, https://en.cppreference.com/w/cpp/language/copy_constructor outlines nicely when the implicit constructor uses a const or non-const reference parameter.
Fixed in 74e1deef6bd86135ee2a5f007b6347202813d143.