[libcxx-commits] [PATCH] D80821: [libc++] Return nullptr from an empty array begin()

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 29 11:27:09 PDT 2020


ldionne added a comment.

In D80821#2063583 <https://reviews.llvm.org/D80821#2063583>, @zoecarver wrote:

> @ldionne I disagree. I think we can have all the things here :)
>
> We're going to need four overloads in order to make this work (hopefully factored out into their own helper object):
>
> 1. `N != 0`: use the current implementation (or something equivalent).
> 2. `T` is trivially copyable *and* we're in a constexpr context: hold a `char` array and use bit_cast to convert it to `T*`.


We can't use `bit_cast` for converting pointer types like that. From cppreference / `bit_cast`:

> This function template is constexpr if and only if each of To, From and the types of all subobjects of To and From:
> 
> - is not a union type;
> - is not a pointer type;
> - is not a pointer to member type;
> - is not a volatile-qualified type; and
> - has no non-static data member of reference type.

I really don't think there's a way around this one, as it would need to relax the rules of the constexpr interpreter to allow synthetizing a pointer to a `T` from a pointer to arbitrary memory. We specifically don't allow that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80821/new/

https://reviews.llvm.org/D80821





More information about the libcxx-commits mailing list