title: Why overlap in an assignment expression must be exact and the objects must have the same type, and what does it mean?
body: <p>Browsing through <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1705r1.html?" rel="nofollow noreferrer">Enumeration of Core Undefined Behavior</a>, I stumbled upon the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1705r1.html?fbclid=IwAR1kYRaUXdk2MuAm9BNgy4pIAvUzfdmbAIM2TSw6OpSAhcQ_BFpQb2aWsjs#exprass" rel="nofollow noreferrer">[expr.ass] case</a>. An example is given:</p>
  <pre><code>int x = 1;
  char* c = reinterpret_cast&lt;char*&gt;(&amp;x);
  x = *c;
  </code></pre>
  <p>What exactly is wrong with this code? Is it because it accesses <code>x</code> on both sides of the operand, but one of them is via aliasing pointer? Would this fix:</p>
  <pre><code>int x = 1;
  char* c = reinterpret_cast&lt;char*&gt;(&amp;x);
  int y = *c;
  x = y;
  </code></pre>
  <p>Be sufficient, then? If not, is it actually illegal to access <em>any parts</em> of an object via <code>char*</code> (assuming that object's <code>sizeof</code> is greater than <code>char</code>'s, for the sake of keepig the &quot;<em>parts</em>&quot; part)? If yes, how come serialization to binary works, since it relies on aliasing a given object with (possibly cv-qualified) <code>char*</code>, followed by pushing (which requires dereferencing, similarily to above example) separate bytes to a stream?</p>