summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-05-31 12:01:27 +0200
committerBruno Haible <bruno@clisp.org>2020-05-31 12:01:27 +0200
commitd2ae3a4ac629609fc29c16c53757767fd2963b88 (patch)
treef52a59627d4a50aa9302d4eabbb2913042536a8e
parent0964a8cc11b4e13780e427c7dfc5d6a0fe072c9e (diff)
downloadgnulib-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.
-rw-r--r--ChangeLog11
-rw-r--r--lib/gl_list.hh16
-rw-r--r--lib/gl_map.hh12
-rw-r--r--lib/gl_omap.hh12
-rw-r--r--lib/gl_oset.hh8
-rw-r--r--lib/gl_set.hh8
6 files changed, 61 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index e8133349c1..321d5e28c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2020-05-31 Bruno Haible <bruno@clisp.org>
+
+ 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.
+
2020-05-30 Bruno Haible <bruno@clisp.org>
wmemchr: Relicense under LGPLv2+.
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); }
diff --git a/lib/gl_map.hh b/lib/gl_map.hh
index f3d0a46b94..082694fe6b 100644
--- a/lib/gl_map.hh
+++ b/lib/gl_map.hh
@@ -143,7 +143,17 @@ public:
/* If there is a next pair, stores the next pair in KEY and VALUE, advance
the iterator, and returns true. Otherwise, returns false. */
bool next (KEYTYPE *& key, VALUETYPE *& value)
- { return gl_map_iterator_next (&_state, reinterpret_cast<const void **>(&key), reinterpret_cast<const void **>(&value)); }
+ {
+ const void *next_key;
+ const void *next_value;
+ bool has_next = gl_map_iterator_next (&_state, &next_key, &next_value);
+ if (has_next)
+ {
+ key = static_cast<KEYTYPE *>(next_key);
+ value = static_cast<VALUETYPE *>(next_value);
+ }
+ return has_next;
+ }
~iterator ()
{ gl_map_iterator_free (&_state); }
diff --git a/lib/gl_omap.hh b/lib/gl_omap.hh
index 15d81041d4..1f892e46f8 100644
--- a/lib/gl_omap.hh
+++ b/lib/gl_omap.hh
@@ -150,7 +150,17 @@ public:
/* If there is a next pair, stores the next pair in KEY and VALUE, advances
the iterator, and returns true. Otherwise, returns false. */
bool next (KEYTYPE *& key, VALUETYPE *& value)
- { return gl_omap_iterator_next (&_state, reinterpret_cast<const void **>(&key), reinterpret_cast<const void **>(&value)); }
+ {
+ const void *next_key;
+ const void *next_value;
+ bool has_next = gl_omap_iterator_next (&_state, &next_key, &next_value);
+ if (has_next)
+ {
+ key = static_cast<KEYTYPE *>(next_key);
+ value = static_cast<VALUETYPE *>(next_value);
+ }
+ return has_next;
+ }
~iterator ()
{ gl_omap_iterator_free (&_state); }
diff --git a/lib/gl_oset.hh b/lib/gl_oset.hh
index 16da0dd2b3..b78ef52802 100644
--- a/lib/gl_oset.hh
+++ b/lib/gl_oset.hh
@@ -121,7 +121,13 @@ public:
/* If there is a next element, stores the next element in ELT, advances the
iterator and returns true. Otherwise, returns false. */
bool next (ELTYPE *& elt)
- { return gl_oset_iterator_next (&_state, reinterpret_cast<const void **>(&elt)); }
+ {
+ const void *next_elt;
+ bool has_next = gl_oset_iterator_next (&_state, &next_elt);
+ if (has_next)
+ elt = static_cast<ELTYPE *>(next_elt);
+ return has_next;
+ }
~iterator ()
{ gl_oset_iterator_free (&_state); }
diff --git a/lib/gl_set.hh b/lib/gl_set.hh
index 357e14175a..3b64bc5b1a 100644
--- a/lib/gl_set.hh
+++ b/lib/gl_set.hh
@@ -114,7 +114,13 @@ public:
/* If there is a next element, stores the next element in ELT, advances the
iterator and returns true. Otherwise, returns false. */
bool next (ELTYPE *& elt)
- { return gl_set_iterator_next (&_state, reinterpret_cast<const void **>(&elt)); }
+ {
+ const void *next_elt;
+ bool has_next = gl_set_iterator_next (&_state, &next_elt);
+ if (has_next)
+ elt = static_cast<ELTYPE *>(next_elt);
+ return has_next;
+ }
~iterator ()
{ gl_set_iterator_free (&_state); }