mailing list of musl libc
 help / color / mirror / code / Atom feed
From: James Y Knight <jyknight@google.com>
To: musl@lists.openwall.com
Subject: Re: [PATCH] Define NULL as __null in C++ mode when using GCC or Clang.
Date: Wed, 10 Jul 2019 13:35:35 -0400	[thread overview]
Message-ID: <CAA2zVHqcrtM_r-pnDeQf31Lng2n732No5Vc-JPB7w7CM4+jYVA@mail.gmail.com> (raw)
In-Reply-To: <20190710164446.GS1506@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 3540 bytes --]

On Wed, Jul 10, 2019 at 12:45 PM Rich Felker <dalias@libc.org> wrote:

> On Wed, Jul 10, 2019 at 12:18:11PM -0400, James Y Knight wrote:
> > On Wed, Jul 10, 2019 at 2:34 AM Florian Weimer <fweimer@redhat.com>
> wrote:
> >
> > > * Szabolcs Nagy:
> > >
> > > > it is clear that 0L is a conforming definition for all
> > > > conforming c++ compilers.
> > > >
> > > > it is less clear if __null is so in all compilers that
> > > > define __GNUC__.
> > >
> > > Why wouldn't something like this be valid for current C++ versions?
> > >
> > > static inline constexpr decltype(nullptr) __null{};
> > > #define NULL __null
> > >
> > > I don't see a requirement that NULL must be an expression that can be
> > > evaluated by the preprocessor.
> >
> >
> > Is this just for the purposes of argument, or, why would you want to do
> > that? More sanely, yes, `#define NULL nullptr` would now also be a
> > conforming definition, but that is an undesirable change in practice for
> a
> > variety of compatibility reasons. Toolchains have remained with `#define
> > NULL __null`, and seem likely to continue to do so indefinitely.
> >
> > I feel like this thread is kinda going off on a tangent now. Inventing
> new
> > and unique ways to define NULL in C++ doesn't really seem a useful thing
> to
> > do be doing here...
>
> Well "do it the same way GCC's headers did it" isn't useful because
> we're not using GCC's headers. If there's a definition that's
> preferable to what we have now, it should stand on its own as a better
> (or at least better in some ways that we decide are good trade-offs)
> choice. The current definition was chosen that way, not just at
> random, as you can see from the commit history


Neither was GCC's choice random, as I'm sure you'll agree.

musl explicitly does not use, require, or support the use of
> standard-namespace-conflicting headers (as opposed to extensions like
> vector intrinsics) shipped with the compiler, and supports as wide a
> range as possible of compilers -- for building musl itself, ones
> implementing a minimal subset of "GNU C", and for compiling against
> musl, an even more minimal subset that can be "faked" with just some
> macros if needed. So whether there are or may be "GNU C++" compilers
> that lack __null is a valid question.


It's a question which is impossible to ever answer in the negative -- there
always _may be_ any sort of terrible software implemented out there,
somewhere. But, I do doubt any such relevant compilers actually exist.

My leaning would kinda be to use
> nullptr in recent C++ versions and retain 0L for old ones if nullptr
> is a valid definition in new C++ versions, but I still wonder if
> having use of NULL "break maximally" isn't a better behavior with
> respect to ending its use...
>

#define NULL nullptr is standards-valid in c++11 and later, but would be an
unfortunate choice to make. Both in terms of breaking working code (code
which is making unportable assumptions, granted), but also in terms of
breaking ABIs on valid code: changing the type from long to
decltype(nullptr) changes mangling, etc.

If you really wanted to push for that, I'd recommend starting a discussion
on the gcc or clang lists -- the libc list doesn't really seem a place most
likely to find C++ experts to help evaluate the pros and cons of making
such a change. Certainly that all such C++ experts had previously decided
it would be a bad idea to do so doesn't *necessarily* mean it's still the
wrong thing, but it should at least be considered a strong signal...

[-- Attachment #2: Type: text/html, Size: 4710 bytes --]

  reply	other threads:[~2019-07-10 17:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-09 19:19 James Y Knight
2019-07-09 19:38 ` Rich Felker
2019-07-09 23:04   ` James Y Knight
2019-07-10  2:03     ` Szabolcs Nagy
2019-07-10  6:34       ` Florian Weimer
2019-07-10  8:46         ` Szabolcs Nagy
2019-07-10 16:18         ` James Y Knight
2019-07-10 16:44           ` Rich Felker
2019-07-10 17:35             ` James Y Knight [this message]
2019-07-10 20:11               ` A. Wilcox
2019-07-10 20:19                 ` Michael Everitt
2019-07-10 20:45                 ` Rich Felker
2019-07-10 20:48               ` Rich Felker
2019-07-10 21:11                 ` Szabolcs Nagy
2019-07-10 21:16                   ` Rich Felker
2019-07-10 21:44                     ` Szabolcs Nagy
2019-07-10 16:01       ` James Y Knight

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=CAA2zVHqcrtM_r-pnDeQf31Lng2n732No5Vc-JPB7w7CM4+jYVA@mail.gmail.com \
    --to=jyknight@google.com \
    --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).