aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/__utility
AgeCommit message (Collapse)AuthorFilesLines
6 daysReapply "[libc++] Refactor key extraction for __hash_table and __tree ↵Nikolas Klauser1-0/+114
(#154512)" (#155565) The original PR has been reverted because of an LLDB test failure. This patch now works around the test failure by simply allowing the new symbols to show up in a stack trace. This reverts commit 72c04bb882ad70230bce309c3013d9cc2c99e9a7. Original commit message: This patch replaces `__can_extract_key` with an overload set to try to extract the key. This simplifies the code, since we don't need to have separate overload sets for the unordered and associative containers. It also allows extending the set of extraction cases more easily, since we have a single place to define how the key is extracted.
7 daysRevert "[libc++] Refactor key extraction for __hash_table and __tree (#154512)"Aiden Grossman1-114/+0
This reverts commit af1f06e41b05c267480f1629dc0fcdf18f3b59f6. This is causing some build failures in premerge as some of the LLDB tests fail.
7 days[libc++] Refactor key extraction for __hash_table and __tree (#154512)Nikolas Klauser1-0/+114
This patch replaces `__can_extract_key` with an overload set to try to extract the key. This simplifies the code, since we don't need to have separate overload sets for the unordered and associative containers. It also allows extending the set of extraction cases more easily, since we have a single place to define how the key is extracted.
7 days[libc++] Remove a few incorrect _LIBCPP_EXPORTED_FROM_ABI annotations (#132602)Nikolas Klauser1-1/+1
This has two benefits: - It is less likely that the macro will be copy-pasted around when unnecessary - We can drop `_LIBCPP_HIDE_FROM_ABI` from any member functions once we are able to make `_LIBCPP_HIDE_FROM_ABI` the default within libc++
2025-07-20[libc++] Refactor internal index_sequence API to match the public one (#149475)Nikolas Klauser2-46/+32
The internal API is a lot more complicated than it actually needs to be. This refactors the internal API to match the features and names of the public one.
2025-06-16[libc++] Remove a few workarounds for old Clang versions (#143858)Nikolas Klauser1-12/+3
2025-06-11[libc++] Refactor signed/unsigned integer traits (#142750)Nikolas Klauser1-8/+8
This patch does a few things: - `__libcpp_is_signed_integer` and `__libcpp_is_unsigned_integer` are refactored to be variable templates instead of class templates. - the two traits are merged into a single header `<__type_traits/integer_traits.h>`. - `__libcpp_signed_integer`, `__libcpp_unsigned_integer` and `__libcpp_integer` are moved into the same header. - The above mentioned concepts are renamed to `__signed_integer`, `__unsigned_integer` and `__signed_or_unsigned_integer` respectively.
2025-05-12[libc++] Simplify the implementation of std::get for pairs (#114984)Nikolas Klauser1-16/+16
This makes it clearer what the functions actually do. As a nice side-effect it also avoids a function call. If the C++03 header split is successful we could drop `__get_pair` entirely.
2025-05-08[libc++] Add the __is_replaceable type trait (#132408)Louis Dionne1-0/+3
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-29[libc++][pair] P2944R3: Constrain `std::pair`'s equality operator (#136672)Hristo Hristov1-1/+9
Implements https://wg21.link/P2944R3 (partially): - [pairs.spec](https://eel.is/c++draft/pairs.spec) Related issues: - Related to #105424 - Related to #118135 - PR https://github.com/llvm/llvm-project/pull/135759 - PR https://github.com/llvm/llvm-project/pull/117664 Closes: [#136763](https://github.com/llvm/llvm-project/issues/136763) # References - https://eel.is/c++draft/concept.booleantestable - https://eel.is/c++draft/concept.equalitycomparable --------- Co-authored-by: Hristo Hristov <zingam@outlook.com> Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-04-19[libc++] Properly decay functions in CTAD for `pair` (#134544)A. Jiang1-45/+59
This patch makes instantiation of `pair` in CTAD a bit lazier to avoid instantiating invalid `pair` specialization before the decaying explicit deduction guide works.
2025-04-13[libc++] Use __underlying_type directly in underyling_type_t (#135423)Nikolas Klauser2-3/+3
This avoids instantiating multiple classes, reducing compile times. This patch also introduces `__underyling_type_t` for internal use, similar to other type traits.
2025-04-09[libc++] Remove _LIBCPP_TEMPLATE_VIS (#134885)Nikolas Klauser4-9/+9
The need for `_LIBCPP_TEMPLATE_VIS` has been removed in #133233.
2025-03-23[libc++] Add [[gnu::nodebug]] on type traits (#128502)Nikolas Klauser1-2/+3
2025-03-15[libc++][NFC] fix exception_guard include guard name (#131370)Hui1-3/+3
2025-03-04[libc++] Remove a few unused includes in <utility> headers (#129674)Nikolas Klauser5-7/+0
2025-01-13[libc++] Pass type information down to __libcpp_allocate (#118837)Louis Dionne2-2/+29
Currently, places where we call __libcpp_allocate must drop type information on the ground even when they actually have such information available. That is unfortunate since some toolchains and system allocators are able to provide improved security when they know what type is being allocated. This is the purpose of http://wg21.link/p2719, where we introduce a new variant of `operator new` which takes a type in its interface. A different but related issue is that `std::allocator` does not honor any in-class `T::operator new` since it is specified to call the global `::operator new` instead. This patch closes the gap to make it trivial for implementations that provide typed memory allocators to actually benefit from that information in more contexts, and also makes libc++ forward-compatible with future proposals that would fix the existing defects in `std::allocator`. It also makes the internal allocation API higher level by operating on objects instead of operating on bytes of memory. Since this is a widely-used function and making this a template could have an impact on debug info sizes, I tried minimizing the number of templated layers by removing `__do_deallocate_handle_size`, which was easy to replace with a macro (and IMO this leads to cleaner code).
2025-01-08[libc++] Put _LIBCPP_NODEBUG on all internal aliases (#118710)Nikolas Klauser7-15/+16
This significantly reduces the amount of debug information generated for codebases using libc++, without hurting the debugging experience.
2025-01-06[libc++] Simplify unwrap_ref_decay a bit (#121623)Nikolas Klauser1-4/+2
2024-12-22[libc++] Switch _LIBCPP_NODEBUG to [[gnu::nodebug]] (#120720)Nikolas Klauser2-6/+6
This makes the placement of the attribute more consistent. This also avoids clang dropping the attribute silently (see #120722).
2024-12-17[libc++] Granularize <new> includes (#119964)Nikolas Klauser2-2/+3
2024-12-14[libc++] Introduce __forward_as (#118168)Nikolas Klauser1-0/+17
This allows forwarding an object as a specific type. This is usually useful when using `deducing this` to avoid calling any functions in a deriving class.
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-11-16[libc++] Address post-commit comments for __scope_guard (#116291)Nikolas Klauser1-11/+7
Fixes #116204
2024-11-12[libc++] Introduce a standalone __scope_guard and use it in <string> (#114867)Nikolas Klauser2-6/+60
This introduces a new `__scope_guard` without any fancy features. The scope guard is used in `<string>` to simplify some of the ASan annotations (especially by making it harder to forget them where exceptions are thrown).
2024-11-10[libc++][NFC] Merge add_{const, cv, volatile}.h into a single header (#115610)Nikolas Klauser1-4/+1
There isn't much benefit in having granular headers for only a few simple lines of code.
2024-11-07[z/OS][libc++] Remove `align_val_t` dependency in small_buffer.h (#114396)Zibi Sarbinowski1-2/+2
Rewriting `__alloc()` and `__dealloc()` template functions to avoid errors when `small_buffer.h` is included in the modules LIT tests. For example: ``` test-suite-install/include/c++/v1/__utility/small_buffer.h:69:81: error: use of undeclared identifier 'align_val_t' # | 69 | byte* __allocation = static_cast<byte*>(::operator new[](sizeof(_Stored), align_val_t{alignof(_Stored)})); # | | ^ ```
2024-11-04[libc++] Remove a few includes from pair.h (#114708)Nikolas Klauser1-4/+1
2024-11-03[libc++] Add a few _LIBCPP_ASSERT_INTERNALs to make sure internal invariants ↵Nikolas Klauser1-0/+8
are kept (#114575) This can make it significanly easier to find bugs when working on string.
2024-10-31[libc++] Granularize <cstddef> includes (#108696)Nikolas Klauser6-6/+6
2024-10-26[libc++] Implement P0429R9 `std::flat_map` (#98643)Hui1-0/+6
Around half of the tests are based on the tests Arthur O'Dwyer's original implementation of std::flat_map, with modifications and removals. partially implement #105190
2024-10-12[libc++][RFC] Always define internal feature test macros (#89178)Nikolas Klauser2-3/+3
Currently, the library-internal feature test macros are only defined if the feature is not available, and always have the prefix `_LIBCPP_HAS_NO_`. This patch changes that, so that they are always defined and have the prefix `_LIBCPP_HAS_` instead. This changes the canonical use of these macros to `#if _LIBCPP_HAS_FEATURE`, which means that using an undefined macro (e.g. due to a missing include) is diagnosed now. While this is rather unlikely currently, a similar change in `<__configuration/availability.h>` caught a few bugs. This also improves readability, since it removes the double-negation of `#ifndef _LIBCPP_HAS_NO_FEATURE`. The current patch only touches the macros defined in `<__config>`. If people are happy with this approach, I'll make a follow-up PR to also change the macros defined in `<__config_site>`.
2024-09-12[libc++][NFC] Use [[__nodiscard__]] unconditionally (#80454)Nikolas Klauser2-4/+4
`__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-09-11[libc++][NFC] Replace _LIBCPP_NORETURN and TEST_NORETURN with [[noreturn]] ↵Nikolas Klauser1-1/+1
(#80455) `[[__noreturn__]]` is now always available, so we can simply use the attribute directly instead of through a macro.
2024-09-05[libc++][modules] Modularize <cstddef> (#107254)Louis Dionne3-0/+3
Many headers include `<cstddef>` just for size_t, and pulling in additional content (e.g. the traits used for std::byte) is unnecessary. To solve this problem, this patch splits up `<cstddef>` into subcomponents so that headers can include only the parts that they actually require. This has the added benefit of making the modules build a lot stricter with respect to IWYU, and also providing a canonical location where we define `std::size_t` and friends (which were previously defined in multiple headers like `<cstddef>` and `<ctime>`). After this patch, there's still many places in the codebase where we include `<cstddef>` when `<__cstddef/size_t.h>` would be sufficient. This patch focuses on removing `<cstddef>` includes from __type_traits to make these headers non-circular with `<cstddef>`. Additional refactorings can be tackled separately.
2024-07-23[libc++] Revert "Make std::pair trivially copyable if its members are ↵Louis Dionne1-41/+5
(#89652)" (#100184) This reverts commit f9dd885cb6e6b. We're not certain yet whether the patch has issues, so we are reverting until we've had time to investigate.
2024-07-20[libc++] Make std::pair trivially copyable if its members are (#89652)Nikolas Klauser1-5/+41
This makes `std::pair` trivially copyable if its members are and we have a way to do so. We need either C++20 with requires clauses or support for `__attribute__((enable_if))`. Only Clang has support for this attribute, so it's effectively clang or C++20. Co-authored-by: Christopher Di Bella <cjdb@google.com>
2024-07-17[libc++] Deprecates rel_ops. (#91642)Mark de Wever1-4/+4
These operators were deprecated in P0768R1 Library Support for the Spaceship (Comparison) Operator This was discovered while investigating the paper's implementation status.
2024-06-28Revert "[libc++][NFC] Simplify pair a bit" (#97003)James Y Knight1-5/+11
Reverts llvm/llvm-project#96165 The change broke code like #include <utility> #include <vector> struct Test { std::vector<std::pair<int, Test>> v; }; std::pair<int, Test> p; under `-std=c++20`, apparently by triggering certain template evaluations too eagerly.
2024-06-26[libc++][NFC] Simplify pair a bit (#96165)Nikolas Klauser1-11/+5
2024-06-23[libc++][NFC] Replace _NOEXCEPT and _LIBCPP_CONSTEXPR macros with the ↵Nikolas Klauser1-26/+23
keywords in C++11 code (#96387)
2024-06-19[libc++] Fix triviality of std::pair for trivially copyable types without an ↵Louis Dionne1-0/+2
assignment operator (#95444) Since 83ead2b, std::pair would not be trivially copyable when it holds a trivially copyable type without an assignment operator. That is because pair gained an elligible copy-assignment-operator (the const version) in 83ead2b in C++ >= 23. This means that the trivially copyable property of std::pair for such types would be inconsistent between C++11/14/17/20 (trivially copyable) and C++23/26 (not trivially copyable). This patch makes std::pair's behavior consistent in all Standard modes EXCEPT C++03, which is a pre-existing condition and we have no way of changing (also, it shouldn't matter because the std::is_trivially_copyable trait was introduced in C++11). While this is not technically an ABI break, in practice we do know that folks sometimes use a different representation based on whether a type is trivially copyable. So we're treating 83ead2b as an ABI break and this patch is fixing said breakage. This patch also adds tests stolen from #89652 that pin down the ABI of std::pair with respect to being trivially copyable. Fixes #95428
2024-06-18[libc++][NFC] Run clang-format on libcxx/include again (#95874)Louis Dionne3-8/+8
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 Klauser2-7/+7
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/+6
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-06-01[libc++][NFC] Format pair.h (#94101)Nikolas Klauser1-18/+19
2024-04-26[libcxx] Remove empty ~__no_destroy (#89882)Vitaly Buka1-19/+10
Primary motivation: is that after #84651 msan will complain if fields accessed after ~__no_destroy. My understanding of the https://eel.is/c++draft/basic.life#10 Static object with trivial destruction has program lifetime. Static object with empty destuctor has implicit lifetime, and accessing the object after lifetime is UB. It was UB before #84651, it's just msan ignored union members. Existing code with unions uses empty destructor, so accessing after the main() can cause UB. "placement new" version can have trivial destructor, so there is no end of lifetime. Secondary motivation: empty destructor will register __cxa_atexit with -O0. https://gcc.godbolt.org/z/hce587b65 We can not remove the destructor with union where _Tp can have non-trivial destructor. But we can remove destructor if we use in-place new instead of union. https://gcc.godbolt.org/z/Yqxx57eEd - empty even with -O0. New test fails without the patch on https://lab.llvm.org/buildbot/#/builders/sanitizer-x86_64-linux-bootstrap-msan
2024-04-22[libc++] Remove _LIBCPP_DISABLE_NODISCARD_EXTENSIONS and refactor the tests ↵Nikolas Klauser4-6/+6
(#87094) This also adds a few tests that were missing.
2024-04-15[libc++] Add a utility to check whether a range is valid (#87665)Louis Dionne2-3/+40
In the future, this utility could be made to also work with iterators, including bounded iterators. We could also query the ASAN runtime for this information when it's around.
2024-04-10[libc++] Adds a global private constructor tag. (#87920)Mark de Wever1-0/+28
This removes the similar tags used in the chrono tzdb implementation. Fixes: https://github.com/llvm/llvm-project/issues/85432