[libcxx-commits] [libcxx] [libc++] Fix constexpr initialization of std::array<T, 0> (PR #74667)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 14 14:49:00 PST 2023


ldionne wrote:

> Hmm, So I see we already migrated away from not returning `nullptr` from `array<T, 0>`. My understanding was that was explicitly prohibited by the standard when it says
> 
> [2](https://eel.is/c++draft/sequences#array.zero-2) [#](https://github.com/Eelis/draft/tree/180690ab2654988b5d40bfe2f50b32737f02f20b/source/containers.tex#L6391) In the case that N == 0, begin() == end() == unique value[.](https://eel.is/c++draft/sequences#array.zero-2.sentence-1) The return value of data() is unspecified[.](https://eel.is/c++draft/sequences#array.zero-2.sentence-2)
> 
> The "unique" bit specifically saying that the two arrays can't both return nullptr.
> 
> I think we may have strayed from the right implementation here, and done it a while ago. I would like to consider this more.

Just to be clear though, this patch doesn't affect whether we return `nullptr` or not from `begin()`, nor our ability to do so. It only fixes cases where we should be able to initialize an empty array inside `constexpr` and we currently can't, without breaking the ABI. If you wanted to return `nullptr` from `begin()` (which I think you can't without contradicting the standard), you could in theory do it orthogonally to this patch.

https://github.com/llvm/llvm-project/pull/74667


More information about the libcxx-commits mailing list