title: trouble with std::codecvt_utf8 facet
body: <p>Here is a snippet of a code that is using <code>std::codecvt_utf8&lt;&gt;</code> facet to convert from <code>wchar_t</code> to UTF-8. With Visual Studio 2012, my expectations are not met (see the condition at the end of the code). Are my expectations wrong? Why? Or is this a Visual Studio 2012 library issue?</p>
  
  <pre><code>#include &lt;locale&gt;
  #include &lt;codecvt&gt;
  #include &lt;cstdlib&gt;
  
  int main ()
  {
      std::mbstate_t state = std::mbstate_t ();
      std::locale loc (std::locale (), new std::codecvt_utf8&lt;wchar_t&gt;);
      typedef std::codecvt&lt;wchar_t, char, std::mbstate_t&gt; codecvt_type;
      codecvt_type const &amp; cvt = std::use_facet&lt;codecvt_type&gt; (loc);
  
      wchar_t ch = L'\u5FC3';
      wchar_t const * from_first = &amp;ch;
      wchar_t const * from_mid = &amp;ch;
      wchar_t const * from_end = from_first + 1;
  
      char out_buf[1];
      char * out_first = out_buf;
      char * out_mid = out_buf;
      char * out_end = out_buf + 1;
  
      std::codecvt_base::result cvt_res
          = cvt.out (state, from_first, from_end, from_mid,
              out_first, out_end, out_mid);
  
      // This is what I expect:
      if (cvt_res == std::codecvt_base::partial
          &amp;&amp; out_mid == out_end
          &amp;&amp; state != 0)
          ;
      else
          abort ();
  }
  </code></pre>
  
  <p>The expectation here is that the <code>out()</code> function output one byte of the UTF-8 conversion at a time but the middle of the <code>if</code> conditional above is false with Visual Studio 2012.</p>
  
  <h1>UPDATE</h1>
  
  <p>What fails is the <code>out_mid == out_end</code> and <code>state != 0</code> conditions. Basically, I expect at least one byte to be produced and the necessary state, for next byte of the UTF-8 sequence to be producible, to be stored in the <code>state</code> variable.</p>