summaryrefslogtreecommitdiff
path: root/libcxx/include/optional
AgeCommit message (Collapse)Author
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-12[libc++] Implement P2988R12: `std::optional<T&>` (#155202)William Tran-Viet
Resolves #148131 - Unlock `std::optional<T&>` implementation - Allow instantiations of `optional<T(&)(...)>` and `optional<T(&)[]>` but disables `value_or()` and `optional::iterator` + all `iterator` related functions - Update documentation - Update tests
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-09-24[libc++] Implement Resolution of LWG 3886 (#155356)William Tran-Viet
Resolves #118336 - Implement the resolution of [LWG3886](https://cplusplus.github.io/LWG/issue3886) for `optional` and `expected`
2025-08-18[libc++] Implement P3168R2: Give optional range support (#149441)William Tran-Viet
Resolves #105430 - Implement all required pieces of P3168R2 - Leverage existing `wrap_iter` and `bounded_iter` classes to implement the `optional` regular and hardened iterator type, respectively - Update documentation to match
2025-07-15[libc++] P2944R3: Constrained comparisons - `optional` (#144249)Hristo Hristov
Partially implements [P2944R3](https://wg21.link/P2944R3) which adds constrained comparisons to std::optional. Closes #136767 # References [optional.relops](https://wg21.link/optional.relops) [optional.comp.with.t](https://wg21.link/optional.comp.with.t) --------- Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-06-02[libc++] Remove availability annotations which can't fire anymore (#140049)Nikolas Klauser
According to https://developer.apple.com/support/xcode/ the removed annotations can't fire anymore, since the targets they would fire for aren't supported anymore.
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-23[libc++][NFC] Replace a few "namespace std" with the correct macro (#140510)Nikolas Klauser
We've added a new macro for the unversioned `namespace std` cases in #133009, but it seems we've missed a few places. This fixes the places I just found.
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-09[libc++] Remove _LIBCPP_TEMPLATE_VIS (#134885)Nikolas Klauser
The need for `_LIBCPP_TEMPLATE_VIS` has been removed in #133233.
2025-04-09[libc++][C++03] Remove headers which don't provide anything (#134044)Nikolas Klauser
This patch removes all of the frozen headers which don't provide anything. Basically any header that's C++11-or-later is removed from the frozen headers. This is part of https://discourse.llvm.org/t/rfc-freezing-c-03-headers-in-libc.
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-15[libc++][NFC] Make enable_ifs in <optional> consistent (#127184)Nikolas Klauser
We've documented the preferred `enable_if` style in the coding guidelines. This updates `<optional>` to conform to them
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-21[libc++][C++03] Use `__cxx03/` headers in C++03 mode (#109002)Nikolas Klauser
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-17[libc++] Granularize <new> includes (#119964)Nikolas Klauser
2024-12-10[libc++] Add #if 0 block to all the top-level headers (#119234)Nikolas Klauser
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-04[libc++][NFC] Use more appropriate type traits for a few cases (#114025)Nikolas Klauser
2024-10-12[libc++][RFC] Always define internal feature test macros (#89178)Nikolas Klauser
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-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-09-16[libc++][modules] Fix missing and incorrect includes (#108850)Louis Dionne
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-11[libc++][NFC] Replace _LIBCPP_NORETURN and TEST_NORETURN with [[noreturn]] ↵Nikolas Klauser
(#80455) `[[__noreturn__]]` is now always available, so we can simply use the attribute directly instead of through a macro.
2024-08-14[libc++] Fix ambiguous constructors for std::complex and std::optional (#103409)Louis Dionne
Fixes #101960
2024-07-21[libc++] Makes `unique_ptr operator*() noexcept. (#98047)Mark de Wever
This implements - LWG2762 unique_ptr operator*() should be noexcept. Differential Revision: https://reviews.llvm.org/D128214
2024-06-18[libc++][NFC] Run clang-format on libcxx/include again (#95874)Louis Dionne
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-17[libc++] Mark more types as trivially relocatable (#89724)Nikolas Klauser
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-05-28[libc++] Make the __availability header a sub-header of __config (#93083)Louis Dionne
In essence, this header has always been related to configuration of the library but we didn't want to put it inside <__config> due to complexity reasons. Now that we have sub-headers in <__config>, we can move <__availability> to it and stop including it everywhere since we already obtain the required macros via <__config>.
2024-03-18[libc++][NFC] Merge ↵Nikolas Klauser
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 Klauser
This also moves `__all` from `sfinae_helpers.h` to `conjunction.h`.
2024-03-03[libc++] Rename __fwd/hash.h to __fwd/functional.h and add reference_wrapper ↵Nikolas Klauser
(#81445) We forward declare `reference_wrapper` in multiple places already. This moves the declaration to the canonical place and removes unnecessary includes of `__functional/reference_wrapper.h`.
2024-02-29[libc++] Clean up includes of <__assert> (#80091)Louis Dionne
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
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-12-05[libc++] Replace uses of _VSTD:: by std:: (#74331)Louis Dionne
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 Dionne
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-11-26[libc++][NFC] Use __construct_at and __destroy_at instead of using ↵philnik777
preprocessor conditionals (#70866)
2023-10-29[libc++] Remove a few transitive includes (#70553)philnik777
2023-09-12[libc++][test] Add '-Wdeprecated-copy', '-Wdeprecated-copy-dtor' warnings to ↵Igor Zhukov
the test suite This is a follow up to https://reviews.llvm.org/D144694. Fixes https://github.com/llvm/llvm-project/issues/60977. Differential Revision: https://reviews.llvm.org/D144775
2023-08-20[libc++][expected] Implement LWG3836yrong
Implement LWG3836 (https://wg21.link/LWG3836) `std::expected<bool, E1>` conversion constructor `expected(const expected<U, G>&)` should take precedence over `expected(U&&)` with operator `bool` Reviewed By: #libc, Mordante Differential Revision: https://reviews.llvm.org/D155701
2023-07-24[libc++] Fix template parameter naming and enforce it through ↵Nikolas Klauser
readability-identifier-naming Reviewed By: #libc, Mordante Spies: Mordante, aheejin, libcxx-commits Differential Revision: https://reviews.llvm.org/D156059
2023-07-20[libc++][hardening] Categorize most assertions inside the container classes.varconst
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-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-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-15[libc++] Merge _LIBCPP_FUNC_VIS, _LIBCPP_TYPE_VIS and _LIBCPP_EXCEPTION_ABI ↵Nikolas Klauser
into _LIBCPP_EXPORTED_FROM_ABI These macros are always defined identically, so we can simplify the code a bit by merging them. Reviewed By: ldionne, #libc Spies: libcxx-commits, krytarowski, smeenai Differential Revision: https://reviews.llvm.org/D152652
2023-05-07[libc++][Modules] Add missing includes and exportsIan Anderson
Several headers are missing includes for things they use. type_traits.is_enum needs to export type_traits.integral_constant so that clients can access its `value` member without explicitly including __type_traits/integral_constant.h themselves. Make `subrange_fwd` a peer submodule to `subrange` rather than a submodule of it, and have `subrange` export `subrange_fwd`. That will make it easier to programmatically generate modules for the private detail headers, and it will accomplish the same effect that __ranges/subrange.h will make subrange_kind visible. Reviewed By: Mordante, #libc Differential Revision: https://reviews.llvm.org/D150055
2023-05-05[libc++][spaceship] Implement `operator<=>` for `optional`Hristo Hristov
Implements parts of **P1614R2**: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1614r2.html - Implemented `operator<=>` for `optional` - Updated "optional synopsis" to match the current draft https://eel.is/c++draft/optional closer - Implemented https://cplusplus.github.io/LWG/issue3566 - Implemented https://cplusplus.github.io/LWG/issue3746 Reviewed By: #libc, philnik, ldionne Differential Revision: https://reviews.llvm.org/D146392
2023-04-27Fix EBO on std::optional and std::variant when targeting the MSVC ABIEric Fiselier
Committing on behalf of davidben. Reviewed as D146190 Patch originally by Jan Dörrie in https://reviews.llvm.org/D120064. I've just updated it to include tests, and update documentation that MSVC ABI is not stable. In the current implementation both `std::optional` and `std::variant` don't perform the EBO on MSVC's ABI. This is because both classes inherit from multiple empty base classes, which breaks the EBO for MSVC. This patch fixes this issue by applying the `empty_bases` declspec attribute, which is already used to fix a similar issue for `std::tuple`. See https://reviews.llvm.org/D120064 for discussion on MSVC ABI stability. From the discussion, libc++ doesn't have users that expect a stable ABI on MSVC. The fix is thus applied unconditionally to benefit more users. Documentation has been updated to reflect this. Fixes https://github.com/llvm/llvm-project/issues/61095.
2023-04-16[libc++] Add hide_from_abi check for classesNikolas Klauser
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