From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id CD303388E807 for ; Thu, 17 Dec 2020 15:38:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CD303388E807 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6D43830E; Thu, 17 Dec 2020 07:38:53 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C206D3F66B; Thu, 17 Dec 2020 07:38:52 -0800 (PST) From: Richard Sandiford To: Tom Tromey Mail-Followup-To: Tom Tromey , Martin Sebor , gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Cc: Martin Sebor , gcc-patches@gcc.gnu.org Subject: Re: [07/23] Add a class that multiplexes two pointer types References: <878s9wpl6q.fsf@tromey.com> Date: Thu, 17 Dec 2020 15:38:50 +0000 In-Reply-To: <878s9wpl6q.fsf@tromey.com> (Tom Tromey's message of "Thu, 17 Dec 2020 07:21:49 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Dec 2020 15:38:55 -0000 Tom Tromey writes: >>>>>> "Richard" == Richard Sandiford via Gcc-patches writes: > > Richard> +// A class that stores a choice "A or B", where A has type T1 * and B has > Richard> +// type T2 *. Both T1 and T2 must have an alignment greater than 1, since > Richard> +// the low bit is used to identify B over A. T1 and T2 can be the same. > > It seems like the alignment requirement could be static_assert'd, which > would make using this class a bit safer. Yeah, I wondered about doing that, but in principle there's nothing to stop people using the class for something like a char*, provided that the start is suitably aligned. So having gcc_checking_assert is a compromise: it only provides run-time checking rather than compile-time checking, but it doesn't place any artificial limits on how the class can be used. Thanks, Richard