diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc
index 54092f541baf0ccf67bd72e4434be85d9da460a7..5d6bb5b7547a5490a0b11b20a530e84334ac168c 100644
--- a/libstdc++-v3/src/c++11/debug.cc
+++ b/libstdc++-v3/src/c++11/debug.cc
@@ -437,6 +437,8 @@ namespace __gnu_debug
 	_M_version = _M_sequence->_M_version;
 	_M_sequence->_M_attach(this, __constant);
       }
+    else
+      _M_version = 0;
   }
 
   void
@@ -452,6 +454,8 @@ namespace __gnu_debug
 	_M_version = _M_sequence->_M_version;
 	_M_sequence->_M_attach_single(this, __constant);
       }
+    else
+      _M_version = 0;
   }
 
   void
@@ -528,6 +532,8 @@ namespace __gnu_debug
 	_M_version = _M_sequence->_M_version;
 	_M_get_container()->_M_attach_local(this, __constant);
       }
+    else
+      _M_version = 0;
   }
 
   void
@@ -543,6 +549,8 @@ namespace __gnu_debug
 	_M_version = _M_sequence->_M_version;
 	_M_get_container()->_M_attach_local_single(this, __constant);
       }
+    else
+      _M_version = 0;
   }
 
   void
diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/112477.cc b/libstdc++-v3/testsuite/23_containers/map/debug/112477.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bde613b8905a8e66f2903bc40f0c0f763e453c6d
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/map/debug/112477.cc
@@ -0,0 +1,20 @@
+// { dg-do run { target c++11 } }
+// { dg-require-debug-mode "" }
+
+// PR libstdc++/112477
+
+#include <map>
+
+int main()
+{
+  using M = std::map<int, int>;
+  using I = M::iterator;
+
+  M map{ {1, 1}, {2, 2} };
+
+  I it1 = map.begin();
+  it1 = I{};
+
+  I it2{};
+  (void)(it1 == it2);
+}