File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -61,13 +61,25 @@ Type&
61
61
Type::operator =(const Type& rhs)
62
62
{
63
63
// The operation sequence handles self-assignment
64
- rhs.p ->use ++;
65
- if (--p->use == 0 )
64
+ if (rhs. p ) rhs.p ->use ++;
65
+ if (p && --p->use == 0 )
66
66
delete p;
67
67
p = rhs.p ;
68
68
return (*this );
69
69
}
70
70
71
+ // Move assignment
72
+ Type&
73
+ Type::operator =(Type&& rhs) noexcept {
74
+ if (this != &rhs) {
75
+ if (p && --p->use == 0 )
76
+ delete p;
77
+ p = rhs.p ;
78
+ rhs.p = nullptr ;
79
+ }
80
+ return *this ;
81
+ }
82
+
71
83
Type
72
84
Type_node::subscript () const
73
85
{
Original file line number Diff line number Diff line change @@ -235,7 +235,7 @@ class Type {
235
235
Type_node *p;
236
236
public:
237
237
Type (Type_node *n) : p(n) {}
238
- Type () { p = new Tbasic (b_undeclared); }
238
+ Type () : p( new Tbasic(b_undeclared)) { }
239
239
// Creation functions
240
240
friend Type basic (enum e_btype t, enum e_sign s,
241
241
enum e_storage_class sc, qualifiers_t );
@@ -259,9 +259,13 @@ class Type {
259
259
void declare ();
260
260
261
261
// Manage use count of underlying Type_node
262
- Type (const Type& t) : p(t.p) { ++p->use ; } // Copy
263
- ~Type () { if (--p->use == 0 ) delete p; }
262
+ Type (const Type& t) : p(t.p) { if (p) ++p->use ; } // Copy
263
+ ~Type () { if (p && --p->use == 0 ) delete p; }
264
264
Type& operator =(const Type& t);
265
+ // Move constructor
266
+ Type (Type&& t) noexcept : p(t.p) { t.p = nullptr ; }
267
+ // Move assignment
268
+ Type& operator =(Type&& rhs) noexcept ;
265
269
266
270
// Interface to the Type_node functionality
267
271
Type clone () const { return p->clone (); }
You can’t perform that action at this time.
0 commit comments