diff --git a/libstdc++-v3/include/debug/safe_local_iterator.tcc b/libstdc++-v3/include/debug/safe_local_iterator.tcc index 90e60e37c32..6d546ec040c 100644 --- a/libstdc++-v3/include/debug/safe_local_iterator.tcc +++ b/libstdc++-v3/include/debug/safe_local_iterator.tcc @@ -78,7 +78,13 @@ namespace __gnu_debug _M_valid_range(const _Safe_local_iterator& __rhs, std::pair& __dist) const { - if (!_M_can_compare(__rhs)) + if (_M_value_initialized() && __rhs._M_value_initialized()) + { + __dist = { 0, __dp_exact }; + return true; + } + + if (_M_singular() || __rhs._M_singular() || !_M_can_compare(__rhs)) return false; if (bucket() != __rhs.bucket()) diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/114316.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/114316.cc new file mode 100644 index 00000000000..41b649a9cbd --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/114316.cc @@ -0,0 +1,28 @@ +// { dg-do run { target c++11 } } +// { dg-require-debug-mode "" } + +// PR libstdc++/114316 + +#include +#include + +#include + +void test01() +{ + std::unordered_set::iterator it{}; + VERIFY( std::find(it, it, 0) == it ); +} + +void test02() +{ + std::unordered_set::local_iterator it{}; + VERIFY( std::find(it, it, 0) == it ); +} + +int main() +{ + test01(); + test02(); + return 0; +}