aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/array
AgeCommit message (Collapse)AuthorFilesLines
2025-11-24[libc++][array] Applied `[[nodiscard]]` (#168829)Hristo Hristov1-54/+88
`[[nodiscard]]` should be applied to functions where discarding the return value is most likely a correctness issue. - https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant --------- Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-11-11[libc++] Remove __is_replaceable emulation (#167355)Louis Dionne1-2/+0
The Trivial Relocation feature has been removed from the C++26 working draft. Based on discussions in Kona, it is unlikely that the "replaceable" type concept will come back in the C++29 time frame. Since we don't have a use for the type trait in the library at the moment, remove the code associated to it. If we end up needing something like it in the future, we can always add it back.
2025-05-08[libc++] Add the __is_replaceable type trait (#132408)Louis Dionne1-0/+2
That type trait represents whether move-assigning an object is equivalent to destroying it and then move-constructing a new one from the same argument. This will be useful in a few places where we may want to destroy + construct instead of doing an assignment, in particular when implementing some container operations in terms of relocation. This is effectively adding a library emulation of P2786R12's is_replaceable trait, similarly to what we do for trivial relocation. Eventually, we can replace this library emulation by the real compiler-backed trait. This is building towards #129328.
2025-04-19[libc++] Backport segmented iterator optimization for std::for_each to C++11 ↵Peng Liu1-0/+1
(#134960) Previously, the segmented iterator optimization for `std::for_each` was restricted to C++23 and later due to its dependency on `__movable_box`, which is not available in earlier standards. This patch eliminates that restriction, enabling consistent optimizations starting from C++11. By backporting this enhancement, we improve performance across older standards and create opportunities to extend similar optimizations to other algorithms by forwarding their calls to `std::for_each`.
2025-04-09[libc++] Remove _LIBCPP_TEMPLATE_VIS (#134885)Nikolas Klauser1-4/+4
The need for `_LIBCPP_TEMPLATE_VIS` has been removed in #133233.
2025-03-23[libc++] Add [[gnu::nodebug]] on type traits (#128502)Nikolas Klauser1-1/+1
2025-02-21[libc++] Qualify calls to nullary functions like __throw_foo (#122465)Louis Dionne1-4/+4
This is technically not necessary in most cases to prevent issues with ADL, but let's be consistent. This allows us to remove the libcpp-qualify-declval clang-tidy check, which is now enforced by the robust-against-adl clang-tidy check.
2025-01-08[libc++] Put _LIBCPP_NODEBUG on all internal aliases (#118710)Nikolas Klauser1-14/+15
This significantly reduces the amount of debug information generated for codebases using libc++, without hurting the debugging experience.
2024-12-21[libc++][C++03] Use `__cxx03/` headers in C++03 mode (#109002)Nikolas Klauser1-3/+4
This patch implements the forwarding to frozen C++03 headers as discussed in https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc. In the RFC, we initially proposed selecting the right headers from the Clang driver, however consensus seemed to steer towards handling this in the library itself. This patch implements that direction. At a high level, the changes basically amount to making each public header look like this: ``` // inside <vector> #ifdef _LIBCPP_CXX03_LANG # include <__cxx03/vector> #else // normal <vector> content #endif ``` In most cases, public headers are simple umbrella headers so there isn't much code in the #else branch. In other cases, the #else branch contains the actual implementation of the header.
2024-12-13[libc++] Granularize the <new> header (#119270)Louis Dionne1-0/+1
This disentangles the code which previously had a mix of many #ifdefs, a non-versioned namespace and a versioned namespace. It also makes it clearer which parts of <new> are implemented on Windows by including <new.h>.
2024-12-10[libc++] Add #if 0 block to all the top-level headers (#119234)Nikolas Klauser1-90/+93
Including The frozen C++03 headers results in a lot of formatting changes in the main headers, so this splits these changes into a separate commit instead. This is part of https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc.
2024-11-07[libc++] Add support for bounded iterators in std::array (#110729)Louis Dionne1-6/+53
This patch introduces a new kind of bounded iterator that knows the size of its valid range at compile-time, as in std::array. This allows computing the end of the range from the start of the range and the size, which requires storing only the start of the range in the iterator instead of both the start and the size (or start and end). The iterator wrapper is otherwise identical in design to the existing __bounded_iter. Since this requires changing the type of the iterators returned by std::array, this new bounded iterator is controlled by an ABI flag. As a drive-by, centralize the tests for std::array::operator[] and add missing tests for OOB operator[] on non-empty arrays. Fixes #70864
2024-10-31[libc++] Granularize <cstddef> includes (#108696)Nikolas Klauser1-0/+1
2024-09-16[libc++][modules] Fix missing and incorrect includes (#108850)Louis Dionne1-0/+1
This patch adds a large number of missing includes in the libc++ headers and the test suite. Those were found as part of the effort to move towards a mostly monolithic top-level std module.
2024-09-12[libc++][NFC] Use [[__nodiscard__]] unconditionally (#80454)Nikolas Klauser1-2/+2
`__has_cpp_attribute(__nodiscard__)` is always true now, so we might as well replace `_LIBCPP_NODISCARD`. It's one less macro that can result in bad diagnostics.
2024-08-30[libc++][NFC] Run clang-format on libcxx/includeLouis Dionne1-2/+1
This re-formats a few headers that had become out-of-sync with respect to formatting since we ran clang-format on the whole codebase. There's surprisingly few instances of it.
2024-07-30[libc++] fix `array<T, 0>` under `USE_WRAP_ITER` (#101156)nicole mazzuca1-26/+31
`array<T, 0>::iterator` was always a pointer even when `_LIBCXX_ABI_USE_WRAP_ITER_IN_STD_ARRAY` was defined. This patch fixes that minor bug. Discovered as part of [#100603][]. Drive-by: switch from `typedef` to `using` in `<array>` [#100603]: https://github.com/llvm/llvm-project/pull/100603
2024-07-07[libc++] Restore `__synth_three_way` lambda (#90398)Hristo Hristov1-1/+1
Restore `__synth_three_way` lambda to match the Standard. GH-57222 is done, restoring the Standard wording implementation should be possible. https://github.com/llvm/llvm-project/blob/df28d4412c1d21b0e18896c92ac77d2fac7729f1/libcxx/include/__compare/synth_three_way.h#L28 According to comment https://github.com/llvm/llvm-project/issues/59513#issuecomment-2068338762, GH-59513 is not a blocker. Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-06-18[libc++][NFC] Run clang-format on libcxx/include again (#95874)Louis Dionne1-3/+1
As time went by, a few files have become mis-formatted w.r.t. clang-format. This was made worse by the fact that formatting was not being enforced in extensionless headers. This commit simply brings all of libcxx/include in-line with clang-format again. We might have to do this from time to time as we update our clang-format version, but frankly this is really low effort now that we've formatted everything once.
2024-06-18[libc++] Refactor<__type_traits/is_swappable.h> (#86822)Nikolas Klauser1-3/+2
This changes the `is_swappable` implementation to use variable templates first and basing the class templates on that. This avoids instantiating them when the `_v` versions are used, which are generally less resource intensive.
2024-06-17[libc++] Mark more types as trivially relocatable (#89724)Nikolas Klauser1-0/+3
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-04-22[libc++] Remove _LIBCPP_DISABLE_NODISCARD_EXTENSIONS and refactor the tests ↵Nikolas Klauser1-2/+2
(#87094) This also adds a few tests that were missing.
2024-03-18[libc++][NFC] Merge ↵Nikolas Klauser1-2/+0
is{,_nothrow,_trivially}{,_copy,_move,_default}{_assignable,_constructible} (#85308) These headers have become very small by using compiler builtins, often containing only two declarations. This merges these headers, since there doesn't seem to be much of a benefit keeping them separate. Specifically, `is_{,_nothrow,_trivially}{assignable,constructible}` are kept and the `copy`, `move` and `default` versions of these type traits are moved in to the respective headers.
2024-03-14[libc++] Remove a few includes from <__functional/hash.h> (#83254)Nikolas Klauser1-0/+1
This also moves `__all` from `sfinae_helpers.h` to `conjunction.h`.
2024-03-04[libc++] Use __wrap_iter in string_view and array in the unstable ABI (#74482)Louis Dionne1-8/+14
std::string_view and std::array iterators don't have to be raw pointers, and in fact other implementations don't represent them as raw pointers. Them being raw pointers in libc++ makes it easier for users to write non-portable code. This is bad in itself, but this is even worse when considering efforts like hardening where we want an easy ability to swap for a different iterator type. If users depend on iterators being raw pointers, this becomes a build break. Hence, this patch enables the use of __wrap_iter in the unstable ABI, creating a long term path towards making this the default. This patch may break code that assumes these iterators are raw pointers for people compiling with the unstable ABI. This patch also removes several assumptions that array iterators are raw pointers in the code base and in the test suite.
2024-02-29[libc++] Clean up includes of <__assert> (#80091)Louis Dionne1-1/+1
Originally, we used __libcpp_verbose_abort to handle assertion failures. That function was declared from all public headers. Since we don't use that mechanism anymore, we don't need to declare __libcpp_verbose_abort from all public headers, and we can clean up a lot of unnecessary includes. This patch also moves the definition of the various assertion categories to the <__assert> header, since we now rely on regular IWYU for these assertion macros. rdar://105510916
2024-01-25[libc++] Fix missing and incorrect push/pop macros (#79204)Louis Dionne1-0/+5
We recently noticed that the unwrap_iter.h file was pushing macros, but it was pushing them again instead of popping them at the end of the file. This led to libc++ basically swallowing any custom definition of these macros in user code: #define min HELLO #include <algorithm> // min is not HELLO anymore, it's not defined While investigating this issue, I noticed that our push/pop pragmas were actually entirely wrong too. Indeed, instead of pushing macros like `move`, we'd push `move(int, int)` in the pragma, which is not a valid macro name. As a result, we would not actually push macros like `move` -- instead we'd simply undefine them. This led to the following code not working: #define move HELLO #include <algorithm> // move is not HELLO anymore Fixing the pragma push/pop incantations led to a cascade of issues because we use identifiers like `move` in a large number of places, and all of these headers would now need to do the push/pop dance. This patch fixes all these issues. First, it adds a check that we don't swallow important names like min, max, move or refresh as explained above. This is done by augmenting the existing system_reserved_names.gen.py test to also check that the macros are what we expect after including each header. Second, it fixes the push/pop pragmas to work properly and adds missing pragmas to all the files I could detect a failure in via the newly added test. rdar://121365472
2023-12-18[libc++] Format the code base (#74334)Louis Dionne1-293/+242
This patch runs clang-format on all of libcxx/include and libcxx/src, in accordance with the RFC discussed at [1]. Follow-up patches will format the benchmarks, the test suite and remaining parts of the code. I'm splitting this one into its own patch so the diff is a bit easier to review. This patch was generated with: find libcxx/include libcxx/src -type f \ | grep -v 'module.modulemap.in' \ | grep -v 'CMakeLists.txt' \ | grep -v 'README.txt' \ | grep -v 'libcxx.imp' \ | grep -v '__config_site.in' \ | xargs clang-format -i A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh to help resolve merge and rebase issues across these formatting changes. [1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
2023-12-15[libc++] Fix constexpr initialization of std::array<T, 0> (#74667)Louis Dionne1-2/+3
This patch fixes constexpr default initialization of empty arrays and improves the tests accordingly. Fixes #74375
2023-12-05[libc++][NFC] Use aliases instead of typedefs in std::array (#74491)Louis Dionne1-12/+12
As requested in https://github.com/llvm/llvm-project/pull/74482.
2023-12-05[libc++] Replace uses of _VSTD:: by std:: (#74331)Louis Dionne1-13/+13
As part of the upcoming clang-formatting of libc++, this patch performs the long desired removal of the _VSTD macro. See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all for the clang-format proposal.
2023-12-04[libc++] Rename _LIBCPP_INLINE_VISIBILITY to _LIBCPP_HIDE_FROM_ABI (#74095)Louis Dionne1-62/+62
In preparation for running clang-format on the whole code base, we are also removing mentions of the legacy _LIBCPP_INLINE_VISIBILITY macro in favor of the newer _LIBCPP_HIDE_FROM_ABI. We're still leaving the definition of _LIBCPP_INLINE_VISIBILITY to avoid creating needless breakage in case some older patches are checked-in with mentions of the old macro. After we branch for LLVM 18, we can do another pass to clean up remaining uses of the macro that might have gotten introduced by mistake (if any) and remove the macro itself at the same time. This is just a minor convenience to smooth out the transition as much as possible. See https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all for the clang-format proposal.
2023-09-01[libc++][NFC] Refactor __enable_if return types to defaulted template parametersNikolas Klauser1-2/+2
This brings most of the enable_ifs in libc++ to the same style. It also has the nice side-effect of reducing the size of names of these symbols, since the depedent return type is shorter. Reviewed By: #libc, ldionne Spies: ldionne, libcxx-commits Differential Revision: https://reviews.llvm.org/D157787
2023-07-20[libc++][hardening] Categorize most assertions inside the container classes.varconst1-8/+8
This introduces: - `_LIBCPP_ASSERT_VALID_INPUT_RANGE`; - `_LIBCPP_ASSERT_VALID_CONTAINER_ACCESS`; - `_LIBCPP_ASSERT_VALID_ITERATOR_ACCESS`; - `_LIBCPP_ASSERT_VALID_ALLOCATOR`; - `_LIBCPP_ASSERT_INTERNAL`. Differential Revision: https://reviews.llvm.org/D155349
2023-07-07[libc++][Modules] Add missing __fwd includesIan Anderson1-0/+1
A few __fwd includes are missing from public modules that will become noticeable when the private submodules are split into their own top level modules (D144322). Add the missing includes. Reviewed By: ldionne, philnik, #libc Differential Revision: https://reviews.llvm.org/D153216
2023-06-28[libc++][hardening][NFC] Introduce `_LIBCPP_ASSERT_UNCATEGORIZED`.varconst1-8/+8
Replace most uses of `_LIBCPP_ASSERT` with `_LIBCPP_ASSERT_UNCATEGORIZED`. This is done as a prerequisite to introducing hardened mode to libc++. The idea is to make enabling assertions an opt-in with (somewhat) fine-grained controls over which categories of assertions are enabled. The vast majority of assertions are currently uncategorized; the new macro will allow turning on `_LIBCPP_ASSERT` (the underlying mechanism for all kinds of assertions) without enabling all the uncategorized assertions (in the future; this patch preserves the current behavior). Differential Revision: https://reviews.llvm.org/D153816
2023-05-08[libc++][spaceship] Implement `operator<=>` for `array`Hristo Hristov1-27/+28
Implements part of P1614R2 "The Mothership has Landed" Reviewed By: Mordante, #libc, philnik Differential Revision: https://reviews.llvm.org/D132265
2023-04-16[libc++] Add hide_from_abi check for classesNikolas Klauser1-2/+2
We already have a clang-tidy check for making sure that `_LIBCPP_HIDE_FROM_ABI` is on free functions. This patch extends this to class members. The places where we don't check for `_LIBCPP_HIDE_FROM_ABI` are classes for which we have an instantiation in the library. Reviewed By: ldionne, Mordante, #libc Spies: jplehr, mikhail.ramalho, sstefan1, libcxx-commits, krytarowski, miyuki, smeenai Differential Revision: https://reviews.llvm.org/D142332
2023-04-12[libc++] Rename __tuple_dir back to __tupleNikolas Klauser1-3/+3
This essentially reverts D139270 Reviewed By: #libc, EricWF Spies: tahonermann, libcxx-commits, arichardson Differential Revision: https://reviews.llvm.org/D147519
2023-04-09[libc++] Remove <cstdlib> includesNikolas Klauser1-0/+1
We changed the `abort` calls when trying to throw exceptions in `-fno-exceptions` mode to `__verbose_abort` calls, which removes the dependency in most files. Reviewed By: ldionne, #libc Spies: dim, emaste, mikhail.ramalho, smeenai, libcxx-commits Differential Revision: https://reviews.llvm.org/D146076
2023-03-08[libc++] Granularize <type_traits> includesNikolas Klauser1-1/+11
Reviewed By: ldionne, #libc, #libc_abi Spies: #libc_vendors, smeenai, libcxx-commits Differential Revision: https://reviews.llvm.org/D145320
2023-02-15[libc++][NFC] Replace _LIBCPP_STD_VER > x with _LIBCPP_STD_VER >= xNikolas Klauser1-3/+3
This change is almost fully mechanical. The only interesting change is in `generate_feature_test_macro_components.py` to generate `_LIBCPP_STD_VER >=` instead. To avoid churn in the git-blame this commit should be added to the `.git-blame-ignore-revs` once committed. Reviewed By: ldionne, var-const, #libc Spies: jloser, libcxx-commits, arichardson, arphaman, wenlei Differential Revision: https://reviews.llvm.org/D143962
2022-12-21[libc++] Rename __tuple to __tuple_dir to avoid file collisionMichał Górny1-3/+3
Rename the `__tuple` directory in libc++ headers to `__tuple_dir` to avoid file collision when installing. Historically, `__tuple` has been a file and it has been replaced by a directory in 2d52c6bfae801b016dd3627b8c0e7c4a99405549. Replacing a regular file with a directory (or more importantly, the other way around when downgrading) is not universally supported. Since this is an internal header, its actual name should not matter, so just rename it to avoid problems. Differential Revision: https://reviews.llvm.org/D139270
2022-11-05[libc++] Granularize <concept> includesNikolas Klauser1-0/+1
Reviewed By: ldionne, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D137283
2022-10-01[libc++][NFC] Prefer type aliases over structsNikolas Klauser1-2/+1
Reviewed By: ldionne, #libc Spies: sstefan1, libcxx-commits, jeroen.dobbelaere Differential Revision: https://reviews.llvm.org/D134901
2022-09-05[libc++] Granularize __tupleNikolas Klauser1-1/+5
Reviewed By: ldionne, #libc Spies: libcxx-commits, mgorny Differential Revision: https://reviews.llvm.org/D133081
2022-09-03[NFC][libc++] Moves transitive includes location.Mark de Wever1-6/+6
As discussed in D132284 they will be moved to the end. Reviewed By: #libc, Mordante Differential Revision: https://reviews.llvm.org/D133212
2022-08-31[libc++] Reduces the number of transitive includes.Mark de Wever1-1/+1
This defines a new policy for removal of transitive includes. The goal of the policy it to make it relatively easy to remove headers when needed, but avoid breaking developers using and vendors shipping libc++. The method used is to guard transitive includes based on the C++ language version. For the upcoming C++23 we can remove headers when we want, but for other language versions we try to keep it to a minimum. In this code the transitive include of `<chrono>` is removed since D128577 introduces a header cycle between `<format>` and `<chrono>`. This cycle is indirectly required by the Standard. Our cycle dependency tool basically is a grep based tool, so it needs some hints to ignore cycles. With the input of our transitive include tests we can create a better tool. However that's out of the scope of this patch. Note the flag `_LIBCPP_REMOVE_TRANSITIVE_INCLUDES` remains unchanged. So users can still opt-out of transitives includes entirely. Reviewed By: #libc, ldionne, philnik Differential Revision: https://reviews.llvm.org/D132284
2022-08-19[libc++][NFC] Rename the constexpr macrosNikolas Klauser1-59/+59
This was discussed on Discord with the consensus that we should rename the macros. Reviewed By: ldionne, Mordante, var-const, avogelsgesang, jloser, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D131498
2022-07-04[libc++][NFC] Replace enable_if with __enable_if_t in a few placesNikolas Klauser1-6/+1
Reviewed By: ldionne, #libc Spies: jloser, libcxx-commits Differential Revision: https://reviews.llvm.org/D128400