]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Define operator== for hash table iterators [PR115939]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 16 Jul 2024 08:43:06 +0000 (09:43 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 23 Aug 2024 12:39:35 +0000 (13:39 +0100)
commit591b71993f15ed95eb38f3314f3d9ac159b9d051
treec83626748dd39b885e372d904483d3613a4a45ed
parent125bab23ad75449333983c9389898c5b92b3aa0d
libstdc++: Define operator== for hash table iterators [PR115939]

Currently iterators for unordered containers do not directly define
operator== and operator!= overloads. Instead they rely on the base class
defining them, which is done so that iterator and const_iterator
comparisons work using the same overloads.

However this means a derived-to-base conversion is needed to call those
operators, and PR libstdc++/115939 shows that this can be ambiguous (for
-pedantic) when another overloaded operator could be used after an
implicit conversion.

This change defines operator== and operator!= directly for
_Node_iterator and _Node_const_iterator so that no derived-to-base
conversions are needed. The new overloads just forward to the base class
ones, so the implementation is still shared and doesn't need to be
duplicated.

libstdc++-v3/ChangeLog:

PR libstdc++/115939
* include/bits/hashtable_policy.h (_Node_iterator): Add
operator== and operator!=.
(_Node_const_iterator): Likewise.
* testsuite/23_containers/unordered_map/115939.cc: New test.
libstdc++-v3/include/bits/hashtable_policy.h
libstdc++-v3/testsuite/23_containers/unordered_map/115939.cc [new file with mode: 0644]