xref: /llvm-project/libcxx/docs/ReleaseNotes/20.rst (revision 08a18efc664a85b4db8ca46ac986ec2d154ae433)
133af4bd7SLouis Dionne===========================================
233af4bd7SLouis DionneLibc++ 20.0.0 (In-Progress) Release Notes
333af4bd7SLouis Dionne===========================================
433af4bd7SLouis Dionne
533af4bd7SLouis Dionne.. contents::
633af4bd7SLouis Dionne   :local:
733af4bd7SLouis Dionne   :depth: 2
833af4bd7SLouis Dionne
933af4bd7SLouis DionneWritten by the `Libc++ Team <https://libcxx.llvm.org>`_
1033af4bd7SLouis Dionne
1133af4bd7SLouis Dionne.. warning::
1233af4bd7SLouis Dionne
1333af4bd7SLouis Dionne   These are in-progress notes for the upcoming libc++ 20.0.0 release.
1433af4bd7SLouis Dionne   Release notes for previous releases can be found on
1533af4bd7SLouis Dionne   `the Download Page <https://releases.llvm.org/download.html>`_.
1633af4bd7SLouis Dionne
1733af4bd7SLouis DionneIntroduction
1833af4bd7SLouis Dionne============
1933af4bd7SLouis Dionne
2033af4bd7SLouis DionneThis document contains the release notes for the libc++ C++ Standard Library,
2133af4bd7SLouis Dionnepart of the LLVM Compiler Infrastructure, release 20.0.0. Here we describe the
2233af4bd7SLouis Dionnestatus of libc++ in some detail, including major improvements from the previous
2333af4bd7SLouis Dionnerelease and new feature work. For the general LLVM release notes, see `the LLVM
2433af4bd7SLouis Dionnedocumentation <https://llvm.org/docs/ReleaseNotes.html>`_. All LLVM releases may
2533af4bd7SLouis Dionnebe downloaded from the `LLVM releases web site <https://llvm.org/releases/>`_.
2633af4bd7SLouis Dionne
2733af4bd7SLouis DionneFor more information about libc++, please see the `Libc++ Web Site
2833af4bd7SLouis Dionne<https://libcxx.llvm.org>`_ or the `LLVM Web Site <https://llvm.org>`_.
2933af4bd7SLouis Dionne
3033af4bd7SLouis DionneNote that if you are reading this file from a Git checkout or the
3133af4bd7SLouis Dionnemain Libc++ web page, this document applies to the *next* release, not
3233af4bd7SLouis Dionnethe current one. To see the release notes for a specific release, please
3333af4bd7SLouis Dionnesee the `releases page <https://llvm.org/releases/>`_.
3433af4bd7SLouis Dionne
3533af4bd7SLouis DionneWhat's New in Libc++ 20.0.0?
3633af4bd7SLouis Dionne==============================
3733af4bd7SLouis Dionne
38*08a18efcSMark de WeverThe main focus of the libc++ team has been to implement new C++20, C++23, and C++26 features.
39*08a18efcSMark de Wever
4033af4bd7SLouis DionneImplemented Papers
4133af4bd7SLouis Dionne------------------
4233af4bd7SLouis Dionne
4363eb40eeSA. Jiang- P0619R4: Reviewing Deprecated Facilities of C++17 for C++20 (`Github <https://github.com/llvm/llvm-project/issues/99985>`__)
447808541fSA. Jiang- P2747R2: ``constexpr`` placement new (`Github <https://github.com/llvm/llvm-project/issues/105427>`__)
45026210e8SA. Jiang- P2609R3: Relaxing Ranges Just A Smidge (`Github <https://github.com/llvm/llvm-project/issues/105253>`__)
461c48c9ccSLouis Dionne- P2985R0: A type trait for detecting virtual base classes (`Github <https://github.com/llvm/llvm-project/issues/105432>`__)
4799174842SLouis Dionne- ``std::jthread`` and ``<stop_token>`` are not guarded behind ``-fexperimental-library`` anymore
48a06591b4SHristo Hristov- P2674R1: A trait for implicit lifetime types (`Github <https://github.com/llvm/llvm-project/issues/105259>`__)
49*08a18efcSMark de Wever- P0429R9: A Standard ``flat_map`` (`Github <https://github.com/llvm/llvm-project/issues/105190>`__)
5033af4bd7SLouis Dionne
5133af4bd7SLouis DionneImprovements and New Features
5233af4bd7SLouis Dionne-----------------------------
5333af4bd7SLouis Dionne
54d07fdf97SNikolas Klauser- The ``lexicographical_compare`` and ``ranges::lexicographical_compare`` algorithms have been optimized for trivially
55d07fdf97SNikolas Klauser  equality comparable types, resulting in a performance improvement of up to 40x.
5633af4bd7SLouis Dionne
5794e7c0b0SA. Jiang- The ``_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER`` macro has been added to make ``std::get_temporary_buffer`` and
5894e7c0b0SA. Jiang  ``std::return_temporary_buffer`` available.
5994e7c0b0SA. Jiang
60df3ba91dSLouis Dionne- The ``std::uncaught_exception`` function was marked as deprecated since C++17 and removed since C++20. The
61df3ba91dSLouis Dionne  ``_LIBCPP_ENABLE_CXX20_REMOVED_UNCAUGHT_EXCEPTION`` macro has been added to make ``std::uncaught_exception``
622fb133f3SNikolas Klauser  available in C++20 and later modes.
634ea2c738SA. Jiang
6427c83382SNikolas Klauser- The internal structure ``__compressed_pair`` has been replaced with ``[[no_unique_address]]``, resulting in reduced
6527c83382SNikolas Klauser  compile times and smaller debug information as well as better code generation if optimizations are disabled.
6627c83382SNikolas Klauser  The Chromium project measured a 5% reduction in object file and debug information size.
6733af4bd7SLouis Dionne
68dfe737f2SLouis Dionne- The ``_LIBCPP_ABI_BOUNDED_UNIQUE_PTR`` ABI configuration was added, which allows ``std::unique_ptr<T[]>`` to
69dfe737f2SLouis Dionne  detect out-of-bounds accesses in certain circumstances. ``std::unique_ptr<T[]>`` can now also detect out-of-bounds
70dfe737f2SLouis Dionne  accesses for a limited set of types (non-trivially destructible types) when the ABI configuration is disabled.
71dfe737f2SLouis Dionne
72427a5cf1SLouis Dionne- The ``_LIBCPP_ABI_BOUNDED_ITERATORS_IN_STD_ARRAY`` ABI configuration was added, which allows storing valid bounds
73427a5cf1SLouis Dionne  in ``std::array::iterator`` and detecting OOB accesses when the appropriate hardening mode is enabled.
74427a5cf1SLouis Dionne
750298e58cSPeng Liu- The ``input_iterator``-pair overload of ``void assign(InputIt, InputIt)`` has been optimized for ``std::vector``,
760298e58cSPeng Liu  resulting in a performance improvement of up to 2x for trivial element types (e.g., ``std::vector<int>``), and up
770298e58cSPeng Liu  to 3.4x for non-trivial element types (e.g., ``std::vector<std::vector<int>>``).
780298e58cSPeng Liu
790298e58cSPeng Liu- The ``input_iterator``-pair overload of ``iterator insert(const_iterator, InputIt, InputIt)`` has been optimized
800298e58cSPeng Liu  for ``std::vector``, resulting in a performance improvement of up to 10x for ``std::vector<int>``, and up to 2.3x
810298e58cSPeng Liu  for ``std::vector<std::vector<int>>``.
82056153f3SPeng Liu
832b26ee6eSJames Y Knight- On Windows, ``<system_error>``'s ``std::system_category`` is now distinct from ``std::generic_category``. The behavior
842b26ee6eSJames Y Knight  on other operating systems is unchanged.
852b26ee6eSJames Y Knight
862b26ee6eSJames Y Knight  On Windows -- unlike on Unix systems -- the libc and system APIs use distinct error codes. The libc functions return
872b26ee6eSJames Y Knight  ``errno.h`` error codes via the ``errno`` global, while Win32 API functions return ``winerror.h`` error codes via
882b26ee6eSJames Y Knight  ``GetLastError()``.
892b26ee6eSJames Y Knight
902b26ee6eSJames Y Knight  The C++ standard's ``std::error_code`` and ``std::error_category`` functionality was designed to support multiple
912b26ee6eSJames Y Knight  error domains, precisely in order to handle situations such as this. However, libc++ formerly treated
922b26ee6eSJames Y Knight  ``generic_category()`` and ``system_category()`` as equivalent, even on Windows. It now implements the intended split,
932b26ee6eSJames Y Knight  where ``system_category`` represents native ``winerror.h`` error codes, and ``generic_category`` represents libc error
942b26ee6eSJames Y Knight  codes (and, equivalently, ``std::errc::*`` errors).
952b26ee6eSJames Y Knight
962b26ee6eSJames Y Knight  This change enables code like ``std::error_code(GetLastError(), std::system_category()) ==
972b26ee6eSJames Y Knight  std::errc::invalid_argument`` to function as desired: constructing an ``error_code`` with the Windows error number in
982b26ee6eSJames Y Knight  the "system" category, and then mapping it to a generic code with ``error_condition``, for comparison with the
992b26ee6eSJames Y Knight  ``std::errc`` constant.
1002b26ee6eSJames Y Knight
1012b26ee6eSJames Y Knight  This is an incompatible change: ``std::error_code(ENOSYS, std::system_category()) ==
1022b26ee6eSJames Y Knight  std::errc::function_not_supported`` would formerly have returned true, but now returns false on Windows. Code
1032b26ee6eSJames Y Knight  providing a number from the ``errno.h`` domain should be migrated to construct a ``generic_category`` error_code,
1042b26ee6eSJames Y Knight  instead. (E.g., use ``std::error_code(ENOSYS, std::generic_category())``). The new behavior matches MSVC.
1052b26ee6eSJames Y Knight
1062b26ee6eSJames Y Knight- On Windows, the ``std::filesystem`` library now returns the Win32 ``system_category`` error codes, where it's feasible
1072b26ee6eSJames Y Knight  to do so. This allows interrogation and reporting of the original error code, which is useful if multiple Windows
1082b26ee6eSJames Y Knight  errors map to a single generic error (such as with ``std::errc::no_such_file_or_directory``).
1092b26ee6eSJames Y Knight
1102b26ee6eSJames Y Knight  This is also a slightly-incompatible API change: code inspecting the raw integer value from the returned error_code
1112b26ee6eSJames Y Knight  expecting an integer from ``generic_category`` (e.g. ``err.value() == ENOTDIR``) will not work as desired. Instead,
1122b26ee6eSJames Y Knight  such code should use the comparison operators which implicitly handle eror mappings, ``err ==
1132b26ee6eSJames Y Knight  std::errc::not_a_directory``, or use ``err.default_error_condition()`` to map to an ``error_condition``, and then test
1142b26ee6eSJames Y Knight  its ``value()`` and ``category()``.
1152b26ee6eSJames Y Knight
116*08a18efcSMark de Wever- ``std::stable_sort`` uses radix sort for integral types now, which can improve the performance up to 10 times, depending
117*08a18efcSMark de Wever  on type of sorted elements and the initial state of the sorted array.
118*08a18efcSMark de Wever
119*08a18efcSMark de Wever- Reduced the amount of debug information generated for internal typedefs. This reduces the size of debug builds.
120*08a18efcSMark de Wever
121*08a18efcSMark de Wever- Added :ref:`hardening mode <hardening>` support for ``forward_list`` and ``bitset``.
122*08a18efcSMark de Wever
12333af4bd7SLouis DionneDeprecations and Removals
12433af4bd7SLouis Dionne-------------------------
12533af4bd7SLouis Dionne
126c9d9dc9cSLouis Dionne- The ``LIBCXX_ENABLE_ASSERTIONS`` CMake variable and the ``_LIBCPP_ENABLE_ASSERTIONS`` macro that were used to
127c9d9dc9cSLouis Dionne  enable the safe mode have been removed in LLVM 20. Please use :ref:`support for hardening <using-hardening-modes>`
128c9d9dc9cSLouis Dionne  instead.
12933af4bd7SLouis Dionne
130bf1666fbSLouis Dionne- Support for the C++20 synchronization library (``<barrier>``, ``<latch>``, ``atomic::wait``, etc.) has been
131bf1666fbSLouis Dionne  removed in language modes prior to C++20. If you are using these features prior to C++20, you will need to
132bf1666fbSLouis Dionne  update to ``-std=c++20``.
13345bc8560SLouis Dionne
13485ca5517SA. Jiang- The relational operators for ``std::chrono::weekday`` has been removed entirely, and the
13585ca5517SA. Jiang  ``_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`` macro is now ignored.
136684a6150SA. Jiang
1372fb133f3SNikolas Klauser- The ``_LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST`` macro no longer has any effect. ``std::allocator<const T>`` is not
1382fb133f3SNikolas Klauser  supported as an extension anymore, please migrate any code that uses e.g. ``std::vector<const T>`` to be
1392fb133f3SNikolas Klauser  standards conforming.
14033af4bd7SLouis Dionne
141*08a18efcSMark de Wever- Non-conforming member typedefs ``base``, ``iterator``, ``const_iterator``, ``size_type``, ``difference_type``, and
142*08a18efcSMark de Wever  ``const_reference`` of ``std::bitset``, and member typedef ``base`` of ``std::forward_list`` and ``std::list`` are
143*08a18efcSMark de Wever  removed. Previously, these member typedefs (except ``const_reference``) were private but could cause ambiguity in name
144*08a18efcSMark de Wever  lookup. Code that expects such ambiguity will possibly not compile in LLVM 20.
145159d694cSA. Jiang
14695483663SDoug Wyatt- The function ``__libcpp_verbose_abort()`` is now ``noexcept``, to match ``std::terminate()``. (The combination of
147d269ec32SLouis Dionne  ``noexcept`` and ``[[noreturn]]`` has special significance for function effects analysis.) For backwards compatibility,
148d269ec32SLouis Dionne  the ``_LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT`` macro can be defined to make the function non-``noexcept``. That macro
149d269ec32SLouis Dionne  will be removed in LLVM 21.
15095483663SDoug Wyatt
15163eb40eeSA. Jiang- ``<ccomplex>``, ``<cstdalign>`` (previously missing), ``<cstdbool>``, and ``<ctgmath>`` are deprecated since C++17 as
15263eb40eeSA. Jiang  specified by the standard. They, together with ``<ciso646>``, are removed in C++20, but libc++ still provides these
15363eb40eeSA. Jiang  headers as an extension and only deprecates them. The ``_LIBCPP_DISABLE_DEPRECATION_WARNINGS`` macro can be defined to
15463eb40eeSA. Jiang  suppress deprecation for these headers.
15563eb40eeSA. Jiang
156afae1a5fSLouis Dionne- The ``_LIBCPP_DISABLE_AVAILABILITY`` macro that was used to force-disable availability markup has now been removed.
157afae1a5fSLouis Dionne  Whether availability markup is used by the library is now solely controlled at configuration-time.
158afae1a5fSLouis Dionne
1596cbc3738SNikolas Klauser- The pointer safety functions ``declare_reachable``, ``declare_no_pointers``, ``undeclare_no_pointers`` and
1606cbc3738SNikolas Klauser  ``__undeclare_reachable`` have been removed from the library. These functions were never implemented in a non-trivial
1616cbc3738SNikolas Klauser  way, making it very unlikely that any binary depends on them.
1626cbc3738SNikolas Klauser
163019a902aSA. Jiang- Non-conforming extension ``packaged_task::result_type`` is deprecated. It will be removed in LLVM 21.
164019a902aSA. Jiang
16533af4bd7SLouis DionneUpcoming Deprecations and Removals
16633af4bd7SLouis Dionne----------------------------------
16733af4bd7SLouis Dionne
168e9bb4e30SMark de WeverLLVM 21
169e9bb4e30SMark de Wever~~~~~~~
170e9bb4e30SMark de Wever
1712fb133f3SNikolas Klauser- The status of the C++03 implementation will be frozen after the LLVM 21 release. This means that starting in LLVM 22,
1722fb133f3SNikolas Klauser  non-critical bug fixes may not be back-ported to C++03, including LWG issues. C++03 is a legacy platform, where most
1732fb133f3SNikolas Klauser  projects are no longer actively maintained. To reduce the amount of fixes required to keep such legacy projects
1742fb133f3SNikolas Klauser  compiling with up-to-date toolchains, libc++ will aim to freeze the status of the headers in C++03 mode to avoid
1752fb133f3SNikolas Klauser  unintended breaking changes. See https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc for more details.
176e9bb4e30SMark de Wever
1772fb133f3SNikolas Klauser  If you are using C++03 in your project, you should consider moving to a newer version of the Standard to get the most
1782fb133f3SNikolas Klauser  out of libc++.
179e9bb4e30SMark de Wever
180d269ec32SLouis Dionne- The ``_LIBCPP_VERBOSE_ABORT_NOT_NOEXCEPT`` macro will be removed in LLVM 21, making ``std::__libcpp_verbose_abort``
181d269ec32SLouis Dionne  unconditionally ``noexcept``.
182d269ec32SLouis Dionne
183019a902aSA. Jiang- Non-conforming extension ``packaged_task::result_type`` will be removed in LLVM 21.
184019a902aSA. Jiang
185e9bb4e30SMark de Wever
18633af4bd7SLouis DionneABI Affecting Changes
18733af4bd7SLouis Dionne---------------------
18833af4bd7SLouis Dionne
18901df775dSNikolas Klauser- The ABI breaks for removing undefined behaviour in ``std::forward_list``, ``std::list``, ``std::map``, ``std::set``,
19001df775dSNikolas Klauser  ``std::multimap``, ``std::multiset``, ``std::unordered_map``, ``std::unordered_set``, ``std::unordered_multimap`` and
19101df775dSNikolas Klauser  ``std::unordered_multiset`` are now applied unconditionally. This only affects fancy pointers which have a different
19201df775dSNikolas Klauser  value representation when pointing at the base of an internal node type instead of the type itself. A size or
19301df775dSNikolas Klauser  alignment difference is diagnosed, but more subtle ABI breaks may result in unexpected behaviour.
19401df775dSNikolas Klauser
19527c83382SNikolas Klauser- The internal structure ``__compressed_pair`` has been replaced with ``[[no_unique_address]]``. The ABI impact is:
19633af4bd7SLouis Dionne
19727c83382SNikolas Klauser  - When using the Itanium ABI (most non-MSVC platforms), empty types are now placed at the beginning of the enclosing
19827c83382SNikolas Klauser    object instead of where the beginning of the ``__compressed_pair`` subobject was. This is only observable by
19927c83382SNikolas Klauser    checking the address of the empty allocator, equality comparator or hasher.
20027c83382SNikolas Klauser  - Additionally, using an overaligned empty type as an allocator, comparator or hasher in the associative containers
20127c83382SNikolas Klauser    (and only those containers) may result in the container's object object size and data layout changing beyond only
20227c83382SNikolas Klauser    the address of the empty member.
20327c83382SNikolas Klauser  - When using the MSVC ABI, this change results in some classes having a completely different memory layout, so this is
20427c83382SNikolas Klauser    a genuine ABI break. However, the library does not currently guarantee ABI stability on MSVC platforms.
20533af4bd7SLouis Dionne
206084309a0SLouis Dionne- The localization support base API has been reimplemented, leading to different functions being exported from the
207084309a0SLouis Dionne  libc++ built library on Windows and Windows-like platforms.
208