From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26427 invoked from network); 24 Dec 2021 01:28:44 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 24 Dec 2021 01:28:44 -0000 Received: (qmail 28067 invoked by uid 550); 24 Dec 2021 01:28:42 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 28026 invoked from network); 24 Dec 2021 01:28:41 -0000 Date: Thu, 23 Dec 2021 20:28:28 -0500 From: Rich Felker To: Colin Cross Cc: musl@lists.openwall.com, Ismael Luceno Message-ID: <20211224012828.GT7074@brightrain.aerifal.cx> References: <20211223210521.GR7074@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211223210521.GR7074@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Re: [PATCH] Define NULL as nullptr when used in C++ On Thu, Dec 23, 2021 at 04:05:22PM -0500, Rich Felker wrote: > On Thu, Dec 23, 2021 at 11:13:01AM -0800, Colin Cross wrote: > > On Sun, Aug 15, 2021 at 05:51:57PM +0200, Ismael Luceno wrote: > > > This should be safer for casting and more compatible with existing code > > > bases that wrongly assume it must be defined as a pointer. > > > > This seems to meet the C++ spec for NULL [1], but I noticed some > > compatibility issues with code that was previously compiling with > > glibc. > > > > I've found multiple places that used reinterpret_cast(NULL), > > which now fail with: > > error: reinterpret_cast from 'nullptr_t' to 'int *' is not allowed > > According to [2] those should technically be static_cast and not > > reinterpret_cast. > > This is an improvement then. reinterpret_cast is very very wrong here > and should produce a compile error. It's the equivalent of writing (in > C): > > *(int **)&(void *){NULL} > > instead of > > (int *)NULL > > i.e. it's type punning where the author intended a value conversion. I've been informed I'm probably wrong about this, because reinterpret_cast means something different when applied to pointers than to other types. Still, getting the error is right as far as I can tell, since reinterpret_cast is not supposed to accept nullptr_t for conversion to int*. Rich