title: How can I workaround this Visual Studio compiler BUG?
body: <p>This is the "famous" /vd2 bug in visual studio, more information ex.:
  <a href="http://mcdougalljonathan.blogspot.com/2011/12/visual-c-2010-stdistringstream-crash-in.html" rel="nofollow">http://mcdougalljonathan.blogspot.com/2011/12/visual-c-2010-stdistringstream-crash-in.html</a>
  or google for "visual studio vd2 gtkmm" keywords..</p>
  
  <p>So I have to produce a release with a code that have a lot of these pattern below with VS2010. Looks like impossible, I have 10 days left. Any idea?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  
  struct Object
  {
    virtual ~Object() {}
  };
  
  struct Base: virtual public Object
  {
    Base() :Object()
    {
      // upcast and downcast
      Object* o = static_cast&lt;Object*&gt;(this);
      Base*   b = dynamic_cast&lt;Base*&gt;(o);
      std::cout &lt;&lt; "  this: " &lt;&lt; this &lt;&lt; " after cast: " &lt;&lt; b;
      // should be the same address
      if ( this != b)
        std::cout &lt;&lt; " check address: NOK";
      else
        std::cout &lt;&lt; " check address: OK ";
    }
  };
  
  struct Derived: public Base
  {
    int i;
  };
  
  int main()
  {
    Derived d;
    std::cout &lt;&lt; " end arrived: ";
    std::stringstream* ss = new std::stringstream;
    delete ss;
    std::cout &lt;&lt; "OK";
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have an idea... So I want to replace every std::stream to a wrapper, for ex. std2::stream, where I dynamically allocate them to a smart ptr, and I compile that wrapper implementation without the /vd2 switch. I will try it on next day...</p>
  
  <p>So I want something like this</p>
  
  <pre><code>// compile without /vd2
  #include &lt;sstream&gt;
  #include &lt;iostream&gt;
  #include &lt;boost/scoped_ptr.hpp&gt;
  
  namespace std2
  {
      class stringstream
      {
          public:
              stringstream()
              {
                  m_stream.reset(new std::stringstream);
              }
              template&lt;typename T&gt;
              std::stringstream&amp; operator&lt;&lt;(const T&amp; param)
              {
                  *m_stream &lt;&lt; param;
                  return *m_stream;
              }
  
              std::string str() const
              { return m_stream-&gt;str(); }
          private:
              boost::scoped_ptr&lt;std::stringstream&gt; m_stream;
  
      };
  }
  
  int main()
  {
      std2::stringstream stream;
      stream &lt;&lt; "DDDD" &lt;&lt; std::endl;
      std::cout &lt;&lt; stream.str() &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>