From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=lancelotsix.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lancelotsix.com 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) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=lancelotsix.com; s=2021; t=1684934556; bh=m2NCUHgYIJaKlm1tgJ/gqA/pTNsXFI79AyFh7HBPXzk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GMPkypUDZBZMK2AiTgWmUGHe8qTQmjkfESfwl4rx1+3vgtYrHu72JMdiL+TphqlM+ kWn2eVdyIy9sNLacgbtiK6W6/FV8u/oc8Ii257W5ggQRIfNs+jjJI9oT4CQ2NpCyV4 5YGwZwGv00pbgciJp6A6loFUpDyLIvP1qN3pybs7PVKCs/GGKX8xysolmPUly/D/88 A0MMuJHkjYa0gEFUT9LhP9CCWzhI3mA3bPaNDkPEnoUXV7UTo/JJ0A1BdPFtPcfp+8 jMDB+QNDdUKasdXuV2Iw9Y8s3TXvO497TZkd8jS3qzZd4fplGAJtHdzU6h8juJXERy YcZvF63HE046g== Date: Wed, 24 May 2023 14:22:32 +0100 From: Lancelot SIX 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-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,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 List-Id: 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 >