title: Can reinterpret_cast<qintptr>(...) be negative?
body: <p>I have a class that is basis for representing hierarchical structure where the bottom object holds actual data:</p>
  
  <pre><code>class Data { };
  
  class Item
  {
  public:
      AItem(AItem *source = nullptr) : m_Data(source ? reinterpret_cast&lt;qintptr&gt;(source) : -reinterpret_cast&lt;qintptr&gt;(new Data)) {}
      virtual ~AItem() { if(m_Data &lt; 0) delete reinterpret_cast&lt;AData*&gt;(-m_Data); }
  
      qintptr id() const { return m_Data; }
      Data *data() const { return m_Data &lt; 0 ? reinterpret_cast&lt;AData*&gt;(-m_Data) : reinterpret_cast&lt;AItem*&gt;(m_Data)-&gt;data(); }
  
  private:
      qintptr m_Data;
  };
  </code></pre>
  
  <p>Notice that when no "source" is set in the constructor I create new object of <code>Data</code>, reinterpret it as integer, <strong>negate it</strong> and then save it to m_Data. This is crucial as it is used when getting the <code>Data</code> object from the hierarchy in <code>data()</code> and of course in the destructor.</p>
  
  <p>However this might be a dangerous hack because it relies on both <code>reinterpret_cast&lt;qintptr&gt;(source)</code> and <code>reinterpret_cast&lt;qintptr&gt;(new Data)</code> never to produce negative integer. Could they?</p>
  
  <p>If they could (and I think they could but I cannot find definitive answer) I will have to add boolean flag to check if the item is base object or not.</p>