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:
parent
073d144b0e
commit
03dd2ec39d
7 changed files with 11 additions and 14 deletions
|
|
@ -35,7 +35,5 @@
|
||||||
const char memberconstchar;
|
const char memberconstchar;
|
||||||
|
|
||||||
virtual ~DirectorTest() {}
|
virtual ~DirectorTest() {}
|
||||||
private:
|
|
||||||
DirectorTest& operator=(const DirectorTest &);
|
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -62,8 +62,6 @@ struct BoolStructure {
|
||||||
m_rbool(m_bool2),
|
m_rbool(m_bool2),
|
||||||
m_const_pbool(m_pbool),
|
m_const_pbool(m_pbool),
|
||||||
m_const_rbool(m_rbool) {}
|
m_const_rbool(m_rbool) {}
|
||||||
private:
|
|
||||||
BoolStructure& operator=(const BoolStructure &);
|
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,6 @@ public:
|
||||||
int* array_member1[ARRAY_SIZE];
|
int* array_member1[ARRAY_SIZE];
|
||||||
ParametersTest* array_member2[ARRAY_SIZE];
|
ParametersTest* array_member2[ARRAY_SIZE];
|
||||||
MemberVariablesTest() : member3(NULL), member4(NULL) {}
|
MemberVariablesTest() : member3(NULL), member4(NULL) {}
|
||||||
private:
|
|
||||||
MemberVariablesTest& operator=(const MemberVariablesTest&);
|
|
||||||
};
|
};
|
||||||
void foofunction(const int *const i) {}
|
void foofunction(const int *const i) {}
|
||||||
|
|
||||||
|
|
@ -80,8 +78,6 @@ public:
|
||||||
void ret8(int*const& a) {}
|
void ret8(int*const& a) {}
|
||||||
int*const& ret9() {return GlobalIntPtr;}
|
int*const& ret9() {return GlobalIntPtr;}
|
||||||
ReturnValuesTest() : int3(NULL) {}
|
ReturnValuesTest() : int3(NULL) {}
|
||||||
private:
|
|
||||||
ReturnValuesTest& operator=(const ReturnValuesTest&);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const int* globalRet1() {return &GlobalInt;}
|
const int* globalRet1() {return &GlobalInt;}
|
||||||
|
|
@ -113,8 +109,6 @@ int* const globalRet2() {return &GlobalInt;}
|
||||||
A* ap;
|
A* ap;
|
||||||
const A* cap;
|
const A* cap;
|
||||||
Acptr acptr;
|
Acptr acptr;
|
||||||
private:
|
|
||||||
B& operator=(const B&);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const B* bar(const B* b) {
|
const B* bar(const B* b) {
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,10 @@ class Bar {
|
||||||
Foo *testFoo(int a, Foo *f) {
|
Foo *testFoo(int a, Foo *f) {
|
||||||
return new Foo(2 * a + (f ? f->num : 0) + fval.num);
|
return new Foo(2 * a + (f ? f->num : 0) + fval.num);
|
||||||
}
|
}
|
||||||
|
/* Const member data means this class can't be assigned.
|
||||||
private:
|
private:
|
||||||
Bar& operator=(const Bar&);
|
Bar& operator=(const Bar&);
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -89,8 +89,6 @@ struct SpeedClass {
|
||||||
const colour myColour2;
|
const colour myColour2;
|
||||||
speedtd1 mySpeedtd1;
|
speedtd1 mySpeedtd1;
|
||||||
SpeedClass() : myColour2(red), mySpeedtd1(slow) { }
|
SpeedClass() : myColour2(red), mySpeedtd1(slow) { }
|
||||||
private:
|
|
||||||
SpeedClass& operator=(const SpeedClass&);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int speedTest0(int s) { return s; }
|
int speedTest0(int s) { return s; }
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,6 @@ public:
|
||||||
void const_member_method(const ConstWithout *p) const {}
|
void const_member_method(const ConstWithout *p) const {}
|
||||||
const ConstWithout * const_var;
|
const ConstWithout * const_var;
|
||||||
const ConstWithout * const var_const;
|
const ConstWithout * const var_const;
|
||||||
private:
|
|
||||||
ConstWithout& operator=(const ConstWithout &);
|
|
||||||
};
|
};
|
||||||
const ConstWithout * global_constwithout = 0;
|
const ConstWithout * global_constwithout = 0;
|
||||||
void global_method_constwithout(const ConstWithout *p) {}
|
void global_method_constwithout(const ConstWithout *p) {}
|
||||||
|
|
|
||||||
|
|
@ -779,6 +779,15 @@ Allocate():
|
||||||
|
|
||||||
if (Swig_storage_isstatic(n)) {
|
if (Swig_storage_isstatic(n)) {
|
||||||
Setattr(n, "cplus:staticbase", inclass);
|
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");
|
String *name = Getattr(n, "name");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue