title: How can boost::asio::buffer_cast violate type-safety?
body: <p>Comments are sprinkled throughout <a href="https://github.com/boostorg/asio/blob/9bfe806fc1d2a51c97b433571f42b83606a28b05/include/boost/asio/buffer.hpp#L89" rel="nofollow noreferrer">boost::asio</a> that say this:</p>
  
  <blockquote>
    <p>The boost::asio::buffer_cast function permits violations of type
    safety, so uses of it in application code should be carefully
    considered.</p>
  </blockquote>
  
  <p>However, ultimately what the buffer interface boils down to is this:</p>
  
  <pre><code>struct buffer {
    void *data;
  
    friend void* cast_helper(const buffer&amp; b);
  };
  
  void* cast_helper(const buffer&amp; b) {
    return b.data;
  }
  
  template &lt;typename to_t&gt;
  to_t buffer_cast(const buffer&amp; b) {
    return static_cast&lt;to_t&gt;(cast_helper(b));
  }
  </code></pre>
  
  <p><code>static_cast</code> a <code>void*</code> to a pointer type is well-defined and considered the appropriate thing to do for <code>void*</code> data (see "Should I use static_cast or reinterpret_cast when casting a void* to whatever"). So what does it mean by violating type-safety?</p>