title: error: passing ‘const std::map<int, int>’ as ‘this’ argument discards qualifiers [-fpermissive]
body: <p>Fetching an entry from a const C++ std::map fails to compile on gcc 5.4.0.</p>
  
  <pre><code>test_map.cpp: In function ‘int main()’:
  test_map.cpp:9:24: error: passing ‘const std::map&lt;int, int&gt;’ as ‘this’ argument discards qualifiers [-fpermissive]
                   foo[key];
  </code></pre>
  
  <h2>Minimal test case</h2>
  
  <pre><code>// Compile with
  // g++ test_map.cpp -o test_map
  
  #include &lt;map&gt;
  
  int main() {
      const std::map&lt;int, int&gt; foo;
      foo[0]; // compiles if "const" above is suppressed
  }
  </code></pre>
  
  <h2>Look before you post</h2>
  
  <p>This looks similar to <a href="https://stackoverflow.com/questions/10765787/passing-const-this-argument-discards-qualifiers-fpermissive">passing ‘const this argument discards qualifiers [-fpermissive]</a> which is about a <code>Cache</code>, not a <code>std::map</code>.  The cause there: the user calls a <code>write()</code> method. That method is not declared <code>const</code> which makes sense since writing presumably modified the object.</p>
  
  <p>But here, fetching an element from a map does not modify the map, does it?</p>
  
  <h2>Question</h2>
  
  <p>The actual map in my real use case is indeed const.  It's fully initialized in the source code.  It does not make sense to modify it.  Declaring it non-const practically solves the problem but does not make sense.</p>