title: Errors occurs when accessing unordered_map by [] operator
body: <p>I stumbled upon a strange problem with an unordered_map.</p>
  
  <p>First I generated an <code>unordered_map&lt;string, Person&gt;</code> and inserted a record ("Bob", Person(1, "Bob")) into the table. Then I tried to access the record by using the [] operator with key "Bob" and an error happened.</p>
  
  <p>This is the code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;unordered_map&gt;
  using namespace std;
  
  class Person
  {
      public:
          int play;
          string name;
          Person(int p, string n):play(p), name(n) {}
  };
  
  int main()
  {
      unordered_map&lt;string,Person&gt; test;
      test.insert(std::make_pair("haha",Person(1,"haha")));
      cout&lt;&lt;test["haha"].name&lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>Errors occur when I compile the code with "g++ -S hash.cpp"
  Output:</p>
  
  <pre><code>In file included from /usr/include/c++/7/unordered_map:41:0,
                   from hash.cpp:2:
  /usr/include/c++/7/tuple: In instantiation of ‘std::pair&lt;_T1, _T2&gt;::pair(std::tuple&lt;_Args1 ...&gt;&amp;, std::tuple&lt;_Args2 ...&gt;&amp;, std::_Index_tuple&lt;_Indexes1 ...&gt;, std::_Index_tuple&lt;_Indexes2 ...&gt;) [with _Args1 = {std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;&amp;}; long unsigned int ..._Indexes1 = {0}; _Args2 = {}; long unsigned int ..._Indexes2 = {}; _T1 = const std::__cxx11::basic_string&lt;char&gt;; _T2 = Person]’:
  /usr/include/c++/7/tuple:1641:63:   required from ‘std::pair&lt;_T1, _T2&gt;::pair(std::piecewise_construct_t, std::tuple&lt;_Args1 ...&gt;, std::tuple&lt;_Args2 ...&gt;) [with _Args1 = {std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;&amp;}; _Args2 = {}; _T1 = const std::__cxx11::basic_string&lt;char&gt;; _T2 = Person]’
  /usr/include/c++/7/ext/new_allocator.h:136:4:   required from ‘void __gnu_cxx::new_allocator&lt;_Tp&gt;::construct(_Up*, _Args&amp;&amp; ...) [with _Up = std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt;; _Args = {const std::piecewise_construct_t&amp;, std::tuple&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;&amp;&gt;, std::tuple&lt;&gt;}; _Tp = std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt;]’
  /usr/include/c++/7/bits/alloc_traits.h:475:4:   required from ‘static void std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::construct(std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::allocator_type&amp;, _Up*, _Args&amp;&amp; ...) [with _Up = std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt;; _Args = {const std::piecewise_construct_t&amp;, std::tuple&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;&amp;&gt;, std::tuple&lt;&gt;}; _Tp = std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt;; std::allocator_traits&lt;std::allocator&lt;_CharT&gt; &gt;::allocator_type = std::allocator&lt;std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt; &gt;]’
  /usr/include/c++/7/bits/hashtable_policy.h:2066:37:   required from ‘std::__detail::_Hashtable_alloc&lt;_NodeAlloc&gt;::__node_type* std::__detail::_Hashtable_alloc&lt;_NodeAlloc&gt;::_M_allocate_node(_Args&amp;&amp; ...) [with _Args = {const std::piecewise_construct_t&amp;, std::tuple&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;&amp;&gt;, std::tuple&lt;&gt;}; _NodeAlloc = std::allocator&lt;std::__detail::_Hash_node&lt;std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt;, true&gt; &gt;; std::__detail::_Hashtable_alloc&lt;_NodeAlloc&gt;::__node_type = std::__detail::_Hash_node&lt;std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt;, true&gt;]’
  /usr/include/c++/7/bits/hashtable_policy.h:750:8:   required from ‘std::__detail::_Map_base&lt;_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true&gt;::mapped_type&amp; std::__detail::_Map_base&lt;_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true&gt;::operator[](std::__detail::_Map_base&lt;_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true&gt;::key_type&amp;&amp;) [with _Key = std::__cxx11::basic_string&lt;char&gt;; _Pair = std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt;; _Alloc = std::allocator&lt;std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt; &gt;; _Equal = std::equal_to&lt;std::__cxx11::basic_string&lt;char&gt; &gt;; _H1 = std::hash&lt;std::__cxx11::basic_string&lt;char&gt; &gt;; _H2 = std::__detail::_Mod_range_hashing; _Hash = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits&lt;true, false, true&gt;; std::__detail::_Map_base&lt;_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true&gt;::mapped_type = Person; std::__detail::_Map_base&lt;_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _H1, _H2, _Hash, _RehashPolicy, _Traits, true&gt;::key_type = std::__cxx11::basic_string&lt;char&gt;]’
  /usr/include/c++/7/bits/unordered_map.h:980:20:   required from ‘std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::mapped_type&amp; std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::operator[](std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::key_type&amp;&amp;) [with _Key = std::__cxx11::basic_string&lt;char&gt;; _Tp = Person; _Hash = std::hash&lt;std::__cxx11::basic_string&lt;char&gt; &gt;; _Pred = std::equal_to&lt;std::__cxx11::basic_string&lt;char&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const std::__cxx11::basic_string&lt;char&gt;, Person&gt; &gt;; std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::mapped_type = Person; std::unordered_map&lt;_Key, _Tp, _Hash, _Pred, _Alloc&gt;::key_type = std::__cxx11::basic_string&lt;char&gt;]’
  hash.cpp:17:19:   required from here
  /usr/include/c++/7/tuple:1652:70: error: no matching function for call to ‘Person::Person()’
           second(std::forward&lt;_Args2&gt;(std::get&lt;_Indexes2&gt;(__tuple2))...)
                                                                        ^
  hash.cpp:10:3: note: candidate: Person::Person(int, std::__cxx11::string)
     Person(int p, string n):play(p), name(n) {}
     ^~~~~~
  hash.cpp:10:3: note:   candidate expects 2 arguments, 0 provided
  hash.cpp:5:7: note: candidate: Person::Person(const Person&amp;)
   class Person
         ^~~~~~
  hash.cpp:5:7: note:   candidate expects 1 argument, 0 provided
  hash.cpp:5:7: note: candidate: Person::Person(Person&amp;&amp;)
  hash.cpp:5:7: note:   candidate expects 1 argument, 0 provided
  </code></pre>
  
  <p>I had inserted the record but the map seemed to be unaware of this and tried to insert the record again.</p>
  
  <p>So how does the g++ compiler process the [] operator?</p>
  
  <p>Thanks.</p>