From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id hYEZDbUPbmToxxIAWB0awg (envelope-from ) for ; Wed, 24 May 2023 09:23:01 -0400 Received: by simark.ca (Postfix, from userid 112) id 23ED31E11E; Wed, 24 May 2023 09:23:01 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=xlNThtYJ; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 ESMTPS id 82BE61E0D6 for ; Wed, 24 May 2023 09:23:00 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2E0D3858412 for ; Wed, 24 May 2023 13:22:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2E0D3858412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684934579; bh=yzRzuwQiaCZrdsUMcmI+NqgbMPR5b1BpQxe8KD/5OQ4=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=xlNThtYJwToir1+p1MjVZ3cfQBeUsTow9/qny4QL941eClS3O73FOUjcaG8lqlcs5 Pq6Fvd/ENA1hjskHdGmL8aivswzTnjqODQQ1U6hwxbDzj5i4rQwJVslCPDO+WeAC33 3TWP8IpM1/rqumKH5xbZRcmX5NLb1zX3eOD9s9a0= Received: from lndn.lancelotsix.com (vps-42846194.vps.ovh.net [IPv6:2001:41d0:801:2000::2400]) by sourceware.org (Postfix) with ESMTPS id E68A63858C54 for ; Wed, 24 May 2023 13:22:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E68A63858C54 Received: from octopus (cust120-dsl54.idnet.net [212.69.54.120]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id 9267589F61; Wed, 24 May 2023 13:22:36 +0000 (UTC) Date: Wed, 24 May 2023 14:22:32 +0100 To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] gdbsupport: add support for references to checked_static_cast Message-ID: <20230524132157.rhdftbdnjckyzdnt@octopus> References: <20230518205737.403656-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230518205737.403656-1-simon.marchi@efficios.com> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Wed, 24 May 2023 13:22:36 +0000 (UTC) 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: , From: Lancelot SIX via Gdb-patches Reply-To: Lancelot SIX Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi Simon, > diff --git a/gdbsupport/gdb-checked-static-cast.h b/gdbsupport/gdb-checked-static-cast.h > index bc75244bddd0..7e5a69a6474d 100644 > --- a/gdbsupport/gdb-checked-static-cast.h > +++ b/gdbsupport/gdb-checked-static-cast.h > @@ -66,6 +66,22 @@ checked_static_cast (V *v) > return result; > } > > +/* Same as the above, but to cast from a reference type to another. */ > + > +template > +T > +checked_static_cast (V &v) > +{ > + static_assert (std::is_reference::value, "target must be a reference type"); Have you considered incorporating this constraint inside checked_static_cast's signature? It could look like something like this: template typename std::enable_if::value, T>::type checked_static_cast (V &v) { ... } If T is not a reference, then this template won't be instantiated at all instead of instantiating it and having an error. This could allow other templates / functions to be considered if they matched instead of just producing an error. I do agree that this can end-up a bit more difficult to read for someone not used to read this kind of code. Best, Lancelot. > + > + using T_no_R = typename std::remove_reference::type; > + using T_P = typename std::add_pointer::type; > + > + using V_no_R = typename std::remove_reference::type; > + > + return *checked_static_cast (&v); > +} > + > } > > #endif /* COMMON_GDB_CHECKED_DYNAMIC_CAST_H */ > > base-commit: c96452ad168cf42ad42f0d57214dddb38d5fae88 > -- > 2.40.1 >