Project

General

Profile

Defect #23

Updated by Tony Ciavarella over 3 years ago

Consider this: 

 <pre><code class="cpp"> 
 union A 
 { 
     disorder::utility::BitField<uint64_t, 0, 32> x; 
     disorder::utility::BitField<uint64_t, 32, 32> y; 
     uint64_t all; 
 }; 

 A a1, a2; 

 a1.x = 1; 
 a1.y = 2; 

 a2.x = a1.x; // this actually assigns all 64 bits of a1 to a2, not just the x 32-bits. 
 </code></pre> 

 Consider overriding the default operator= to make this behave more intuitively.    Overriding operator= will make BitField usage more complex because it will cause the move assignment operator, copy constructor, and move constructor to become non-trivial which will also bubble up to whatever data structures BitFields are used in. 

 Note that the above example can be made to do what is expected by writing it like this instead: 
 <pre><code class="cpp"> 
 a2.x = a1.x.get(); // this only assigns the x 32-bits of a1 to a2. 
 </code></pre>

Back