summaryrefslogtreecommitdiff
path: root/libcxx/include/__memory/construct_at.h
AgeCommit message (Collapse)Author
2025-10-31[libc++] Simplify the implementation of destroy_at a bit (#165392)Nikolas Klauser
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-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.
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>.
2024-10-03[libc++] Re-apply LWG3870: Remove `voidify` (#110944)A. Jiang
This reverts commit f3d58f4161b86a479f68acb453e9622911c688a0. Relands #110355.
2024-10-01Revert "[libc++] LWG3870: Remove `voidify` (#110355)" (#110587)Michael Buch
This reverts commit 78f9a8b82d772ff04a12ef95f2c9d31ee8f3e409. This caused the LLDB test `TestDataFormatterGenericOptional.py` to fail, and we need a bit more time to look into it.
2024-10-01[libc++] LWG3870: Remove `voidify` (#110355)A. Jiang
Instead of changing the cast sequence to implicit conversion in _`voidify`_, I think it is better to totally remove `__voidify` and use `static_cast` to `void*`, which has equivalent effects. Test coverage for const iterators are removed. Now most affected algorithms are underconstrained, for which I submitted [LWG3888](https://cplusplus.github.io/LWG/issue3888). I'm not sure whether we should speculatively implement it at this moment, and thus haven't added any `*.verify.cpp`. In some control block types and `optional`, the stored objects are changed to have cv-unqualified type. Fixes #105119.
2024-04-05Fix issue with never-constexpr __construct_at in C++ < 20. (#87403)Eric
The application of constexpr to __construct_at triggers weird linker errors when building LLVM with modules enabled and C++ < 20. > ld.lld: error: undefined hidden symbol: void* std::__1::__voidify[abi:nn190000]<llvm::sys::ProcessStatistics>(llvm::sys::ProcessStatistics&) >>>> referenced by construct_at.h:52 (/usr/local/bin/../include/c++/v1/__memory/construct_at.h:52) >>>> Program.cpp.o:(llvm::sys::Wait(llvm::sys::ProcessInfo const&, std::__1::optional<unsigned int>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, std::__1::optional<llvm::sys::ProcessStatistics>*, bool)) in archive lib/libLLVMSupport.a I suspect this is related to undefined behavior caused by the fact that construct_at is never really constexpr (which is UB NDR). I'm unsure how to meaningfully write a test for this, as I haven't been able to trigger it in smaller unit tests
2023-12-18[libc++] Format the code base (#74334)Louis Dionne
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-11-07[libc++][hardening] Add `_LIBCPP_ASSERT_NON_NULL` to check for null pointers ↵Konstantin Varlamov
(#71428)
2023-09-01[libc++][NFC] Update the remaining enable_ifsNikolas Klauser
This brings most of the enable_ifs in libc++ to the same style. Reviewed By: #libc, ldionne Spies: ldionne, libcxx-commits Differential Revision: https://reviews.llvm.org/D157753
2023-07-06Fixing conflicting macro definitions between curses.h and the standard library.Nicole Rabjohn
POSIX allows certain macros to exist with generic names (i.e. refresh(), move(), and erase()) to exist in `curses.h` which conflict with functions found in std::filesystem, among others. This patch undefs the macros in question and adds them to LIBCPP_PUSH_MACROS and LIBCPP_POP_MACROS. Reviewed By: #libc, philnik, ldionne Differential Revision: https://reviews.llvm.org/D147356
2023-06-30[libc++] Revert __uninitialized_buffer changesLouis Dionne
This patch reverts the following commits: 015cd317eaed28a923d14a33c9d6739012a688be (add missing HIDE_FROM_ABI) 420a204d52205f1277a8d5df3dbafac6082e02e2 (add _LIBCPP_NO_CFI) 31eeba3f7c0e2ef4a21c07da9326a4ae1a8de7e2 (add __uninitialized_buffer) It also reverts a small part of b935ab8e747cf52ff12471879460206a9f433eea which is required to make the stable_partition.pass.cpp test pass on GCC. Some issues were pointed out in https://reviews.llvm.org/D152208 and in https://reviews.llvm.org/D154017, so I am reverting this patch until we have time to weigh the various solutions and get consensus on the design of the API. Differential Revision: https://reviews.llvm.org/D154161
2023-06-28[libc++][hardening][NFC] Introduce `_LIBCPP_ASSERT_UNCATEGORIZED`.varconst
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-06-16[libc++] Introduce __make_uninitialized_buffer and use it instead of ↵Nikolas Klauser
get_temporary_buffer This will also be used in some PSTL backends. Reviewed By: ldionne, #libc, Mordante Spies: arichardson, mstorsjo, Mordante, sstefan1, jplehr, libcxx-commits Differential Revision: https://reviews.llvm.org/D152208
2023-02-15[libc++][NFC] Replace _LIBCPP_STD_VER > x with _LIBCPP_STD_VER >= xNikolas Klauser
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
2023-02-13[libc++] Fix bug in allocate_shared_for_overwriteLouis Dionne
Instead of destroying the object with allocator::destroy, we must call its destructor directly. As a fly-by also mark LWG3008 as fixed since it is handled by our implementation. This was pointed out by Tim Song in https://reviews.llvm.org/D140913. Differential Revision: https://reviews.llvm.org/D143791
2023-02-11[libc++][NFC] Use std:: instead of _VSTD:: in construct_at.hLouis Dionne
2023-01-12[libc++][NFC] Qualify declvalNikolas Klauser
While it's not necessary to qualify calls to `declval` it makes error messages very crypric if the declaration isn't reachable anymore For example: ``` /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:53:66: error: no type named 'type' in 'std::common_type<long, long>' typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_type.h:107:14: note: in instantiation of template class 'std::common_type<std::chrono::duration<long, std::ratio<3600, 1>>, std::chrono::duration<long, std::ratio<3600, 1>>>' requested here : public common_type<_Tp, _Tp> {}; ^ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:279:58: note: in instantiation of template class 'std::common_type<std::chrono::duration<long, std::ratio<3600, 1>>>' requested here _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);} ^ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:308:54: note: in instantiation of template class 'std::chrono::duration<long, std::ratio<3600, 1>>' requested here typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days; ^ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:280:81: error: no type named 'type' in 'std::common_type<std::chrono::duration<long, std::ratio<3600, 1>>>' _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:308:54: note: in instantiation of template class 'std::chrono::duration<long, std::ratio<3600, 1>>' requested here typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days; ^ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:53:66: error: no type named 'type' in 'std::common_type<int, int>' typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_type.h:107:14: note: in instantiation of template class 'std::common_type<std::chrono::duration<int, std::ratio<86400, 1>>, std::chrono::duration<int, std::ratio<86400, 1>>>' requested here : public common_type<_Tp, _Tp> {}; ^ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:279:58: note: in instantiation of template class 'std::common_type<std::chrono::duration<int, std::ratio<86400, 1>>>' requested here _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);} ^ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__chrono/duration.h:309:55: note: in instantiation of template class 'std::chrono::duration<int, std::ratio<86400, 1>>' requested here typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks; ^ 19 similar errors omitted ``` changes with qualification added to: ``` While building module 'std' imported from /home/nikolask/llvm-projects/libcxx/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp:13: In file included from <module-includes>:17: In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/math.h:309: In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/limits:107: In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/type_traits:432: In file included from /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_reference.h:13: /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__type_traits/common_type.h:28:43: error: declaration of 'declval' must be imported from module 'std.utility.__utility.declval' before it is required using __cond_type = decltype(false ? std::declval<_Tp>() : std::declval<_Up>()); ^ /home/nikolask/llvm-projects/libcxx/build/include/c++/v1/__utility/declval.h:30:34: note: declaration here is not visible decltype(std::__declval<_Tp>(0)) declval() _NOEXCEPT; ^ /home/nikolask/llvm-projects/libcxx/libcxx/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp:13:10: fatal error: could not build module 'std' #include <functional> ~~~~~~~~^ 2 errors generated. ``` Reviewed By: ldionne, Mordante, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D130854
2022-12-23[libc++] Granularize <type_traits> includes in <compare>Nikolas Klauser
Reviewed By: Mordante, #libc Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D140480
2022-09-05[libc++] Granularize the rest of memoryNikolas Klauser
Reviewed By: ldionne, #libc Spies: vitalybuka, paulkirth, libcxx-commits, mgorny Differential Revision: https://reviews.llvm.org/D132790
2022-09-02Revert "[libc++] Granularize the rest of memory"Vitaly Buka
Breaks buildbots. This reverts commit 30adaa730c4768b5eb06719c808b2884fcf53cf3.
2022-09-02[libc++] Granularize the rest of memoryNikolas Klauser
Reviewed By: ldionne, #libc Spies: libcxx-commits, mgorny Differential Revision: https://reviews.llvm.org/D132790
2022-08-19[libc++][NFC] Rename the constexpr macrosNikolas Klauser
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-27[libc++] Implement P1004R2 (constexpr std::vector)Nikolas Klauser
Reviewed By: #libc, ldionne Spies: mgorny, var-const, ormris, philnik, miscco, hiraditya, steven_wu, jkorous, ldionne, christof, libcxx-commits Differential Revision: https://reviews.llvm.org/D68365
2022-06-17[libc++] Implement std::boyer_moore{, _horspool}_searcherNikolas Klauser
This mostly copys the `<experimental/functional>` stuff and updates the code to current libc++ style. Reviewed By: ldionne, #libc Spies: nlopes, adamdebreceni, arichardson, libcxx-commits, mgorny Differential Revision: https://reviews.llvm.org/D121074
2022-03-24[libc++] Audit all uses of _LIBCPP_ASSERT and _LIBCPP_DEBUG_ASSERTLouis Dionne
I audited all uses of _LIBCPP_ASSERT to make sure that we only used it for "basic assertions", i.e. assertions with constant-time conditions. I also audited all uses of _LIBCPP_DEBUG_ASSERT to make sure we used it only for debug-mode assertions, and in one case had to change for _LIBCPP_ASSERT instead. As a fly-by, I also changed a couple of tests against nullptr or 0 to be more explicit. After this patch, all uses of _LIBCPP_ASSERT should be with constant-time conditions, and all uses of _LIBCPP_DEBUG_ASSERT should be with conditions that we only want to check when the debug mode is enabled. Differential Revision: https://reviews.llvm.org/D122395
2022-03-01[libc++] Revert "Protect users from relying on detail headers" & related changesLouis Dionne
This commit reverts 5aaefa51 (and also partly 7f285f48e77 and b6d75682f9, which were related to the original commit). As landed, 5aaefa51 had unintended consequences on some downstream bots and didn't have proper coverage upstream due to a few subtle things. Implementing this is something we should do in libc++, however we'll first need to address a few issues listed in https://reviews.llvm.org/D106124#3349710. Differential Revision: https://reviews.llvm.org/D120683
2022-02-26[libcxx][modules] protects users from relying on detail headersChristopher Di Bella
libc++ has started splicing standard library headers into much more fine-grained content for maintainability. It's very likely that outdated and naive tooling (some of which is outside of LLVM's scope) will suggest users include things such as <__ranges/access.h> instead of <ranges>, and Hyrum's law suggests that users will eventually begin to rely on this without the help of tooling. As such, this commit intends to protect users from themselves, by making it a hard error for anyone outside of the standard library to include libc++ detail headers. Differential Revision: https://reviews.llvm.org/D106124
2022-02-16[libc++] Move everything related solely to _LIBCPP_ASSERT to its own fileLouis Dionne
This is the first step towards disentangling the debug mode and assertions in libc++. This patch doesn't make any functional change: it simply moves _LIBCPP_ASSERT-related stuff to its own file so as to make it clear that libc++ assertions and the debug mode are different things. Future patches will make it possible to enable assertions without enabling the debug mode. Differential Revision: https://reviews.llvm.org/D119769
2022-02-04[libc++] Replace includes of <utility> with specific detail headersArthur O'Dwyer
Basically a rebase of D104980; most of that patch had already happened via gradual drive-by changes, but this finishes it up. Don't touch the inclusions from `<__functional_base>`, `<__hash_table>`, or `<__locale>`; those could be removed if we propagated the inclusions up to the includers of those files, but there are lots of those includers. `<algorithm>`, `<functional>`, and `<memory>` already include `<utility>` at the top level. `<iterator>` did not, so I've added it there. Differential Revision: https://reviews.llvm.org/D119020
2022-02-04[libc++] Normalize all our '#pragma GCC system_header', and regression-test.Arthur O'Dwyer
Now we'll notice if a header forgets to include this magic phrase. Differential Revision: https://reviews.llvm.org/D118800
2022-01-12[libc++][ranges] Implement `construct_at` and `destroy{,_at}`.Konstantin Varlamov
Differential Revision: https://reviews.llvm.org/D116078
2021-12-20[libc++][ranges] Implement `uninitialized_value_construct{,_n}` and ↵Konstantin Varlamov
`uninitialized_fill{,_n}`. Also: - refactor out `__voidify`; - use the `destroy` algorithm internally; - refactor out helper classes used in tests for `uninitialized_*` algorithms. Differential Revision: https://reviews.llvm.org/D115626
2021-09-08[libc++] Use enable_if_t instead of _EnableIfLouis Dionne
I just ran into a compiler error involving __bind_back and some overloads that were being disabled with _EnableIf. I noticed that the error message was quite bad and did not mention the reason for the overload being excluded. Specifically, the error looked like this: candidate template ignored: substitution failure [with _Args = <ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>' Instead, when using enable_if or enable_if_t, the compiler is clever and can produce better diagnostics, like so: candidate template ignored: requirement 'is_invocable_v< std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>, std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &, ContiguousView>' was not satisfied [with _Args = <ContiguousView>] Basically, it tries to do a poor man's implementation of concepts, which is already a lot better than simply complaining about substitution failure. Hence, this commit uses enable_if_t instead of _EnableIf whenever possible. That is both more straightforward than using the internal helper, and also leads to better error messages in those cases. I understand the motivation for _EnableIf's implementation was to improve compile-time performance, however I believe striving to improve error messages is even more important for our QOI, hence this patch. Furthermore, it is unclear that _EnableIf actually improved compile-time performance in any noticeable way (see discussion in the review for details). Differential Revision: https://reviews.llvm.org/D108216
2021-08-27[libc++][NFC] Remove useless _LIBCPP_PUSH_MACROSLouis Dionne
Only files that actually use min/max are required to do this dance. Differential Revision: https://reviews.llvm.org/D108778
2021-07-30[libc++] Handle arrays in std::destroy_atLouis Dionne
Also, improve tests for std::destroy and std::destroy_n so that they check for array support. These changes are part of http://wg21.link/p0896 (the One Ranges proposal). Differential Revision: https://reviews.llvm.org/D106916
2021-06-24[libcxx][modularisation] moves <utility> content out of <type_traits>Christopher Di Bella
Moves: * `std::move`, `std::forward`, `std::declval`, and `std::swap` into `__utility/${FUNCTION_NAME}`. * `std::swap_ranges` and `std::iter_swap` into `__algorithm/${FUNCTION_NAME}` Differential Revision: https://reviews.llvm.org/D103734
2021-05-11[libc++] s/_VSTD::declval/declval/g. NFCI.Arthur O'Dwyer
2021-04-20[libc++] NFC: Normalize `#endif //` comment indentationLouis Dionne
2021-04-14[libc++] Split up __memory/base.h into meaningful headersLouis Dionne