From patchwork Thu May 11 14:48:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 69160 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A6EC2385383F for ; Thu, 11 May 2023 14:51:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6EC2385383F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683816660; bh=pju/rYeetuSYY50RaWliOs7Fqnyrf7fx/Z3oChzLV1M=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=fRWXpGrFgy+wRcPC5q2QQlFd388WbQ1UdUax+DPQHww0WioDyiFBcf9wlvxN2hfX4 UVS6xzq4KcpqpXrdr2BeSgZ0J3ntjjet6DA1wDOpyNfpMHWutjuNVpf8mJ1zxgol7y ymMUIGR5Ve2AbWXBCgD700cWt2EO2HMb67x1Cd20= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 225513857730 for ; Thu, 11 May 2023 14:50:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 225513857730 Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 952CC1E12E; Thu, 11 May 2023 10:50:35 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 10/12] gdbsupport: make basic_safe_iterator::operator* return the same thing as underlying iterator Date: Thu, 11 May 2023 10:48:30 -0400 Message-Id: <20230511144832.17974-11-simon.marchi@efficios.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230511144832.17974-1-simon.marchi@efficios.com> References: <20230511144832.17974-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3497.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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 | ^~~~~~~~~~ /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 --- gdbsupport/safe-iterator.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gdbsupport/safe-iterator.h b/gdbsupport/safe-iterator.h index bc8b4356540e..ccd772ca2a59 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 @@ class basic_safe_iterator basic_safe_iterator () {} - value_type operator* () const { return *m_it; } + typename gdb::invoke_result::type + operator* () const + { return *m_it; } self_type &operator++ () {