This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
Section: 17.7 [support.rtti], 17.10 [support.initlist], 17.11 [cmp] Status: New Submitter: Jiang An Opened: 2021-10-23 Last modified: 2022-01-29
Priority: 3
View all issues with New status.
Discussion:
Standard library headers <typeinfo>, <initializer_list>, and <compare> are required for some core language features, as specified in 7.6.1.8 [expr.typeid]/7, 9.4.5 [dcl.init.list]/2, and 7.6.8 [expr.spaceship]/8. In C++11 (via N2930), every header that has dependency on std::initializer_list is required to include <initializer_list>. The similar requirements are added for operator<=> and <compare> in C++20 (via LWG 3330).
As N2930 and LWG3330 have been adpoted, IMO there are some inconsistencies in the standard library now:No operation is done for <typeinfo>, although <typeindex> (std::type_index), <functional> (std::function, since C++11), and <any> (std::any) have dependency on std::type_info;
<iterator> has dependency on std::initializer_list since C++14/LWG 2128 (the std::rbegin overload and its friends), but it is not required to include <initializer_list>;
<stacktrace> is not required to include <compare> while it provides operator <=> overloads.
The situation may be quite serious for std::type_index. Perhaps no expected operation on std::type_index is guaranteed to work when only <typeindex> but not <typeinfo> is included.
libc++, libstdc++, and MSVC STL include <typeinfo> and <initializer_list> when the required standard interface depends on them. I think we should standardize the existing practice (except that <stackstrace> has not been implemented now) to reduce uncertainty for users.[2021-10-24; Daniel comments]
This issue is related to and depending on LWG 3625.
[2022-01-29; Reflector poll]
Set priority to 3 after reflector poll.
Proposed resolution:
This wording is relative to N4901.
[Drafting note: The proposed wording below contains one conditional change, it is therefore depending upon LWG 3625.]
Add #include <typeinfo> to 22.7.2 [any.synop], 22.10.2 [functional.syn], and 22.11.1 [type.index.synopsis].
Add #include <initializer_list> to 25.2 [iterator.synopsis].
Add #include <compare> to 19.6.2 [stacktrace.syn].
If we decide to add range access function templates (25.7 [iterator.range]) to <stacktrace>, we should also add #include <initializer_list> to 19.6.2 [stacktrace.syn].