mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Colin Cross <ccross@google.com>
Cc: musl@lists.openwall.com, Ismael Luceno <ismael@iodev.co.uk>
Subject: Re: [musl] Re: [PATCH] Define NULL as nullptr when used in C++
Date: Thu, 23 Dec 2021 20:28:28 -0500	[thread overview]
Message-ID: <20211224012828.GT7074@brightrain.aerifal.cx> (raw)
In-Reply-To: <20211223210521.GR7074@brightrain.aerifal.cx>

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<int*>(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

      parent reply	other threads:[~2021-12-24  1:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23 19:13 Colin Cross
2021-12-23 21:05 ` Rich Felker
2021-12-23 22:01   ` Ismael Luceno
2021-12-24  1:28   ` Rich Felker [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211224012828.GT7074@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=ccross@google.com \
    --cc=ismael@iodev.co.uk \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).