summaryrefslogtreecommitdiff
path: root/libcxx/include/variant
AgeCommit message (Collapse)Author
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-10-30[libc++] Fix LLVM 22 TODOs (#153367)Nikolas Klauser
We've upgraded to LLVM 22 now, so we can remove a bunch of TODOs.
2025-07-20[libc++] Refactor internal index_sequence API to match the public one (#149475)Nikolas Klauser
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-25[libc++] P2944R3: Constrained comparisions - `variant` (#141396)Hristo Hristov
This is a follow-up and depends on #139368 being merged first. Implements [P2944R3](https://wg21.link/P2944R3) partially, which adds constrained comparisons to `std::variant` Closes #136769 Depends on #139368 # References [variant.relops](https://wg21.link/variant.relops)
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-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-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-03-27[libc++] Introduce unversioned namespace macros (#133009)Nikolas Klauser
We've started using `_LIBCPP_BEGIN_NAMESPACE_STD` and `_LIBCPP_END_NAMESPACE_STD` for more than just the namespace for a while now. For example, we're using it to add visibility annotations to types. This works very well and avoids a bunch of annotations, but doesn't work for the few places where we have an unversioned namespace. This adds `_LIBCPP_BEGIN_UNVERSIONED_NAMESPACE_STD` and `_LIBCPP_END_UNVERSIONED_NAMESPACE_STD` to make it simpler to add new annotations consistently across the library as well as making it more explicit that the unversioned namespace is indeed intended.
2025-03-23[libc++] Add [[gnu::nodebug]] on type traits (#128502)Nikolas Klauser
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-19[libc++] Deprecate and remove member types of `hash` in `<variant>` (#127758)A. Jiang
These member types were deprecated in C++17 by P0174R2 and removed in C++20 by P0619R4, but the changes in `<variant>` seem missing. Drive-by: Replace one `_NOEXCEPT` with `noexcept` as the `hash` specialization is C++17-and-later only.
2025-01-23[libc++] Use [[clang::no_specializations]] to diagnose invalid user ↵Nikolas Klauser
specializations (#118167) Some templates in the standard library are illegal to specialize for users (even if the specialization contains user-defined types). The [[clang::no_specializations]] attribute allows marking such base templates so that the compiler will diagnose if users try adding a specialization.
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-14[libc++] Introduce __forward_as (#118168)Nikolas Klauser
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-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-10[libc++][NFC] Merge add_{const, cv, volatile}.h into a single header (#115610)Nikolas Klauser
There isn't much benefit in having granular headers for only a few simple lines of code.
2024-11-04[libc++][NFC] Use more appropriate type traits for a few cases (#114025)Nikolas Klauser
2024-10-31[libc++] Granularize <cstddef> includes (#108696)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-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-12[libc++][modules] Add a header to forward-declare std::get (#108285)Louis Dionne
This is necessary because e.g. ranges::elements_view uses std::get but it needs to have in scope the declaration of all the versions of std::get that exist in the library. This need is what had originally led to elements_view.h gaining an include of __fwd/complex.h, but in reality it is a more general issue that requires a canonical declration point for all the std::get variations.
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-09-06[libc++][modules] Tweak a few includes (#107467)Louis Dionne
Add a few missing includes, remove two unnecessary ones and use __cstddef/size_t.h instead of <cstddef> in a few places. This is a collection of miscellaneous findings that collectively unblock other modularization patches.
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-05-10[libc++] Make `constexpr std::variant`. Implement P2231R1 (#83335)Hui
Fixes #86686
2024-04-25[libc++] Reorganize the std::variant macros (#89419)Louis Dionne
std::variant uses multiple macros to generate special member functions. These macros were very subtle to read because of e.g. a macro argument appearing in the middle of a macro-ized class definition. In conjunction with clang-format, this could lead to extremely subtle macro expansions that were not easy to parse for humans. By adding semi-colons in macro expansions in judicious places, clang-format does a better job and makes these macros a lot easier to read. As a drive-by fix, I noticed that several of these functions were missing HIDE_FROM_ABI annotations, so I added them.
2024-04-19[libc++] Fix usage of 'exclude_from_explicit_instantiation' attribute on ↵Krystian Stasiowski
local class members (#89377) #88777 adds a warning for when the `exclude_from_explicit_instantiation` attribute is applied to local classes and members thereof. This patch addresses the few instances of `exclude_from_explicit_instantiation` being applied to local class members in libc++.
2024-04-01[libc++] Refactor __tuple_like and __pair_like (#85206)Nikolas Klauser
The exposition-only type trait `pair-like` includes `ranges::subrange`, but in every single case excludes `ranges::subrange` from the list. This patch introduces two new traits `__tuple_like_no_subrange` and `__pair_like_no_subrange`, which exclude `ranges::subrange` from the possible matches. `__pair_like` is no longer required, and thus removed. `__tuple_like` is implemented as `__tuple_like_no_subrange` or a `ranges::subrange` specialization.
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-13[libc++] Remove _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT (#83928)Louis Dionne
This was slated for removal in LLVM 19.
2024-03-11[libc++] Remove <tuple> from <variant> (#83183)Nikolas Klauser
This moves a utility from `<tuple>` into an implementation detail header and refactors the selection of the variant index type to use.
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
2024-01-21[libc++] Fix Coverity warning about use-after-move (#78780)Louis Dionne
While the code is technically correct because the index is never actually moved from (and anyway that wouldn't matter since it's an integer), it's still better style not to access an object after it has been moved-from. Since this is so easy to do, just save the index in a temporary variable. rdar://120501577
2024-01-21[libc++][variant] P2637R3: Member `visit` (`std::variant`) (#76447)Hristo Hristov
Implements parts of: `P2637R3` https://wg21.link/P2637R3 (https://eel.is/c++draft/variant.visit) Implements: `variant.visit()` `variant.visit<R>()` The tests are as close as possible to the non-member function. To land after: https://github.com/llvm/llvm-project/pull/76268 --------- Co-authored-by: Zingam <zingam@outlook.com>
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-22[libc++] Re-introduce special support for narrowing conversions to bool in ↵bgra8
variant (#73121) This patch re-introduces special support for narrowing conversions to bool in std::variant, which was removed in 170810fca6ee in order to make libc++ Standards-conforming. The special support is gated by the `_LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT` macro and will be supported for LLVM 18 only as a courtesy to help large code bases migrate over to the Standard behavior. --------- Co-authored-by: Bogdan Graur <bgraur@google.com> Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2023-11-15P1957R2: remove special-case for booleans in std::variant (#71502)David Benjamin
This picks up the std::variant half of P1957R2. Fixes #62332.
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-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-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.