57
64
Tree ()->NodeName () == CT_UnionDef::NodeId ());
67
/** Yields true if the class has a trivial copy assignment operator. */
68
bool CRecord::hasTrivialAssign () const {
70
// A copy assignment operator for class X is trivial if it is implicitly declared and if:
71
// — class X has no virtual functions (10.3) and no virtual base classes (10.1), and
72
// — each direct base class of X has a trivial copy assignment operator, and
73
// — for all the nonstatic data members of X that are of class type (or array thereof),
74
// each such class type has a trivial copy assignment operator.
75
bool oper_found = false;
76
unsigned i, num = Functions ();
77
for (i = 0; i < num; i++) {
78
CFunctionInfo* mf = Function (i);
82
// implicit assignment operator
83
if (! oper_found && mf->isBuiltin () && mf->isCopyAssignOperator ())
86
// no implicit assignment operator found
90
// check if base classes have a trivial assignment operator and are not virtual
91
CClassInfo* c = ClassInfo ();
92
num = c ? c->BaseClasses () : 0;
93
for (i = 0; i < num; i++) {
94
CBaseClassInfo* bc = c->BaseClass (i);
95
if (bc->isVirtual () || ! bc->Class ()->hasTrivialAssign ())
99
// check non-static data members
101
for (i = 0; i < num; i++) {
102
CAttributeInfo* ai = Attribute (i);
103
if (! ai->isStatic ()) {
104
CTypeInfo* type = ai->TypeInfo ();
105
// get underlying type of array
106
while (type->isArray ())
107
type = type->VirtualType ()->BaseType ();
108
// check if data member has trivial assignment operator
109
if (type->isClassOrUnion ()) {
110
CTypeRecord* tr = type->VirtualType ()->TypeRecord ();
111
if (tr && tr->Record () && ! tr->Record ()->hasTrivialAssign ()) {
112
// data member with non-trivial assignment operator found
121
/** Yields true if the class has a trivial copy constructor. */
122
bool CRecord::hasTrivialCopy () const {
124
// A copy constructor for class X is trivial if it is implicitly declared and if:
125
// — class X has no virtual functions (10.3) and no virtual base classes (10.1), and
126
// — each direct base class of X has a trivial copy constructor, and
127
// — for all the non-static data members of X that are of class type (or array thereof),
128
// each such class type has trivial copy constructor.
129
bool ctor_found = false;
130
unsigned i, num = Functions ();
131
for (i = 0; i < num; i++) {
132
CFunctionInfo* mf = Function (i);
134
if (mf->isVirtual ())
136
// implicit copy constructor
137
if (! ctor_found && mf->isBuiltin () && mf->isCopyConstructor ())
140
// no implicit default ctor found
144
// check if base classes have a trivial copy constructor and are not virtual
145
CClassInfo* c = ClassInfo ();
146
num = c ? c->BaseClasses () : 0;
147
for (i = 0; i < num; i++) {
148
CBaseClassInfo* bc = c->BaseClass (i);
149
if (bc->isVirtual () || ! bc->Class ()->hasTrivialCopy ())
153
// check non-static data members
155
for (i = 0; i < num; i++) {
156
CAttributeInfo* ai = Attribute (i);
157
if (! ai->isStatic ()) {
158
CTypeInfo* type = ai->TypeInfo ();
159
// get underlying type of array
160
while (type->isArray ())
161
type = type->VirtualType ()->BaseType ();
162
// check if data member has trivial copy ctor
163
if (type->isClassOrUnion ()) {
164
CTypeRecord* tr = type->VirtualType ()->TypeRecord ();
165
if (tr && tr->Record () && ! tr->Record ()->hasTrivialCopy ()) {
166
// data member with non-trivial copy constructor found
175
/** Yields true if the class has a trivial default constructor. */
176
bool CRecord::hasTrivialCtor () const {
178
// A constructor is trivial if it is an implicitly-declared default constructor and if:
179
// — its class has no virtual functions (10.3) and no virtual base classes (10.1), and
180
// — all the direct base classes of its class have trivial constructors, and
181
// — for all the nonstatic data members of its class that are of class type (or array
182
// thereof), each such class has a trivial constructor.
183
bool ctor_found = false;
184
unsigned i, num = Functions ();
185
for (i = 0; i < num; i++) {
186
CFunctionInfo* mf = Function (i);
188
if (mf->isVirtual ())
190
// implicit default constructor
191
if (! ctor_found && mf->isBuiltin () && mf->isDefaultConstructor ())
194
// no implicit default ctor found
198
// check if base classes have a trivial constructor and are not virtual
199
CClassInfo* c = ClassInfo ();
200
num = c ? c->BaseClasses () : 0;
201
for (i = 0; i < num; i++) {
202
CBaseClassInfo* bc = c->BaseClass (i);
203
if (bc->isVirtual () || ! bc->Class ()->hasTrivialCtor ())
207
// check non-static data members
209
for (i = 0; i < num; i++) {
210
CAttributeInfo* ai = Attribute (i);
211
if (! ai->isStatic ()) {
212
CTypeInfo* type = ai->TypeInfo ();
213
// get underlying type of array
214
while (type->isArray ())
215
type = type->VirtualType ()->BaseType ();
216
// check if data member has trivial ctor
217
if (type->isClassOrUnion ()) {
218
CTypeRecord* tr = type->VirtualType ()->TypeRecord ();
219
if (tr && tr->Record () && ! tr->Record ()->hasTrivialCtor ()) {
220
// data member with non-trivial constructor found
229
/** Yields true if the class has a trivial destructor. */
230
bool CRecord::hasTrivialDtor () const {
232
// A destructor is trivial if it is an implicitly-declared destructor and if:
233
// — all of the direct base classes of its class have trivial destructors and
234
// — for all of the non-static data members of its class that are of class type
235
// (or array thereof), each such class has a trivial destructor.
236
unsigned i, num = Functions ();
237
for (i = 0; i < num; i++) {
238
CFunctionInfo* mf = Function (i);
239
if (mf->isDestructor () && mf->isBuiltin ())
242
// no implicit destructor found
246
// check if base classes have a trivial destructor
247
CClassInfo* c = ClassInfo ();
248
num = c ? c->BaseClasses () : 0;
249
for (i = 0; i < num; i++)
250
if (! c->BaseClass (i)->Class ()->hasTrivialDtor ())
253
// check non-static data members
255
for (i = 0; i < num; i++) {
256
CAttributeInfo* ai = Attribute (i);
257
if (! ai->isStatic ()) {
258
CTypeInfo* type = ai->TypeInfo ();
259
// get underlying type of array
260
while (type->isArray ())
261
type = type->VirtualType ()->BaseType ();
262
// check if data member has trivial dtor
263
if (type->isClassOrUnion ()) {
264
CTypeRecord* tr = type->VirtualType ()->TypeRecord ();
265
if (tr && tr->Record () && ! tr->Record ()->hasTrivialDtor ()) {
266
// data member with non-trivial destructor found
61
276
} // namespace Puma