Hi!

As mentioned in the PR, with GCC before 4.3 one can't instantiate std::pair
where one or both of the template parameters are reference types, because
the std::pair constructor has arguments references to the template parameter
types and the CWG that resolved hasn't been applied to those compilers.

The following patch works around it by not returning
std::pair<const Key &, Value &> object, but instead a different class that
holds the two references and has conversion operator to std::pair.

If that conversion operator isn't acceptable, in the PR there is another
patch which adjusts the (so far) two spots which need to be changed in that
case.

Bootstrapped/regtested on x86_64-linux and i686-linux (using GCC 7 as
bootstrap compiler) and tested on the preprocessed source with GCC 4.1.
Ok for trunk?

2018-11-13  Jakub Jelinek  <ja...@redhat.com>

        PR bootstrap/86739
        * hash-map.h (hash_map::iterator::reference_pair): New class.
        (hash_map::iterator::operator*): Return it rather than std::pair.

--- gcc/hash-map.h.jj   2018-07-11 22:22:01.250836509 +0200
+++ gcc/hash-map.h      2018-11-13 20:45:38.463037081 +0100
@@ -223,10 +223,23 @@ public:
       return *this;
     }
 
-    std::pair<const Key&, Value&> operator* ()
+    /* Can't use std::pair here, because GCC before 4.3 don't handle
+       std::pair where template parameters are references well.
+       See PR86739.  */
+    struct reference_pair {
+      const Key &first;
+      Value &second;
+
+      reference_pair (const Key &key, Value &value) : first (key), second 
(value) {}
+
+      template <typename K, typename V>
+      operator std::pair<K, V> () const { return std::pair<K, V> (first, 
second); }
+    };
+
+    reference_pair operator* ()
     {
       hash_entry &e = *m_iter;
-      return std::pair<const Key&, Value&> (e.m_key, e.m_value);
+      return reference_pair (e.m_key, e.m_value);
     }
 
     bool

        Jakub

Reply via email to