title: Is it ok to return a stack object for a CString and why /GR causes undefined behavior to dynamic_cast?
body: <p>I have polymorphic classes and I want to convert an object via <code>dynamic_cast&lt;B&gt;(A)</code> although with compiler optimization /GR I receive a message that it may cause undefined behavior. I'm using <code>static_cast</code> instead, but it does no run-time checks and is unsafe for my classes. Also is it valid to return a stack <code>CString</code> object from a class?</p>
  
  <pre><code>CString CKingdomWar::GetTeamName( eUserTeam eTeam )
  {
      if( eTeam == ELDAR )
          return CString( "Eldar" );
      else if( eTeam == ELWYN )
          return CString( "Elwyn" );
      else if( eTeam == NORGNAGON )
          return CString( "Norgnagon" );
  
      return CString( " " );
  }
  </code></pre>