Don't generate constructor wrappers if a base class has a private constructor

g++-5 errors out with this now with errors such as:

default_constructor_wrap.cxx:665:27: error: use of deleted function ‘FFF::FFF()’
   result = (FFF *)new FFF();
                           ^
default_constructor_wrap.cxx:314:7: note: ‘FFF::FFF()’ is implicitly deleted because the default definition would be ill-formed:
 class FFF : public F {
       ^
default_constructor_wrap.cxx:301:4: error: ‘F::~F()’ is private
    ~F() { }
    ^
default_constructor_wrap.cxx:314:7: error: within this context
This commit is contained in:
William S Fulton 2015-07-07 20:15:55 +01:00
commit 3718b810c7
13 changed files with 45 additions and 72 deletions

View file

@ -941,6 +941,8 @@ Allocate():
Setattr(inclass, "allocate:default_destructor", "1");
} else if (cplus_mode == PROTECTED) {
Setattr(inclass, "allocate:default_base_destructor", "1");
} else if (cplus_mode == PRIVATE) {
Setattr(inclass, "allocate:private_destructor", "1");
}
} else {
Setattr(inclass, "allocate:has_destructor", "1");

View file

@ -3676,14 +3676,26 @@ int Language::abstractClassTest(Node *n) {
return 0;
if (Getattr(n, "allocate:nonew"))
return 1;
// A class cannot be instantiated if one of its bases has a private destructor
// Note that if the above does not hold the class can be instantiated if its own destructor is private
List *bases = Getattr(n, "bases");
if (bases) {
for (int i = 0; i < Len(bases); i++) {
Node *b = Getitem(bases, i);
if (GetFlag(b, "allocate:private_destructor"))
return 1;
}
}
/* now check for the rest */
List *abstracts = Getattr(n, "abstracts");
if (!abstracts)
return 0;
int labs = Len(abstracts);
#ifdef SWIG_DEBUG
List *bases = Getattr(n, "allbases");
Printf(stderr, "testing %s %d %d\n", Getattr(n, "name"), labs, Len(bases));
List *allbases = Getattr(n, "allbases");
Printf(stderr, "testing %s %d %d\n", Getattr(n, "name"), labs, Len(allbases));
#endif
if (!labs)
return 0; /*strange, but need to be fixed */