summaryrefslogtreecommitdiff
path: root/libcxx/include/__memory
AgeCommit message (Collapse)Author
2025-11-20[libc++][memory] Applied `[[nodiscard]]` to smart pointers (#168483)Hristo Hristov
Applied `[[nodiscard]]` where relevant to smart pointers and related functions. - [x] - `std::unique_ptr` - [x] - `std::shared_ptr` - [x] - `std::weak_ptr` See guidelines: - https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant - `[[nodiscard]]` should be applied to functions where discarding the return value is most likely a correctness issue. For example a locking constructor in unique_lock. --------- Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-11-15[libc++] Apply `[[nodiscard]]` to `in/out_ptr` (#167097)Hristo Hristov
...according to Coding Guidelines: `[[nodiscard]]` should be applied to functions where discarding the return value is most likely a correctness issue. Changes to: - [x] `inout_ptr()` - [x] `out_ptr()` At the time of impelentation the `[[nodiscard]]` policy has not been established yet. --------- Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-11-13[libc++] Merge is_{,un}bounded_array.h into is_array.h (#167479)Nikolas Klauser
These headers are incredibly simple and closely related, so this merges them into a single one.
2025-11-13[libc++] Simplify the implementation of the unique_ptr -> shared_ptr ↵Nikolas Klauser
converting constructor (#165619) This also backports LWG2415 as a drive-by.
2025-11-11[libc++] Remove __is_replaceable emulation (#167355)Louis Dionne
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-11-11[libc++] Remove some of the uses of aligned_storage inside the library (#161635)Nikolas Klauser
`aligned_storage` has been deprecated and will most likely be removed in a future version of C++. This patch removes some of its uses to avoid having to work around its removal in the future.
2025-11-10[libc++] Replace __libcpp_is_final with a variable template (#167137)Nikolas Klauser
2025-10-31[libc++] Simplify the implementation of destroy_at a bit (#165392)Nikolas Klauser
2025-10-16[libc++] Properly implement array cookies in the ARM ABI (#160182)Louis Dionne
When we implemented array cookie support for hardening std::unique_ptr, the implementation was only done for the Itanium ABI. I did not initially realize that ARM was using a different ABI for array cookies, so unique_ptr should not have been hardened on ARM. However, we were also incorrectly setting the ABI-detection macro: we were pretending to be using a vanilla Itanium ABI when in reality the (similar but different) ARM ABI was in use. As a result, unique_ptr was using the wrong representation for array cookies on ARM, which fortunately only mattered in the case of overaligned types. This patch fixes that. rdar://160852193
2025-10-09[libc++] Use std::__{scope,exception}_guard throughout the code base (#161322)Nikolas Klauser
This simplifies the code quite a bit and seems to improve code size slightly in some cases.
2025-09-25[libc++] Remove alignment attributes from _LIBCPP_COMPRESSED_PAIR (#158595)Nikolas Klauser
These attributes aren't required anymore, since the potential overalignemnt of the objects is handled by the surrounding anonymous struct.
2025-09-24[libc++] Simplify __memory/shared_count.h a bit (#160048)Nikolas Klauser
This removes a few checks that aren't required anymore and moves some code around to the places where it's actually used.
2025-09-18[libc++] Refactor memory allocation in basic_string (#128423)Nikolas Klauser
This patch introduces a string-internal API to make the allocation and deallocation the long string simpler. Before this we had a lot of code duplication, so ensuring that things were actually correct was non-trivial.
2025-09-18[libc++] Introduce _LIBCPP_COMPRESSED_ELEMENT (#134253)Nikolas Klauser
We have multiple classes with an empty base optimization that contains just a single type. This patch introduces `_LIBCPP_COMPRESSED_ELEMENT` to refactor these classes to avoid having them essentially twice, reducing the amount of code significantly.
2025-09-10[NFC][libc++] Fix typo in `libcxx/include/__memory/pointer_traits.h` (#157304)Vinay Deshmukh
* Apply the typo fix as a separate NFC patch from here: https://github.com/llvm/llvm-project/pull/134330/files#r2313015079
2025-09-04[libc++][NFC] Use llvm.org/PR to link to bug reports (#156288)Nikolas Klauser
We've built up quite a few links directly to github within the code base. We should instead use `llvm.org/PR<issue-number>` to link to bugs, since that is resilient to the bug tracker changing in the future. This is especially relevant for tests linking to bugs, since they will probably be there for decades to come. A nice side effect is that these links are significantly shorter than the GH links, making them much less of an eyesore. This patch also replaces a few links that linked to the old bugzilla instance on llvm.org.
2025-09-04[libc++] Split ABI flag for removing iterator bases and removing the second ↵Nikolas Klauser
member in reverse_iterator (#143079) Currently `_LIBCPP_NO_ITERATOR_BASES` controls both whether specific classes derive from `iterator` and whether `reverse_iterator` has a second member variable. These two changes are orthogonal though, and one can be applied in all langauge modes while the other change is only conforming for C++17 and later.
2025-08-23[libc++] Fix ABI break introduced by switching to _LIBCPP_COMPRESSED_PAIR ↵Nikolas Klauser
(#154686) LLVM 20 contained an ABI break that can result in the size of `std::unordered_{map,set,multimap,multiset}` and `std::deque` changing when used with an allocator type that is empty and contains a base class that is the same across rebound allocator instantiations (e.g. ``Allocator<int>`` and ``Allocator<char>`` are both empty and contain the same base class). In addition, the layout of a user-defined type that: - contains one of the following containers: `std::unordered_{map,set,multimap,multiset}`, `std::deque`, `std::map`, `std::set`, `std::multimap`, `std::multiset`, `std::list` or `std::vector`, and - passes an empty allocator, comparator or hasher type to that container, and - has a member of that same empty allocator, comparator or hasher type inside the enclosing struct, and - that member is either marked with `[[no_unique_address]]` or optimized out via the EBO (empty base optimization) technique saw its size increase from LLVM 19 to LLVM 20. This was caused by the usage of `[[no_unique_address]]` within some of libc++'s containers in a way that allowed subtle interactions with enclosing objects. This is fixed in LLVM 21 on Clang (returning to the LLVM 19 ABI), however that implies an ABI break from LLVM 20 to LLVM 21. Furthermore, fixing this causes a slight regression to constant evaluation support in `std::unique_ptr`. Specifically, constant evaluation will now fail when the deleter relies on being value-initialized for constant-evaluation admissibility. If a default-initialized deleter can be used during constant evaluation, or if the default constructor is non-trivial, the `unique_ptr` is not affected by this regression. In particular, this regression does not impact any `unique_ptr` using the default deleter. Note that there is currently no way to realistically fix this ABI break on GCC, therefore GCC will remain on the ABI introduced in LLVM 19. That also means that Clang and GCC will have a slightly different ABI for the small subset of types listed above until we are able to apply the same fix we did with Clang on GCC. We fix this regression by surrounding the members of the `_LIBCPP_COMPRESSED_PAIR` with an anonymous struct. This restricts the shifting of empty types to the front of the `_LIBCPP_COMPRESSED_PAIR` instead of throughout the surrounding object. This "frees up" the zero offset to contain another object of the same type, restoring the ability to perform EBO or to elide the storage for a type with `[[no_unique_address]]` in the enclosing (user-defined) struct. Fixes #154146 Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-08-05[libc++] Remove SFINAE on __tuple_impl constructors (#151654)Nikolas Klauser
The SFINAE isn't required, since the primary `tuple` class already does the SFINAE checks. This removes a bit of code that was only used for these constraints. This also moves the `tuple_element` specialization for `tuple` to `__fwd/tuple.h` to avoid a dependency on `__tuple/sfinae_helpers.h` (which should be moved in a follow-up).
2025-07-19[libc++] Diagnose passing null pointers to a bunch of APIs (#148585)Nikolas Klauser
2025-07-10[libc++][NFC] Simplify std::__destroy_at a bit (#147025)Nikolas Klauser
2025-07-05[libc++][NFC] Merge add_{r,l}value_reference.h (#147022)Nikolas Klauser
The implementation is now quite simple, so it doesn't make a ton of sense to have these in separate headers.
2025-06-19[libc++] Simplify the implementation of pointer_traits a bit (#142260)Nikolas Klauser
2025-06-11[libc++] Make forward_list constexpr as part of P3372R3 (#129435)Peng Liu
Fixes #128658
2025-06-10[libc++] Inline __has_feature and __has_extension uses (#133634)Nikolas Klauser
Since GCC now supports `__has_feature` and `__has_extension` as well, there isn't much of a reason to define new macros to test for the features.
2025-06-03[libc++] Fix padding calculation for function reference types (#142125)A. Jiang
#109028 caused `sizeof` to be sometimes applied to function reference types, which makes a program ill-formed. This PR handles reference types by specializations to prevent such bogus `sizeof` expression to be instantiated. Fixes #142118.
2025-05-28Revert "[libc++] Introduce ABI sensitive areas to avoid requiring ↵James Y Knight
_LIBCPP_HIDE_FROM_ABI everywhere (#131156)" (#141756) This reverts commit c861fe8a71e64f3d2108c58147e7375cd9314521. Unfortunately, this use of hidden visibility attributes causes user-defined specializations of standard-library types to also be marked hidden by default, which is incorrect. See discussion thread on #131156. ...and also reverts the follow-up commits: Revert "[libc++] Add explicit ABI annotations to functions from the block runtime declared in <__functional/function.h> (#140592)" This reverts commit 3e4c9dc299c35155934688184319d391b298fff7. Revert "[libc++] Make ABI annotations explicit for windows-specific code (#140507)" This reverts commit f73287e623a6c2e4a3485832bc3e10860cd26eb5. Revert "[libc++][NFC] Replace a few "namespace std" with the correct macro (#140510)" This reverts commit 1d411f27c769a32cb22ce50b9dc4421e34fd40dd.
2025-05-18[libc++] Introduce ABI sensitive areas to avoid requiring ↵Nikolas Klauser
_LIBCPP_HIDE_FROM_ABI everywhere (#131156) This patch introduces `_LIBCPP_{BEGIN,END}_EXPLICIT_ABI_ANNOTATIONS`, which allow us to have implicit annotations for most functions, and just where it's not "hide_from_abi everything" we add explicit annotations. This allows us to drop the `_LIBCPP_HIDE_FROM_ABI` macro from most functions in libc++.
2025-05-15[libc++] Avoid type-punning between __value_type and pair (#134819)Nikolas Klauser
Before this patch, we were dereferencing pointers to objects which were never constructed. Now we always assume that nodes store `pair<const KeyT, ValueT>` for maps instead, as they actually do. This patch also allows for significant follow-up simplifications, since `__node_value_type` and `__container_value_type` are the same type now.
2025-05-08[libc++] Add the __is_replaceable type trait (#132408)Louis Dionne
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-14[libc++] Implement P2897R7 aligned_accessor: An mdspan accessor expressing ↵Damien L-G
pointer over-alignment (#122603) Closes #118372
2025-04-09[libc++] Remove _LIBCPP_TEMPLATE_VIS (#134885)Nikolas Klauser
The need for `_LIBCPP_TEMPLATE_VIS` has been removed in #133233.
2025-03-28[libc++] Simplify the implementation of the pointer aliases in ↵Nikolas Klauser
allocator_traits (#127079)
2025-03-25[libc++][NFC] Replace structs with variable templates in ↵Nikolas Klauser
<__memory/allocator_traits.h> (#129237) Variable templates are a bit easier on the compiler and improve the readability of the code.
2025-03-23[libc++] Add [[gnu::nodebug]] on type traits (#128502)Nikolas Klauser
2025-03-18[libc++] Improve deprecated diagnostic guards.Mark de Wever
Recent Clang-21 builds improved the deprecated diagnotics. This uncovered missing guards in libc++ internally. Note: This patch should be a separate commit and not merged. For testing purposes they are combined. Reviewed as part of #130497.
2025-03-17[libc++][NFC] Remove dead link in commentLouis Dionne
2025-03-09[libc++] Protect more code against -Wdeprecated. (#130419)Mark de Wever
This seems needed when updating the CI Docker image.
2025-02-27[NFC][libc++] Guard against operator& hijacking. (#128351)Mark de Wever
This set usage of operator& instead of std::addressof seems not be easy to "abuse". Some seem easy to misuse, like basic_ostream::operator<<, trying to do that results in compilation errors since the `widen` function is not specialized for the hijacking character type. Hence there are no tests.
2025-02-21[libc++] Qualify calls to nullary functions like __throw_foo (#122465)Louis Dionne
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-02-14[libc++][NFC] Simplify unique_ptr a bit (#121230)Nikolas Klauser
2025-02-10[libc++] Extract destroy algorithms into separate headers (#126449)Louis Dionne
This patch separates the destroy algorithms from the primitive construct_at and destroy_at operations, which are conceptually not algorithms. This makes it easier to start using these destroy algorithms from upcoming relocation facilities. As part of this, it also implements `std::destroy_at` for arrays without relying on the `std::destroy` algorithm, which is conceptually a higher-level facility.
2025-01-21[libc++] Fix input-only range handling for `vector` (#116157)A. Jiang
Changes: - Carve out sized but input-only ranges for C++23. - Call `std::move` for related functions when the iterator is possibly input-only. Fixes #115727
2025-01-14[libc++] Make std::stable_sort constexpr friendly (#110320)PaulXiCao
Implementing `constexpr std::stable_sort`. This is part of P2562R1, tracked via issue #105360. Closes #119394 Co-authored-by: A. Jiang <de34@live.cn> Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-01-13[libc++] Pass type information down to __libcpp_allocate (#118837)Louis Dionne
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 Klauser
This significantly reduces the amount of debug information generated for codebases using libc++, without hurting the debugging experience.
2024-12-22[libc++][NFC] Name `unique_ptr` function arguments `__ptr` and `__deleter`Nikolas Klauser
This makes the code a bit more readable and users will see `ptr` and `deleter` instead of `p` and `d` when using an IDE that shows the argument names.
2024-12-22[libc++] Switch _LIBCPP_NODEBUG to [[gnu::nodebug]] (#120720)Nikolas Klauser
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 Klauser
2024-12-13[libc++] Granularize the <new> header (#119270)Louis Dionne
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>.