title: Differences in size of std::string_view of non-null terminated char array
body: <p>I was playing around with <em>std::string_view</em> with different compilers and noticed that each compiler prints out different sizes when initializing the <em>std::string_view</em> with a non-null terminated char array. </p>
  
  <p>It seems that every compiler prints out the correct size when turning on optimization but prints out the wrong size when optimization is off (except GCC, which prints out the correct size in both cases). </p>
  
  <p>My question is: Why is this the case? </p>
  
  <p>Code:</p>
  
  <pre><code>// test.cpp
  
  #include &lt;iostream&gt;
  
  #ifdef __MINGW32__
  #include &lt;experimental/string_view&gt;
  #elif _MSC_VER
  #include &lt;string_view&gt;
  #endif
  
  int main()
  {
      const char foo[3]{ 'f','o','o' };
  
  #ifdef __MINGW32__
      std::experimental::string_view str_v{ foo };
  #elif _MSC_VER
      std::string_view str_v{ foo };
  #endif
  
      std::cout &lt;&lt; sizeof(foo) &lt;&lt; " " &lt;&lt; str_v.size() &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>Output: Visual C++ 19.00.24619.0</p>
  
  <pre><code>3 5 // cl /Zi /std:c++latest /EHsc /nologo /W4 test.cpp
  3 3 // cl /O2 /std:c++latest /EHsc /nologo /W4 test.cpp
  </code></pre>
  
  <p>Output: Clang 4.0.0-r282394 (using MinGW-w64)</p>
  
  <pre><code>3 4 // clang++ -g --target=x86_64-w64-mingw32 -std=c++1z -Wall -o test.exe test.cpp
  3 3 // clang++ -02 --target=x86_64-w64-mingw32 -std=c++1z -Wall -o test.exe test.cpp
  </code></pre>
  
  <p>Output: GCC 6.2.0 (MinGW-w64)</p>
  
  <pre><code>3 3 // g++ -g -std=c++1z -Wall -o test.exe test.cpp
  3 3 // g++ -O2 -std=c++1z -Wall -o test.exe test.cpp
  </code></pre>