diff options
author | Bruno Haible <bruno@clisp.org> | 2020-05-31 12:01:27 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-05-31 12:01:27 +0200 |
commit | d2ae3a4ac629609fc29c16c53757767fd2963b88 (patch) | |
tree | f52a59627d4a50aa9302d4eabbb2913042536a8e /lib/gl_list.hh | |
parent | 0964a8cc11b4e13780e427c7dfc5d6a0fe072c9e (diff) | |
download | gnulib-d2ae3a4ac629609fc29c16c53757767fd2963b88.tar.gz |
list-c++, set-c++, oset-c++, map-c++, omap-c++: Don't fool the compiler.
Reported by Akim Demaille in
<https://lists.gnu.org/archive/html/bug-bison/2020-05/msg00102.html>.
* lib/gl_list.hh (gl_List::iterator::next): Avoid a reinterpret_cast.
* lib/gl_set.hh (gl_Set::iterator::next): Likewise.
* lib/gl_oset.hh (gl_OSet::iterator::next): Likewise.
* lib/gl_map.hh (gl_Map::iterator::next): Likewise.
* lib/gl_omap.hh (gl_OMap::iterator::next): Likewise.
Diffstat (limited to 'lib/gl_list.hh')
-rw-r--r-- | lib/gl_list.hh | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/gl_list.hh b/lib/gl_list.hh index b19bda71b1..8b0ccad1ba 100644 --- a/lib/gl_list.hh +++ b/lib/gl_list.hh @@ -351,13 +351,25 @@ public: the iterator and returns true. Otherwise, returns false. */ bool next (ELTYPE *& elt) - { return gl_list_iterator_next (&_state, reinterpret_cast<const void **>(&elt), NULL); } + { + const void *next_elt; + bool has_next = gl_list_iterator_next (&_state, &next_elt, NULL); + if (has_next) + elt = static_cast<ELTYPE *>(next_elt); + return has_next; + } /* If there is a next element, stores the next element in ELT, stores its node in *NODEP if NODEP is non-NULL, advances the iterator and returns true. Otherwise, returns false. */ bool next (ELTYPE *& elt, gl_list_node_t *nodep) - { return gl_list_iterator_next (&_state, reinterpret_cast<const void **>(&elt), nodep); } + { + const void *next_elt; + bool has_next = gl_list_iterator_next (&_state, &next_elt, nodep); + if (has_next) + elt = static_cast<ELTYPE *>(next_elt); + return has_next; + } ~iterator () { gl_list_iterator_free (&_state); } |