title: C++ utf-8 literals in GCC and MSVC
body: <p>Here i have some simple code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdint&gt;
  
      int main()
      {
           const unsigned char utf8_string[] = u8&quot;\xA0&quot;;
           std::cout &lt;&lt; std::hex &lt;&lt; &quot;Size: &quot; &lt;&lt; sizeof(utf8_string) &lt;&lt; std::endl;
            for (int i=0; i &lt; sizeof(utf8_string); i++) {
              std::cout &lt;&lt; std::hex &lt;&lt; (uint16_t)utf8_string[i] &lt;&lt; std::endl;
            }
      }
  </code></pre>
  <p>I see different behavior here with MSVC and GCC.
  MSVC sees <code>&quot;\xA0&quot;</code> as not encoded unicode sequence, and encodes it to utf-8.
  So in MSVC the output is:</p>
  <blockquote>
  <p>C2A0</p>
  </blockquote>
  <p>Which is correctly encoded in utf8 unicode symbol <code>U+00A0</code>.</p>
  <p>But in case of GCC nonthing happens. It treats string as simple bytes. There's no change even if i remove <code>u8</code> before string literal.</p>
  <p>Both compilers encode to utf8 with output <code>C2A0</code> if the string is set to: <code>u8&quot;\u00A0&quot;;</code></p>
  <p>Why do compilers behave differently and which actually does it right?</p>
  <p>Software used for test:</p>
  <blockquote>
  <p>GCC 8.3.0</p>
  <p>MSVC 19.00.23506</p>
  </blockquote>
  <p>C++ 11</p>