mirror of https://github.com/swig/swig
C++11 deleted destructors fixes
Fix problems wrapping deleted destructors. Derived classes are not constructible, so don't attempt to generate default constructor or copy constructor wrappers. struct StackOnly1 { // Only constructible on the stack ~StackOnly1() = delete; }; struct StackOnlyDerived1 : StackOnly1 { // this class is not constructible due to deleted base destructor };
This commit is contained in:
parent
1f8d4f8eb0
commit
bf330ba524
|
@ -7,6 +7,19 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.2.0 (in progress)
|
||||
===========================
|
||||
|
||||
2023-09-02: wsfulton
|
||||
Fix problems wrapping deleted destructors. Derived classes are not
|
||||
constructible, so don't attempt to generate default constructor or
|
||||
copy constructor wrappers.
|
||||
|
||||
struct StackOnly1 {
|
||||
// Only constructible on the stack
|
||||
~StackOnly1() = delete;
|
||||
};
|
||||
struct StackOnlyDerived1 : StackOnly1 {
|
||||
// this class is not constructible due to deleted base destructor
|
||||
};
|
||||
|
||||
2023-09-02: wsfulton
|
||||
Fix %copyctor feature when used on classes with deleted copy constructors.
|
||||
A default constructor wrapper was sometimes incorrectly generated.
|
||||
|
|
|
@ -67,6 +67,17 @@ private:
|
|||
DeletedPrivate5() = default;
|
||||
DeletedPrivate5(const DeletedPrivate5&) = delete;
|
||||
};
|
||||
|
||||
struct StackOnly1 {
|
||||
// Only constructible on the stack
|
||||
~StackOnly1() = delete;
|
||||
};
|
||||
struct StackOnlyDerived1 : StackOnly1 {
|
||||
// this class is not constructible due to deleted base destructor
|
||||
};
|
||||
struct StackOnlyDerivedMore1 : StackOnlyDerived1 {
|
||||
// this class is not constructible due to deleted base destructor
|
||||
};
|
||||
%}
|
||||
|
||||
// copyctor feature turned on
|
||||
|
@ -143,4 +154,15 @@ private:
|
|||
CopyCtorDeletedPrivate5() = default;
|
||||
CopyCtorDeletedPrivate5(const CopyCtorDeletedPrivate5&) = delete;
|
||||
};
|
||||
|
||||
struct CopyCtorStackOnly1 {
|
||||
// Only constructible on the stack
|
||||
~CopyCtorStackOnly1() = delete;
|
||||
};
|
||||
struct CopyCtorStackOnlyDerived1 : CopyCtorStackOnly1 {
|
||||
// this class is not constructible due to deleted base destructor
|
||||
};
|
||||
struct CopyCtorStackOnlyDerivedMore1 : CopyCtorStackOnlyDerived1 {
|
||||
// this class is not constructible due to deleted base destructor
|
||||
};
|
||||
%}
|
||||
|
|
|
@ -22,5 +22,8 @@ public class cpp11_copyctor_delete_runme {
|
|||
new DeletedPublic5();
|
||||
new CopyCtorDeletedPublic4();
|
||||
new CopyCtorDeletedPublic5();
|
||||
|
||||
new StackOnly1();
|
||||
new CopyCtorStackOnly1(new CopyCtorStackOnly1());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -778,6 +778,10 @@ Allocate():
|
|||
if (!Getattr(n, "allocate:default_constructor") && (!Getattr(n, "allocate:default_base_constructor"))) {
|
||||
allows_default = 0;
|
||||
}
|
||||
/* not constructible if base destructor is deleted */
|
||||
if (Getattr(n, "allocate:deleted_default_destructor")) {
|
||||
allows_default = 0;
|
||||
}
|
||||
}
|
||||
if (allows_default) {
|
||||
Setattr(n, "allocate:default_constructor", "1");
|
||||
|
@ -804,6 +808,10 @@ Allocate():
|
|||
if (!Getattr(n, "allocate:copy_constructor") && (!Getattr(n, "allocate:copy_base_constructor"))) {
|
||||
allows_copy = 0;
|
||||
}
|
||||
/* not constructible if base destructor is deleted */
|
||||
if (Getattr(n, "allocate:deleted_default_destructor")) {
|
||||
allows_copy = 0;
|
||||
}
|
||||
if (Getattr(n, "allocate:copy_constructor_non_const") || (Getattr(n, "allocate:copy_base_constructor_non_const"))) {
|
||||
must_be_copy_non_const = 1;
|
||||
}
|
||||
|
@ -820,18 +828,22 @@ Allocate():
|
|||
|
||||
if (!Getattr(n, "allocate:has_destructor")) {
|
||||
/* No destructor was defined */
|
||||
List *bases = Getattr(n, "allbases");
|
||||
int allows_destruct = 1;
|
||||
/* No destructor if the destructor is declared as deleted */
|
||||
if (!GetFlag(n, "allocate:deleted_default_destructor")) {
|
||||
/* Check base classes */
|
||||
List *bases = Getattr(n, "allbases");
|
||||
int allows_destruct = 1;
|
||||
|
||||
for (int i = 0; i < Len(bases); i++) {
|
||||
Node *n = Getitem(bases, i);
|
||||
/* If base class does not allow default destructor, we don't allow it either */
|
||||
if (!Getattr(n, "allocate:default_destructor") && (!Getattr(n, "allocate:default_base_destructor"))) {
|
||||
allows_destruct = 0;
|
||||
for (int i = 0; i < Len(bases); i++) {
|
||||
Node *n = Getitem(bases, i);
|
||||
/* If base class does not allow default destructor, we don't allow it either */
|
||||
if (!Getattr(n, "allocate:default_destructor") && (!Getattr(n, "allocate:default_base_destructor"))) {
|
||||
allows_destruct = 0;
|
||||
}
|
||||
}
|
||||
if (allows_destruct) {
|
||||
Setattr(n, "allocate:default_destructor", "1");
|
||||
}
|
||||
}
|
||||
if (allows_destruct) {
|
||||
Setattr(n, "allocate:default_destructor", "1");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1309,19 +1321,26 @@ Allocate():
|
|||
(void) n;
|
||||
if (!inclass)
|
||||
return SWIG_OK;
|
||||
if (!extendmode) {
|
||||
Setattr(inclass, "allocate:has_destructor", "1");
|
||||
if (cplus_mode == PUBLIC) {
|
||||
|
||||
if (!GetFlag(n, "deleted")) {
|
||||
if (!extendmode) {
|
||||
Setattr(inclass, "allocate:has_destructor", "1");
|
||||
if (cplus_mode == PUBLIC) {
|
||||
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");
|
||||
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");
|
||||
Setattr(inclass, "allocate:default_destructor", "1");
|
||||
if (!extendmode)
|
||||
SetFlag(inclass, "allocate:deleted_default_destructor");
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue