aboutsummaryrefslogtreecommitdiff
path: root/gdbsupport
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2023-05-08 14:49:33 -0400
committerSimon Marchi <simon.marchi@efficios.com>2023-05-25 09:44:52 -0400
commit679a4e92b311841e7f9a067d9251f5534485499f (patch)
tree7b24ba5d4943536438a37a4a8e853ade27791809 /gdbsupport
parente2a1578868a2a681fbafd6c56b694cfe9410b8d4 (diff)
downloadbinutils-679a4e92b311841e7f9a067d9251f5534485499f.zip
binutils-679a4e92b311841e7f9a067d9251f5534485499f.tar.gz
binutils-679a4e92b311841e7f9a067d9251f5534485499f.tar.bz2
gdbsupport: make basic_safe_iterator::operator* return the same thing as underlying iterator
Using the following patch that removes the reference_to_pointer_iterator from breakpoint_range, I would get: CXX breakpoint.o /home/smarchi/src/binutils-gdb/gdb/breakpoint.c: In function ‘void breakpoint_program_space_exit(program_space*)’: /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:3030:46: error: cannot allocate an object of abstract type ‘breakpoint’ 3030 | for (breakpoint &b : all_breakpoints_safe ()) | ^ In file included from /home/smarchi/src/binutils-gdb/gdb/gdbthread.h:26, from /home/smarchi/src/binutils-gdb/gdb/infrun.h:21, from /home/smarchi/src/binutils-gdb/gdb/gdbarch.h:28, from /home/smarchi/src/binutils-gdb/gdb/arch-utils.h:23, from /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:21: /home/smarchi/src/binutils-gdb/gdb/breakpoint.h:619:8: note: because the following virtual functions are pure within ‘breakpoint’: 619 | struct breakpoint : public intrusive_list_node<breakpoint> | ^~~~~~~~~~ /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:250:1: note: ‘virtual breakpoint::~breakpoint()’ 250 | breakpoint::~breakpoint () | ^~~~~~~~~~ This is because the operator* method of the basic_safe_iterator iterator wrapper returns a value_type. So, even if the method of the underlying iterator (breakpoint_iterator, an intrusive_list iterator) returns a `breakpoint &`, the method of the wrapper returns a `breakpoint`. I think it would make sense for iterator wrappers such as basic_safe_iterator to return the exact same thing as the iterator they wrap. At least, it fixes my problem. Change-Id: Ibbcd390ac03d2fb6ae4854923750c8d7c3c04e8a Reviewed-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdbsupport')
-rw-r--r--gdbsupport/safe-iterator.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/gdbsupport/safe-iterator.h b/gdbsupport/safe-iterator.h
index bc8b435..ccd772c 100644
--- a/gdbsupport/safe-iterator.h
+++ b/gdbsupport/safe-iterator.h
@@ -19,6 +19,8 @@
#ifndef COMMON_SAFE_ITERATOR_H
#define COMMON_SAFE_ITERATOR_H
+#include "gdbsupport/invoke-result.h"
+
/* A forward iterator that wraps Iterator, such that when iterating
with iterator IT, it is possible to delete *IT without invalidating
IT. Suitably wrapped in a range type and used with range-for, this
@@ -75,7 +77,9 @@ public:
basic_safe_iterator ()
{}
- value_type operator* () const { return *m_it; }
+ typename gdb::invoke_result<decltype(&Iterator::operator*), Iterator>::type
+ operator* () const
+ { return *m_it; }
self_type &operator++ ()
{