Commit graph

7061 commits

Author SHA1 Message Date
A. Jiang
232e8b5f45
[libc++] Implement LWG4169: std::atomic<T>'s default constructor should be constrained (#131950)
Drive-by: Rename `constexpr_noexcept.compile.pass.cpp` to
`ctor.default.pass.cpp` as test coverage is added to it, and compile and
run it in all modes.
2026-08-01 17:20:05 +08:00
Louis Dionne
c433135c99
[libc++] Remove unused headers from <cmath> (#213114)
I believe these headers were relevant when we actually implemented
functions in `<cmath>`, but they are not anymore. Note that ::hypot in
particular is obtained from <math.h> like all the other math functions.

Co-authored-by: A. Jiang <de34@live.cn>
2026-07-31 13:25:22 -04:00
Louis Dionne
9bc2dd1a70
[libc++] Add an assertion for monotonic_buffer_resource's initial_size (#213136)
[mem.res.monotonic.buffer.ctor] requires initial_size to be greater than
zero for the two constructors that take one, but we silently accepted
zero. Add a hardening assertion for that precondition.

Fixes #213059
2026-07-31 13:21:58 -04:00
Nikolas Klauser
e147e5b7d0
[libc++] Simplify clear_padding.h a bit (#212426) 2026-07-31 13:25:12 +02:00
Nikolas Klauser
090b6569b6
[libc++] Make __has_array_cookie a variable template (#212767)
Using variable templates is slightly faster to compile and more
readable, so we might as well use them.
2026-07-31 13:24:04 +02:00
Michael G. Kazakov
b4d2b2f9a3
[libc++][pstl] Implementation of parallel std::lexicographical_compare() based on std::mismatch() (#212366)
This PR adds an implementation of parallel
`std::lexicographical_compare()` based on parallel `std::mismatch()`.

The implementation is close to a one-liner:
```c++
auto __res = _Mismatch()(__policy, __first1, __last1, __first2, __last2, [&](_Ref1 __lhs, _Ref2 __rhs) {
  return !__comp(__lhs, __rhs) && !__comp(__rhs, __lhs);
});
```

Included tests check that:
- Semantics of the iterator-only version is correct.
- Semantics of the predicated version is correct.
- The functions correctly SFINAE out when the first argument is not an
execution policy.
- The `noexcept` policy is followed.
- The `nodiscard` policy is followed.
- `static_assert` verifies iterators' categories.

Part of #99938.
2026-07-31 09:06:38 +08:00
Kyungtak Woo
66d049cdad
[libc++] Fix std::mt19937 seeding with std::seed_seq under vectorized ABI (#209860)
This PR fixes a bug in `std::mersenne_twister_engine::seed(_Sseq&)`
where the initialization twist is bypassed when the vectorized engine
optimization (`_LIBCPP_ABI_VECTORIZED_MERSENNE_TWISTER_ENGINE`) is
enabled.

In the vectorized implementation introduced in #206423, the engine state
must be pre-twisted during initialization by calling
`__update_all_states()` at the end of the `seed` functions.

However, in `seed(_Sseq& __q)`, the all-zero state check contains an
early `return;` when a non-zero state is verified. This early return
bypasses the trailing `__update_all_states()` call. Consequently, the
generator is initialized with raw, untwisted seed values (tempered)
rather than the standard twisted values.

This only manifests when compiled with unstable ABI settings
(`_LIBCPP_ABI_VERSION >= 2`) which enables the vectorized
implementation.

I replaced the early `return;` inside the all-zero state verification
block with a loop break, and conditionalized the zero-state fix using
the loop index `__i`, ensuring `__update_all_states()` is always
executed at the end of the function. Added regression tests to
`seed_sseq.pass.cpp` asserting the exact deterministic outputs for both
32-bit and 64-bit engines.
2026-07-30 09:08:22 -06:00
Hristo Hristov
11b58f0e4c
[libc++][ranges] P3059R2: Making user-defined constructors of view iterators/sentinels private (#193891)
Implements https://wg21.link/P3059R2 (DR)

Closes #189599

1. Made constructors of iterator and sentinel types of the following
views private:
  - `iota_view`
  - `basic_istream_view`
  - `filter_view`
  - `transform_view`
  - `take_view`
  - `take_while_view`
  - `join_view`
  - `lazy_split_view`
  - `split_view`
  - `elements_view`
2. Updated all relevant tests to fix the usages of the now private
constructor, including:
   1. Removed now obsolete tests (files and cases).
2. Updated all relevant tests to get the iterators and the sentinels via
`begin()` and `end()`, wherever applicable .
   3. Added test cases to confirm that P3059R2 was implemented properly.
   4. Minor other (necessary) tweaks.

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: A. Jiang <de34@live.cn>
2026-07-30 17:57:11 +03:00
Nikolas Klauser
a8cc3d2592
[libc++] Clean up windows macros (#207577)
We have multiple macros for different Windows. However, most of them
don't actually define different things. We can condense the macros to
- `_WIN32` directly if it only depends on windows, or
- `_LIBCPP_MSVCRT`

This patch drops `_LIBCPP_MSVCRT_LIKE` and `_LIBCPP_WIN32API`, since
they are equivalent to `_WIN32`.
2026-07-30 14:05:39 +02:00
Nikolas Klauser
d3ca4e5011
[libc++][NFC] Rename the streambuf members (#212277)
This refactors `streambuf` to contain a `_GetArea` and a `_PutArea`.
This makes the code significantly easier to read, since the pointers
belonging together are bundled in a struct.
2026-07-30 11:19:56 +02:00
Nikolas Klauser
98cdcbae77
[libc++] Move numpunct into <__locale_dir/num.h> (#212465)
`numpunct` is part of the `num` family of facets, so it should live in
`num.h`.
2026-07-30 11:17:44 +02:00
Nikolas Klauser
c27b35739d
[libc++] Remove SFINAE checks in tuple which are always true (#212765)
We have a specialization for `tuple` with no arguments, so checking
`sizeof...(_Tp) >= 1` in the primary template will never be false.
2026-07-30 11:17:08 +02:00
William Tran-Viet
7ded638ea3
[libc++] Granularize <optional> (#206644)
Certain headers require `optional<T&>`, so it may be beneficial to split
out `optional<T>` and `optional<T&>`. This can allow consumers to only
bring in the `optional` flavour it needs..

- Parcel out the respective pieces into their own header.
- Certain sources rely on transitive includes brought in by
`<optional>`, so they're kept there for now, and only tests have been
fixed.

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-07-30 11:12:15 +08:00
higher-performance
a01f8c85bc
Speed up compilation of typical invocations of std::visit(std::variant<...>) for up to 11 types (#164196)
Similar to https://reviews.llvm.org/D90168 which was reverted (https://github.com/llvm/llvm-project/issues/62648#issuecomment-1832315651), but uses `switch` statements rather than function pointer tables.
2026-07-29 22:38:39 -04:00
Lucas Mellone
aa924278ef
[libc++][math] Add missing constexpr since C++23 comment for signbit (#212458)
Adds the missing `// constexpr since C++23` for `std::signbit` in the
synopsis comments of `<cmath>`.
Follows-up: https://github.com/llvm/llvm-project/pull/105946.
2026-07-30 01:57:21 +08:00
Michael G. Kazakov
196b4b6a2d
[libc++][pstl] Implementation of a parallel std::adjacent_find() based on std::mismatch() (#210604)
This PR implements a parallel `std::adjacent_find()` based on parallel
`std::mismatch`. The implementation reshapes the input range as two ranges
offset by 1 element and asks `std::mismatch` to find the first equal pair.

Part of #99938.
2026-07-29 11:08:13 -04:00
Louis Dionne
8ea9597ccb
[libc++] Defer removal of two escape hatches to LLVM 25 (#211553)
Rather than removing the escape hatches for trivially default
constructible allocator and bitset's const reference type in LLVM 24,
keep them around for another release since they have not been widely
deployed yet.
2026-07-28 12:47:43 -04:00
Lucas Mellone
a69addf4fb
[libc++][math] Add constexpr to comparison functions (#210075)
Implement `constexpr` to all comparison functions (`std::isgreater`,
`std::isgreaterequal`, `std::isless`, `std::islessequal`,
`std::islessgreater`, `std::isunordered`) as defined by
[P0533R9](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0533r9.pdf).

Towards https://github.com/llvm/llvm-project/issues/105174. Follows-up
https://github.com/llvm/llvm-project/pull/94118.
2026-07-28 18:14:47 +03:00
Hristo Hristov
0fc8ce3bb5
[libc++][optional][NFC] Use variable templates instead of class templates (#212443)
Modernizing similar to: https://github.com/llvm/llvm-project/pull/199481
2026-07-28 18:12:56 +03:00
Nikolas Klauser
455ef3684f
[libc++] Fix ungetc failing after xsgetn (#210951)
After #206453 we don't correctly handle `unget()` anymore. This fixes
the issue by updating the internal buffer to contain the tail of the
read data.

Fixes #210203
2026-07-28 16:27:10 +02:00
Nikolas Klauser
bcdff65a95
[libc++] Simplify some meta-programming in tuple (#212436)
This does two things:
- replace `_Not<T>::value` with `!T::value` when we already evaluate
lazily
- remove `_And`s that aren't useful because they only have a single
argument
2026-07-28 13:33:47 +02:00
Hui
de962dda12
[libc++] Implement P0528R3 std::atomic CAS for types with padding (#76180)
Fixes #99984

Implement P0528R3 The Curious Case of Padding Bits, Featuring Atomic
Compare-and-Exchange


The unit test padding.pass.cpp is assisted by Cursor. However, all tests
have been modified to test what I wanted to test

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-07-28 07:15:19 +01:00
Nikolas Klauser
3d20ba7135
[libc++][NFC] Use [[deprecated]] for __grow_by (#209126)
`__grow_by` is an internal function, and we deprecated it to avoid
accidental use of it inside the library. `_LIBCPP_DEPRECATED_` is meant
for user-configuration, which doesn't apply here.

Fixes #124940
2026-07-27 11:16:02 -04:00
William Tran-Viet
c84136af3d
[libc++] Inline text_encoding alias offset table std::count to 884 (#207471)
- Add count test to verify the exact number of aliases our table
contains
- Should reduce compile time cost of gathering that count
2026-07-27 13:32:19 +02:00
Nikolas Klauser
1333e0a05d
[libc++] Remove locale:🆔:__next_id from the ABI (#210360)
`__next_id` is only ever used inside the dylib, so we can avoid making it public.
2026-07-27 13:21:45 +02:00
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
Nico Weber
1f48ea0f63
[libc++] Removing traiilng whitespace at line end in CMakeLists.txt (#212135)
Follow-up to #209291.
2026-07-26 13:15:10 -04:00
Emmett
286fcce7e7
[libc++][chrono] Implement LWG 4274: Allow chrono::hh_mm_ss to be constructed from unsigned durations (#209686)
**_Implementation details_**:
- Use `is_unsigned_v` instead of `numeric_limits<Rep>::is_signed`, which
is used by `chrono::abs`. `numeric_limits<Rep>::is_signed` may return
false when a custom `Rep` does not specialize `numeric_limits`. Relying
on it to detect the unsigned case could therefore be unreliable for such
a type. `is_unsigned_v` instead gives a compile-time path for built-in
unsigned types, while the sign check keeps signed types correct.

- The constructor calls `__abs_d` four times because each member is
initialized separately. This should not affect runtime performance
because the compiler should inline `__abs_d` and eliminate the repeated
calculations. We could use another helper function or helper class to
explicitly compute the absolute duration only once. However, this would
add extra glue code, and the added complexity is not worthwhile I think.

---------

Co-authored-by: A. Jiang <de34@live.cn>
2026-07-27 00:09:16 +08:00
Nikolas Klauser
61517a8140
[libc++][NFC] Inline fstream functions into the class body (#211738)
The `fstream` member functions are all really short, so inlining them
removes quite a bit of boiler plate code.
2026-07-26 17:46:14 +02:00
Michael G. Kazakov
150f33ce28
[libc++][pstl] Implementation of a parallel std::mismatch() based on __pstl::__parallel_find() (#209291)
This PR adds a parallel version of `std::mismatch` as one of the backend
operations.
It also provides an implementation based on `__pstl::__parallel_find()`
which does the heavy lifting.
`libdispatch` and `std_thread` backends expose this implementation under
their backend tags, while the `serial` backend redirects the calls to
the serial `std::mismatch`.

4 flavours of the function are exposed: 3-legged, 3-legged with
predicate, 4-legged, 4-legged with predicate.
3-legged flavours are implemented in the `default` (`composition`)
backend by redirecting the call to the 4-legged flavours.

Included tests check that:

- Semantics of the iterator-only functions is correct.
- Semantics of the predicated functions is correct.
- Custom types are supported by the implementation.
- The functions correctly SFINAE out when the first argument is not an
execution policy.
- The `nodiscard` policy is followed.
- The `noexcept` policy is followed.
- `static_assert` verifies iterators' categories.

Part of #99938.
2026-07-26 22:51:39 +08:00
Lucas Mellone
4eeff3e309
[libc++][math] Add constexpr to std::fpclassify (#210993)
Adds `constexpr` to `std::fpclassify` as required by
[P0533R9](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0533r9.pdf).

Towards https://github.com/llvm/llvm-project/issues/105174. Follows-up
8889a3d3b5.
2026-07-26 14:30:25 +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
Louis Dionne
be86221af3
[libc++] Implement any_of in terms of find_if (#207274)
This way, any optimizations in find_if will be picked up by any_of.

Closes #129310
2026-07-23 09:38:21 -04:00
Nikolas Klauser
3b7447e00b
[libc++] Optimize standard streams with sync_with_stdio(false) (#209161)
This updates the standard streams so that the buffers are replaced with
`basic_filebuf`s.

Fixes #21566

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-07-23 09:46:47 +02:00
Nikolas Klauser
6f3328e869
[libc++] Don't add #pragma clang attribute with GCC (#206989)
GCC doesn't support `#pragma clang attribute`, which causes a bunch of
diagnostics. Since we have it behind a macro anyways we can simply
define the macro as empty with GCC.
2026-07-22 17:46:13 +02:00
Louis Dionne
17ac8fdd95
[libc++] Don't require complete types in vector<T>::empty() (#210754)
This was previously not required, but the patch to introduce a new
size-based vector layout unintentionally added this new requirement. We
almost certainly not want to promise this guarantee going forward, but
we should actually land this change explicitly and consider the
transition story, not do it as a fallout of another refactoring.

Fixes #210732
2026-07-21 10:21:27 -04:00
Michael G. Kazakov
460778b9d6
[libc++][pstl] Default implementation of parallel std::adjacent_difference (#207585)
This PR adds a "one-liner" default implementation of parallel
`std::adjacent_difference` on top of parallel binary `std::transform`.

The implementation builds two iterator ranges out of the input one, so
that a zip of these ranges yields adjacent pairs. Then performs a binary
transform to calculate and output the adjacent differences.

Part of https://github.com/llvm/llvm-project/issues/99938
2026-07-21 07:42:26 -04: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
Michael G. Kazakov
c40a68644c
[libc++] Strip cv-refs in __desugars_to specialization for integral types (#208950)
This PR passes the argument type through `__remove_cvref_t` before
passing to `is_integral`.

Fixes #208236
2026-07-21 07:40:22 -04:00
h-vetinari
b8eebf2704
[libc++][NFC] Re-order availability mapping to _LIBCPP_INTRODUCED_IN_LLVM_{N} (#210694)
Noticed that the new additions (from 16f692338c and 8a531c3608) were placed
rather randomly. Put the mapping back to reverse chronological order, see 
783fd2f9d.
2026-07-21 07:34:43 -04:00
Louis Dionne
7f49d95c09
[libc++][NFC] Fix synopsis comment for error_condition::message() (#210724)
The method was marked as noexcept in the synopsis, but it's neither
marked noexcept in the spec nor in our implementation.
2026-07-21 07:22:59 -04:00
Hristo Hristov
eec2f0916d
[libc++][NFC] Removed duplicated _LIBCPP_INTRODUCED_IN_LLVM_23 macros (#210602)
Removed the redundant macros, which apparently were added by two
different patches.
2026-07-20 12:23:30 +03:00
Hristo Hristov
ead8fd8e29
[libc++][ranges][NFC] Format lazy_split_view (#210644)
Pre-requisite for: https://github.com/llvm/llvm-project/pull/193891
2026-07-20 12:23:06 +03:00
Nikolas Klauser
4234ff6532
Reapply "[libc++][NFC] Inline std::function members into the class body" (#209555) (#210260)
This caused LLDB to fail, which has been fixed now.

This reverts commit 7618426138.
2026-07-20 10:35:29 +02:00
Hristo Hristov
53c6ce165a
[libc++][cmp][NFC] Fix: Empty namespaces should be avoided (#210624)
Context: Including `<__utility/cmp.h>` causes:

> cmp.h:25:1: error: Empty namespaces should be avoided. Move any checks
around the namespace instead.
[libcpp-avoid-empty-namespaces,-warnings-as-errors]
2026-07-20 05:47:58 +03:00
Nikolas Klauser
122efb2689
[libc++] Optimize std::is_heap_until (#209141)
Fixes #208299
2026-07-16 16:46:46 +02:00
Louis Dionne
f4120c4a1d
[libc++] Treat negative counts in copy_n & friends as no-ops (#207086)
The standard specifies copy_n, fill_n and generate_n (both std and
ranges) to be no-ops when passed a negative count. This patch fixes
libc++ to abide by that requirement, with tests.

It's worth noting that std::for_each_n makes n > 0 a precondition
instead: we add the check and tests for it.

Fixes #193613
2026-07-15 13:24:03 -04:00
Liza Burakova
3e706075dc
[libc++][pstl] Add missing #pragma GCC system_header to libdispatch.h (#209579)
This adds `#pragma GCC system_header` to libdispatch.h, as removing the
`[system]` attributes in the modulemap surfaced this gap.
2026-07-14 14:26:11 -04:00
Felipe de Azevedo Piovezan
7618426138
Revert "[libc++][NFC] Inline std::function members into the class body" (#209555)
Reverts llvm/llvm-project#209461

This is breaking LLDB testing bots and it also failed pre-merge CI.
2026-07-14 18:12:19 +01:00
Douglas Yung
6af0a79d7a
Bump version to 24.0.0git (#209473) 2026-07-14 09:21:03 -04:00