Auto-detect non-assignable classes

Classes with references or const data are now marked as 'noassign'.
This renders many explicit `private: operator=` declarations redundant.
This commit is contained in:
Seth R Johnson 2019-02-14 07:18:33 -05:00
parent 073d144b0e
commit 03dd2ec39d
7 changed files with 11 additions and 14 deletions

View File

@ -35,7 +35,5 @@
const char memberconstchar;
virtual ~DirectorTest() {}
private:
DirectorTest& operator=(const DirectorTest &);
};
%}

View File

@ -62,8 +62,6 @@ struct BoolStructure {
m_rbool(m_bool2),
m_const_pbool(m_pbool),
m_const_rbool(m_rbool) {}
private:
BoolStructure& operator=(const BoolStructure &);
};
%}

View File

@ -53,8 +53,6 @@ public:
int* array_member1[ARRAY_SIZE];
ParametersTest* array_member2[ARRAY_SIZE];
MemberVariablesTest() : member3(NULL), member4(NULL) {}
private:
MemberVariablesTest& operator=(const MemberVariablesTest&);
};
void foofunction(const int *const i) {}
@ -80,8 +78,6 @@ public:
void ret8(int*const& a) {}
int*const& ret9() {return GlobalIntPtr;}
ReturnValuesTest() : int3(NULL) {}
private:
ReturnValuesTest& operator=(const ReturnValuesTest&);
};
const int* globalRet1() {return &GlobalInt;}
@ -113,8 +109,6 @@ int* const globalRet2() {return &GlobalInt;}
A* ap;
const A* cap;
Acptr acptr;
private:
B& operator=(const B&);
};
const B* bar(const B* b) {

View File

@ -74,8 +74,10 @@ class Bar {
Foo *testFoo(int a, Foo *f) {
return new Foo(2 * a + (f ? f->num : 0) + fval.num);
}
/* Const member data means this class can't be assigned.
private:
Bar& operator=(const Bar&);
*/
};
%}

View File

@ -89,8 +89,6 @@ struct SpeedClass {
const colour myColour2;
speedtd1 mySpeedtd1;
SpeedClass() : myColour2(red), mySpeedtd1(slow) { }
private:
SpeedClass& operator=(const SpeedClass&);
};
int speedTest0(int s) { return s; }

View File

@ -119,8 +119,6 @@ public:
void const_member_method(const ConstWithout *p) const {}
const ConstWithout * const_var;
const ConstWithout * const var_const;
private:
ConstWithout& operator=(const ConstWithout &);
};
const ConstWithout * global_constwithout = 0;
void global_method_constwithout(const ConstWithout *p) {}

View File

@ -779,6 +779,15 @@ Allocate():
if (Swig_storage_isstatic(n)) {
Setattr(n, "cplus:staticbase", inclass);
} else if (Cmp(Getattr(n, "kind"), "variable") == 0) {
/* Check member variable to determine whether assignment is valid */
if (GetFlag(n, "feature:immutable")) {
/* Can't assign a class with an immutable member variable */
Setattr(inclass, "allocate:noassign", "1");
} else if (SwigType_isreference(Getattr(n, "type"))) {
/* Can't assign a class with reference member data */
Setattr(inclass, "allocate:noassign", "1");
}
}
String *name = Getattr(n, "name");