libstdc++: Dangling braced-init-list access is now ill-formed.
Accessing dangling braced-init-list using `std::begin`, `std::end`, and `std::data` is now ill-formed, as per P3016R6.
The libstdc++ now implements section 4.6 of P3016R6. Immediately dangling invocations of std::begin, std::end, and std::data on braced-init-lists are now ill-formed. To keep std::data(il) and std::empty(il) well-formed, the data and empty members are added to initializer_list. Calls to std::rbegin and std::rend remain well-formed due to preserved overloads.
In Details
This commit implements changes from P3016R6 regarding initializer_list and range access. The key change is making dangling accesses via std::begin, std::end, and std::data on braced-init-lists ill-formed, requiring the addition of data and empty members to initializer_list. The impact is primarily on code using these functions with braced-init-lists, potentially leading to compilation errors where previously the behavior was unspecified.
For Context
In C++, an initializer_list allows functions to accept a variable number of arguments of the same type, often using the brace syntax (e.g., {1, 2, 3}). The standard library provides functions like std::begin, std::end, and std::data to access the elements within these lists. However, using these functions on a temporary initializer_list could lead to dangling pointers if the list is destroyed before the pointers are used. This commit enforces that such usage is now an error, preventing potential crashes or undefined behavior. It also ensures that std::data and std::empty remain valid for initializer lists.