title: Why does GCC accept convertion from 'const char *' to 'char *' on std::strrchr() returned value?
body: <p>While adding a <a href="https://stackoverflow.com/a/16914149/938111">detailed answer</a>, I noticed that GCC does not warn the following code while Visual C++ complains. </p>
  
  <pre><code>#include &lt;cstring&gt;
  int main()
  {
      const char CONSTSTR[] = "foo/bar/foobar.txt";
  
      char *nonconst = std::strrchr (CONSTSTR, '/');
      // cannot convert from 'const char *' to 'char *'
  
      *nonconst++ = 'B';
      *nonconst++ = 'A';
      *nonconst++ = 'D';
  }
  </code></pre>
  
  <p>I have tested three different GCC versions:</p>
  
  <ul>
  <li>4.1.2 on Red Hat (Linux)</li>
  <li>4.5.3 on Cygwin (Windows)</li>
  <li>4.7.2 on MinGW (Windows)</li>
  </ul>
  
  <p>But all these three GCC versions compiled this code without any warning/error:</p>
  
  <pre><code>&gt; g++ -Wall -Wextra -pedantic -ansi test.cpp &amp;&amp; echo "success"
  success
  </code></pre>
  
  <p>While Microsoft compiler v16 complains:</p>
  
  <pre><code>&gt; cl -c test.cpp
  Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
  Copyright (C) Microsoft Corporation.  All rights reserved.
  
  test.cpp
  test.cpp(5) : error C2440: 'initializing' : cannot convert from 'const char *' to 'char *'
          Conversion loses qualifiers
  </code></pre>
  
  <p>(from my office, I do not have access to ideone/codepad/... to test it using other versions)</p>
  
  <p>As this code uses <a href="http://en.cppreference.com/w/cpp/string/byte/strrchr" rel="nofollow noreferrer">std::strrchr</a>, I do not understand why GCC does not complain.</p>
  
  <pre><code>const char* strrchr( const char* str, int ch );  //the code above uses this declaration
        char* strrchr(       char* str, int ch );
  </code></pre>
  
  <p>My question: <strong>Why does g++ successfully compile this code without any warning/error? Is it a bug? a feature? a miss-configuration on my side?</strong></p>