gnu/gcc/9df83006384d5d6dbfc2bb53f090791862f7ed67 libstdc++: Add data/member for initializer_list, and remove std overloads
This implements changes section 4.6 of P3016R6, and initializer_list related
parts of 4.7 and 4.8. The change makes immediately dangling invocations of
std::begin, std::end, and std::data on braced-init list ill-formed (see
range_access_neg.cc and range_access17_neg.cc):
auto it = std::begin({1, 2, 3}); // ILL-FORMED, it was dangling
(it == std::end({1, 2, 3})); // ILL-FORMED, was unspecified
auto* ptr = std::data({1, 2, 3}); // ILL-FORMED, ptr was dangling
However, similary problemetic calls for std::rbegin, std::rend remain
well-formed (see range_access14_neg.cc), as initializer_list overloads
are preserved for these functions:
auto rit = ranges::rbegin({1, 2, 3}); // COMPILES, dangling
auto rend = ranges::rend({1, 2, 3}); // COMPILES, danging
Note, that non-problematic std::size({1, 2, 3}) and std::empty({1, 2, 3})
use c-array overloads, and remain well-formed.
Per paper, to keep std::data(il) and std::empty(il) well-formed, the data
and empty member are added to initializer_list.
libstdc++-v3/ChangeLog:
* include/bits/version.def (initializer_list): Define with value
202511 for C++26.
* include/bits/version.h: Regenerate.
* libsupc++/initializer_list (initializer_list::data)
(initializer_list::empty) [__glibcxx_initializer_list >= 202511L]:
Define.
(std::begin(initializer_list<_Tp>), std::end(initializer_list<_Tp>)):
Define only if __glibcxx_initializer_list < 202511L (i.e. not defined).
* include/bits/range_access.h (std::empty(initializer_list<_Tp>))
(std::data(initializer_list<_Tp>)): Define only if
__glibcxx_initializer_list < 202511L (i.e. not defined).
* testsuite/18_support/initializer_list/range_access.cc: Move test for
brace-init list to range_access_neg.c. Included <iterator> in C++26 or
later mode.
* testsuite/18_support/initializer_list/data_empty_mem.cc: New test.
* testsuite/18_support/initializer_list/range_access14.cc: New test.
* testsuite/18_support/initializer_list/range_access14_neg.cc: New test.
* testsuite/18_support/initializer_list/range_access17.cc: New test.
* testsuite/18_support/initializer_list/range_access17_neg.cc: New test.
* testsuite/18_support/initializer_list/range_access_neg.cc: New test.
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
11 files changed