Commit graph

183 commits

Author SHA1 Message Date
Avi Patel
1b3d208c77
[libc++] Implement P1901R2: owner_hash and owner_equal for shared_ptr/weak_ptr (#210551)
Fixes #105372.

## Acknowledgements

Claude assisted with test development.
2026-07-27 18:00:45 +08:00
Hui
a434fe87cc
[libc++] Implement std::function_ref (#186692)
Papers:
- P0792R14: function_ref: a type-erased callable reference
- P3948R1 constant_wrapper is the only tool needed for passing constant
expressions via function arguments
- P3961R1 Less double indirection in function_ref (RU-220)

LWG issues:
- LWG4256: Incorrect constraints for function_ref constructors from
nontype_t
- LWG4425: CTAD function_ref of data member pointer should produce
noexcept signature

Fixes #189606
Fixes #105376
Fixes #189604
Fixes #171321
Fixes #171387

---------

Co-authored-by: Xiaoyang Liu <siujoeng.lau@gmail.com>
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-07-25 17:44:55 +01:00
Connector Switch
faaeaf35a5
[libc++] Implement P0493R5: Atomic minimum/maximum (#180333)
Closes #105418.

Since gcc does not currently support `__atomic_fetch_min/max`, we use a
CAS loop in `atomic_ref` and `support/gcc.h`.

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-07-21 19:41:49 +08:00
Vinay Deshmukh
475bc045b4
[libc++] Make <set> std::set constexpr as part of P3372R3 (#167241) 2026-07-01 07:20:25 +08:00
A. Jiang
68395337ef
Revert "[libc++] P3798R1: The unexpected in std::expected (#204826)" (#205597)
Reverts 45a65bb48b.

Currently, there is no consensus among LWG and standard library
maintainers that P3798R1 should be applied as a Defect Report. So it is
better to revert the paper application for now and then reapply it as an
addition in C++29 when C++29 mode is ready.
2026-06-26 07:52:00 +08:00
William Tran-Viet
8a531c3608
[libc++] Implement P1885R12: <text_encoding> (#141312)
Resolves #105373, resolves #118371 and resolves #105332

- Implements `<text_encoding>`
- Adds availability macros for LLVM 23.
- The data is stored in three tables:
  - One giant string split by null-terminators to represent the aliases
- An index table which stores indexes into the string, each entry
representing the first character of an alias
- Text encoding data, which stores an index to the index table, the MIB,
and the number of aliases the encoding has.

Storing it in the above manner allows us to make significant savings in
binary file size and required runtime storage for the data.

As required by the LLVM Project's AI use policy:
- The implementation for `__get_locale_encoding(const char*)` for
Windows has been developed with the assistance of AI.

---------

Co-authored-by: A. Jiang <de34@live.cn>
2026-06-25 07:46:11 +08:00
Alex Kremer
45a65bb48b
[libc++] P3798R1: The unexpected in std::expected (#204826)
Closes #204394

Implements P3798 and related tests.

Applies the paper as a Defect Report per https://wg21.link/P3798/github.
2026-06-23 21:24:58 +08:00
Yihan Wang
a88b88bdd3
[libc++] Implement P4206R0 Revert string support in std::constant_wrapper (#203338)
Fixes https://github.com/llvm/llvm-project/issues/203336

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
Co-authored-by: A. Jiang <de34@live.cn>
2026-06-23 01:17:53 +08:00
A. Jiang
44cc7971ff
[libc++] P3369R0: constexpr for uninitialized_default_construct (#200163)
Remarks:
- Tests also verify that `uninitialized_default_construct(_n)`
algorithms do not initialize trivially default-constructible elements
(`int` in these tests) to determined values during constant evaluation.
2026-06-13 09:56:56 +08:00
Vinay Deshmukh
6e6c51be66
[libc++] Make <map> std::map constexpr as part of P3372R3 (#134330)
Fixes https://github.com/llvm/llvm-project/issues/128660

Adds `constexpr` support for `std::map` as per P3372R3

---------

Co-authored-by: A. Jiang <de34@live.cn>
2026-06-03 09:59:57 +02:00
Nhat Nguyen
866945c202
[libc++][ranges] P2542R8: Implement views::concat (#120920)
Closes #105419
Closes #105348
Closes #105349
Closes #171314

Assisted-by: Chatgpt. 
I use AI to help me write some tests, however. I have reviewed the code
I submit in the tests.

---------

Co-authored-by: A. Jiang <de34@live.cn>
Co-authored-by: Hristo Hristov <hghristov.rmm@gmail.com>
Co-authored-by: Hristo Hristov <zingam@outlook.com>
2026-05-30 23:26:16 +01:00
Connector Switch
d5d7c9c59f
[libc++] Implement ranges::fold_right_last (completes P2322R6) (#195580)
- Closes https://github.com/llvm/llvm-project/issues/105208.
- Closes https://github.com/llvm/llvm-project/issues/174061.
- Closes https://github.com/llvm/llvm-project/issues/174063.
2026-05-11 18:35:15 +08:00
A. Jiang
1d14d8597d
[libc++] P4144R1: Remove span's initializer_list constructor for C++26 (#191428)
Reverts P2447R6 (implemented in
dbbeee6b83). Some test cases that indicate
"old" behavior mentioned in P2447R6 are kept.
2026-04-26 01:18:07 +08:00
Will Hawkins
2f28e1db53
[libc++] Implement P1899 ranges::stride_view (#65200)
Implement `ranges::stride_view` in libc++. This PR was migrated from
Phabricator (https://reviews.llvm.org/D156924).

Closes #105198

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
Co-authored-by: A. Jiang <de34@live.cn>
2026-04-25 06:51:37 -04:00
Hristo Hristov
2039a51881
[libc++][ranges] P2164R9: Implements views::enumerate (#73617)
This patch implements https://wg21.link/P2164R9 `std::views::enumerate`.
This PR was migrated from https://reviews.llvm.org/D157193.

Implemented papers and LWG issues:
- https://wg21.link/P2164R9: views::enumerate
- https://wg21.link/LWG3919: enumerate_view may invoke UB for sized common non-forward underlying ranges
- https://wg21.link/LWG3914: Inconsistent template-head of ranges::enumerate_view
- https://wg21.link/LWG3912: enumerate_view::iterator::operator- should be noexcept

Closes #105251
Closes #105315
Closes #105280
Closes #105279
2026-04-22 08:42:38 -04:00
Hui
b799d7e8f8
[libc++] Implement std::constant_wrapper (#191695)
Fixes #148179
Fixes #189605
Fixes #189865
Fixes #171370
Fixes #189856
Fixes #189838
Fixes #171359
2026-04-21 11:45:59 -04:00
Hristo Hristov
48ad929c0f
[libc++][numeric] P4052R0: Renaming saturation arithmetic functions (#189574)
Implements P4052R0.

Also renames:
- the internal names for consistency.
- test files (no changes to the contents but the function names).

Fixes: #189589

---------

Co-authored-by: A. Jiang <de34@live.cn>
2026-04-12 17:21:12 +03:00
Hristo Hristov
f5509542c0
[libc++][atomics] P3936R1: Safer `atomic_ref::address` (#189761)
Implements P3936R1

Closes #189594

# References:

- https://llvm.org/PR162236
- https://wg21.link/p3936r1

---------

Co-authored-by: A. Jiang <de34@live.cn>
Co-authored-by: Hristo Hristov <zingam@outlook.com>
2026-04-12 14:56:35 +08:00
Hui
d7a24d30f6
[libc++] Implement ranges::shift_right (#177847)
Implement the `ranges::shift_right` algorithm from
[P2440R1](https://wg21.link/P2440R1).

Fixes #134062
Fixes #105184
2026-02-14 17:34:44 +00:00
A. Jiang
bf6e9867c7
[libc++] Update __cpp_lib_flat_set to 202511L according to P3567R2 (#176297)
The paper was already implemented in LLVM22 in cd13170aea,
but the previous patch forgot to update `__cpp_lib_flat_set`.

Fixes #176232.
2026-01-19 15:27:56 -05:00
Hui
985d75a57a
[libc++] define FTM __cpp_lib_ranges_zip (#176569)
P2321R2 has been implemented in various PRs. Based on the discussion
in #105169, the last bit in iterator.concept.winc doesn't require
any changes, so we can actually mark this as done.

Fixes #105169
2026-01-19 15:18:57 -05:00
Matthias Wippich
617b446176
[libc++] Implement P1789R3: Library Support for Expansion Statements (#167184)
[P1789R3](https://isocpp.org/files/papers/P1789R3.pdf) was accepted for
C++26 through LWG motion 14 at the 2025 Kona meeting. This patch
implements it, along with tests and documentation changes.

Closes #167268

---------

Co-authored-by: Tsche <che@pydong.org>
2025-12-26 09:07:13 +08:00
Hui
cd13170aea
[libc++] Implement P3567R2 flat_meow fixes (#162022)
Fixes #171272

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-12-20 21:18:44 +00:00
Janet Cobb
ef190061d3
[libc++][concepts] P2404R3: Move-only types for equality_comparable_with, totally_ordered_with, and three_way_comparable_with (#99420)
This implements all of [P2404R3](https://wg21.link/p2404r3)'s concept
changes.

---------

Co-authored-by: A. Jiang <de34@live.cn>
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-12-19 17:56:32 +08:00
William Tran-Viet
389a23c538
[libc++] Implement P2988R12: std::optional<T&> (#155202)
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-12 11:00:08 +08:00
Nikolas Klauser
2527b071ba
[libc++] P2641R4: Checking if a union alternative is active (std::is_within_lifetime) (#165243)
<https://wg21.link/P2641R4>

Implements the C++26 function in `<type_traits>` [meta.const.eval] (and
the corresponding feature test macro `__cpp_lib_is_within_lifetime`)

```c++
template<class T>
  consteval bool is_within_lifetime(const T*) noexcept;
```

This is done with the `__builtin_is_within_lifetime` builtin added to
Clang 20 by #91895 / 2a07509c8d. This is
not (currently) available with GCC.

This implementation has provisions for LWG4138
<https://cplusplus.github.io/LWG/issue4138> where it is ill-formed to
instantiate `is_within_lifetime<T>` with a function type `T`.

Closes #105381

Co-authored-by: Mital Ashok <mital@mitalashok.co.uk>
2025-11-02 10:30:31 +01:00
Hui
c07440b887
[libc++] constexpr flat_multiset (#161016)
Fixes https://github.com/llvm/llvm-project/issues/128676
2025-11-01 08:51:35 +00:00
Hristo Hristov
8a27b48122
[libc++][atomic] P2835R7: Expose std::atomic_ref's object address (#162236)
Implements https://wg21.link/P2835R7

Closes #118377

# References

- https://wg21.link/atomics.ref.generic.general
- https://wg21.link/atomics.ref.int
- https://wg21.link/atomics.ref.float
- https://wg21.link/atomics.ref.pointer

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-10-13 20:27:02 +08:00
Hristo Hristov
45c41247f8
[libc++][ranges] P3060R3: Add std::views::indices(n) (#146823)
Implements [P3060R3](https://wg21.link/P3060R3)

Closes #148175

# References

- https://github.com/cplusplus/draft/issues/7966
- https://github.com/cplusplus/draft/pull/8006
- https://wg21.link/customization.point.object
- https://wg21.link/range.iota.overview
- https://wg21.link/ranges.syn

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: A. Jiang <de34@live.cn>
2025-10-06 18:13:25 +03:00
Hristo Hristov
804b46bb45
[libc++][string] P3044R2: sub-string_view from string (#147095)
Implements [P3044R2](https://wg21.link/P3044R2)

Note: `substr.pass.cpp` is refactored to accommodate the test of
`basic_string_view`'s `subview` which is an alias of `substr` without
changing the test cases.

Closes #148140

# References

- https://github.com/cplusplus/draft/pull/7975
- https://wg21.link/string.substr
- https://wg21.link/string.view.ops

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-09-25 03:08:15 +03:00
William Tran-Viet
1c51886920
[libc++] Implement P3168R2: Give optional range support (#149441)
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-08-18 18:04:45 +03:00
A. Jiang
4a509f853f
[libc++] Implement comparison operators for tuple added in C++23 (#148799)
And constrain the new `operator==` since C++26.

This patch implements parts of P2165R4, P2944R3, and a possibly improved
resolution of LWG3882. Currently, libstdc++ and MSVC STL constrain the
new overloads in the same way.

Also set feature-test macro `__cpp_lib_constrained_equality` and add
related release note, as P2944R3 will completed with this patch.

Fixes #136765
Fixes #136770
Fixes #105424
2025-08-01 11:53:33 -04:00
Hui
0d1e5ab2fd
[libc++] P2655R3 common_reference_t of reference_wrapper Should Be a Reference Type (#141408)
Fixes #105260

This patch applies the change as a DR to C++20. The rationale is that
the paper is more like a bug fix. It does not introduce new features, it
simply changes an existing behaviour (as a bug fix). MSVC STL DRed this
paper to C++20 as well.
2025-07-06 17:32:59 +01:00
Jakub Mazurkiewicz
1bb2328fd3
[libc++] Implement views::join_with (#65536)
* Implement "P2441R2 `views::join_with`" (https://wg21.link/P2441R2),
closes #105185
* Implement LWG4074 (https://wg21.link/LWG4074), closes #105346
* Complete implementation of "P2711R1 Making multi-param constructors of
views explicit" (https://wg21.link/P2711R1), closes #105252
* Complete implementation of "P2770R0 Stashing stashing iterators for
proper flattening" (https://wg21.link/P2770R0), closes #105250
2025-06-21 10:54:50 +01:00
Peng Liu
13510c0736
[libc++] Make list constexpr as part of P3372R3 (#129799)
This patch makes `std::list` constexpr as part of P3372R3.

Fixes #128659.
2025-06-18 12:13:50 -04:00
Peng Liu
38fb0117ab
[libc++] Make forward_list constexpr as part of P3372R3 (#129435)
Fixes #128658
2025-06-11 12:13:36 -04:00
Peng Liu
3e5fd77d32
[libc++] constexpr priority_queue (#140634)
This patch makes `priority_queue` constexpr as part of P3372R3.

Fixes #128671.
2025-06-04 19:58:25 +08:00
Damien L-G
557e931d95
[libc++] Implement P2897R7 aligned_accessor: An mdspan accessor expressing pointer over-alignment (#122603)
Closes #118372
2025-04-14 17:33:57 -04:00
Hui
7013b51548
[libc++] Implement std::flat_multiset (#128363)
fixes https://github.com/llvm/llvm-project/issues/105193
2025-04-06 10:50:55 +01:00
James E T Smith
475cbf0ad6
[libc++] Implement ranges::iota (#68494)
# Overview

As a disclaimer, this is my first PR to LLVM and while I've tried to
ensure I've followed the LLVM and libc++ contributing guidelines,
there's probably a good chance I missed something. If I have, just let
me know and I'll try to correct it as soon as I can.

This PR implements `std::ranges::iota` and
`std::ranges::out_value_result` outlined in
[P2440r1](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2440r1.html).

As outlined in the paper above, I've:
- Implemented `out_value_result` and added to `<algorithm>`
- Added `out_value_result`, `iota_result`, and two overloads of `iota`
to `std::ranges` in `<numeric>`
- Updated the version macro `__cpp_lib_ranges_iota` in `<version>`

I've also added tests for `ranges::iota` and `ranges::out_value_result`.
Lastly, I added those structs to the appropriate module files.

Partially implements #105184

EDIT: Forgot to mention in the original post, thanks to @hawkinsw for
taking a look at a preliminary version of this PR!

# TODOs
- [x] Updating the range [status
doc](https://github.com/jamesETsmith/llvm-project/blob/main/libcxx/docs/Status/RangesMajorFeatures.csv)
- [x] Ensure all comments from https://reviews.llvm.org/D121436 are
addressed here
- [X] EDIT (I'll do this in a separate PR). ~~I'm open to implementing
the rest of P2440r1 (`ranges::shift_left` and `ranges::shift_right`) if
that's ok, I just wanted to get feedback on `ranges::iota` first~~
- [x] I've been having trouble building the modules locally and want to
make sure that's working properly

Closes: #134060
2025-04-05 13:46:11 +02:00
A. Jiang
6038077dde
[libc++] Bump __cpp_lib_constexpr_algorithms for P2562R1 in C++26 (#132075)
Completes P2562R1.
2025-03-21 07:33:52 +08:00
A. Jiang
2207e3e325
[libc++] Set feature-test macro __cpp_lib_atomic_float (#127559)
The corresponding feature was implemented in LLVM 18 (by #67799), but
this FTM wasn't added before.
2025-02-19 09:06:51 +08:00
Hui
def50f701f
[libc++] implement std::flat_multimap (#113835)
fixes https://github.com/llvm/llvm-project/issues/105190

---------

Co-authored-by: Hui Xie <huixie@Mac.broadband>
Co-authored-by: Hui Xie <huixie@Huis-MacBook-Pro.local>
2025-01-25 18:30:00 +00:00
Jakub Mazurkiewicz
c91d805e66
[libc++] Implement std::not_fn<NTTP> (#86133)
Implement `std::not_fn<NTTP>` from "P2714R1 Bind front and back to NTTP callables".
2025-01-10 14:14:14 -05:00
A. Jiang
76b71c0bc4
[libc++] Set __cpp_lib_smart_ptr_for_overwrite (#114700)
The features were implemented in LLVM 16, but mistakenly considered
unimplemented in FTM tools.
2024-11-05 13:27:40 +08:00
A. Jiang
cae351f345
[libc++] Bump __cpp_lib_optional and __cpp_lib_variant (#113650)
In C++20 mode, `__cpp_lib_optional` and `__cpp_lib_variant` should be
`202106L` due to DR P2231R1.

In C++26 mode, `__cpp_lib_variant` should be bumped to `202306L` due to
P2637R3.
- Clang 16/17 shouldn't get this bumping (as member `visit` requires
explicit object parameters), but it's very tricky to make the bumping
conditionally enabled. I _hope_ unconditionally bumping in C++26 will be
OK for LLVM 20 when the support for Clang 17 is dropped.

Related PRs:
- https://reviews.llvm.org/D102119
- #83335
- #76447
2024-10-26 07:38:52 +08:00
Hristo Hristov
a06591b4d4
[libc++][type_traits] P2674R1: A trait for implicit lifetime types (#106870)
Implements P2674R1: https://wg21.link/P2674R1

- https://eel.is/c++draft/type.traits
  - https://eel.is/c++draft/meta.type.synop
  - https://eel.is/c++draft/meta.unary.prop
- https://eel.is/c++draft/support.limits
  - https://eel.is/c++draft/version.syn

Implementation details:
- Uses compiler intrinsic `__builtin_is_implicit_lifetime`:
  - https://github.com/llvm/llvm-project/pull/101807
- Tests based on:
-
d213981c80/clang/test/SemaCXX/type-traits.cpp (L1989)

References:
- Implicit-lifetime
- Implicit-lifetime types [basic.types.general]/9:
https://eel.is/c++draft/basic.types.general
- Implicit-lifetime class [class.prop]/9:
https://eel.is/c++draft/class.prop
- P0593R6 Implicit creation of objects for low-level object
manipulation: https://wg21.link/P0593R6
- P1010R1 Container support for implicit lifetime types:
https://wg21.link/P1010R1
- P0593R6 Implicit creation of objects for low-level object
manipulation: https://wg21.link/P0593R6

Closes: #105259

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-10-09 08:19:14 +02:00
A. Jiang
7808541fde
[libc++] P2747R2: constexpr placement new (library part) (#105768)
This patch implements https://wg21.link/P2747R2.

The library changes affect direct `operator new` and `operator new[]`
calls even when the core language changes are absent.

The changes are not available for MS ABI because the `operator new` and
`operator new[]` are from VCRuntime's `<vcruntime_new.h>`. A feature
request was submitted for that [1].

As a drive-by change, the patch reformatted the whole `new.pass.cpp` and
`new_array.pass.cpp` tests.

Closes #105427

[1]: https://developercommunity.visualstudio.com/t/constexpr-for-placement-operator-newope/10730304.
2024-08-28 09:35:57 -04:00
A. Jiang
026210e80d
[libc++][ranges] P2609R3: Relaxing Ranges Just A Smidge (#101715)
This patch implements https://wg21.link/p2609r3.
The test code was originally authored by JMazurkiewicz.

Notes:
- P2609R3 is not officially a Defect Report, but MSVC STL
  implements it in C++20 mode.

  Moreover, P2609R3 and P2997R1 touch exactly the same set of
  concepts, and MSVC STL and libc++ have already treated P2997R1
  as a DR.

- This patch also adjusted feature-test macros.
  + In C++20 mode, the value of __cpp_lib_ranges should be `202110L` because
    - `202202L` covers `range_adaptor_closure` (P2387R3), and
    - `202207L` covers move-only types in range adaptors (P2494R2).
  And all of these changes are only available since C++23 mode.

  + In C++23 mode, the value should be `202406L` because
    - `202211L` covers removing poison overloads (P2602R2),
    - `202302L` covers relaxing projected value types (P2609R3), and
    - `202406L` covers removing requirements on `iter_common_reference_t` (P2997R1).
  And all of these changes are already or being implemented.

Fixes #105253.

Co-authored-by: Jakub Mazurkiewicz <mazkuba3@gmail.com>
2024-08-28 08:55:44 -04:00
Louis Dionne
1c48c9cc43
[libc++] Implement P2985R0: std::is_virtual_base_of (#105847)
This trait is implemented in C++26 conditionally on the compiler
supporting the __builtin_is_virtual_base_of intrinsic. I believe only
tip-of-trunk Clang currently implements that builtin.

Closes #105432
2024-08-26 09:58:19 -04:00