This patch fixes llvm.org/PR35491 and LWG2157 (https://cplusplus.github.io/LWG/issue2157)
The fix attempts to maintain ABI compatibility by replacing the array with a instance of aligned_storage.
Differential D41223
[libc++] Fix PR35491 - std::array of zero-size doesn't work with non-default constructible types. EricWF on Dec 13 2017, 10:45 PM. Authored by
Details
This patch fixes llvm.org/PR35491 and LWG2157 (https://cplusplus.github.io/LWG/issue2157) The fix attempts to maintain ABI compatibility by replacing the array with a instance of aligned_storage.
Diff Detail
Event Timeline
Comment Actions I'm wondering if it's not a better idea to have an explicit specialization for size == 0 template <class T> class array<T, 0> { // and so on. }; Comment Actions BTW, this is https://cplusplus.github.io/LWG/issue2157 , so please update www accordingly, and also test {{}} cases. Comment Actions I think that's probably more work than it's worth. I think we should change the primary template to support the bare minimum number of operations, and then let the rest of the operations blow up if users attempt to use them. The www pages will get updated when the issue is actually accepted, which it currently isn't.
I don't agree those cases are valid. That initialization syntax suggests there is something in the zero-sized array which is default constructible - or that users should be able to control construction of. I disagree with that.
Comment Actions Nevermind, I see STL is insisting that case be handled. I'll add tests and then complain to him later. Comment Actions The lack of _LIBCPP_CONSTEXPR_AFTER_CXX14 on the array<T, 0> specialization's begin(), end(), and other methods seems to be a bug: https://stackoverflow.com/questions/60462569/empty-stdarrayt-0-doesnt-have-constexpr-begin |
Just asking: no compiler is dumb enough to not inline this entirely trivial wrapper so that it's okay to not to propagate noexcept here to avoid try...capture...terminate codegen in its caller side?