Commit graph

7906 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
Hristo Hristov
34de4392d0
[libc++][ranges][test-suite][NFC] Consistency improvements after P3050 merge (#213062)
Consistency improvements and other small tweaks.

A follow-up to https://github.com/llvm/llvm-project/pull/193891 - the
changes were deferred to reduce the size of an already large and
approved PR.
2026-07-31 21:23:54 +03: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
Louis Dionne
dac66ca477
[libc++] Fix dangling reference in the associative container benchmarks (#213139)
Two insert benchmarks were registered with lambdas capturing insert_iter_iter_bench
by reference, unlike every other registration in this file, which captures by value.

RegisterBenchmark() stores the lambda by value and only invokes it from
RunSpecifiedBenchmarks(), which happens long after associative_container_benchmarks()
has returned, creating a dangling reference.
2026-07-31 13:21:21 -04:00
Louis Dionne
69685bb9ce
[libc++] Actually partially populate the container in a benchmark (#213146)
The "partially populated" variant of assignment was a copy-paste of the
"into cleared container" assignment.
2026-07-31 13:20:14 -04:00
Michael G. Kazakov
2f30bd168c
[libc++][NFC] Make size_t -> int conversions explicit in a few PSTL tests (#213145)
The implicit truncating conversions that were introduced in some PSTL
tests are causing warnings on MSVC. This PR fixes that.

See
https://github.com/llvm/llvm-project/pull/212366#discussion_r3679252259
for more details.
2026-07-31 20:43:31 +08:00
Nikolas Klauser
3a809f644c
[libc++abi] Add a clang-tidy config and test (#207324)
This essentially copies the `.clang-tidy` file from libc++ into
libc++abi, except that the naming conventions are updated to not add
underscores and some checks are disabled that don't pass currently. They
will be fixed in follow-ups.
2026-07-31 13:26:27 +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
Zibi Sarbinowski
f8eefd3d9d
[libc++] Fix difference_type expectations in range adaptor iterator member_types tests (#201853)
This fixes incorrect expectations in:

```
libcxx/test/std/ranges/range.adaptors/range.adjacent/iterator/member_types.compile.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.zip.transform/iterator/member_types.compile.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.adjacent.transform/iterator/member_types.compile.pass.cpp
```

These iterators define difference_type as `range_difference_t<Base>`.
For `ForwardSizedView` and `InputCommonView`, the `difference_type` of
the underlying iterators is `std::intptr_t` in `test_iterators.h`.

The tests instead assert `std::ptrdiff_t`. That happens to hold on
platforms where `std::intptr_t` and `std::ptrdiff_t` are the same type,
but fails elsewhere.

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-07-30 13:08:46 -04: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
76140a666d
[libc++] Switch XFAIL in xsgetn.buffer.pass.cpp to LLVM 23 (#212969)
We want to back-port the fix for xsgetn, so the XFAIL needs to be
updated to reflect that.
2026-07-30 14:15:45 +02: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
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
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
Hui
a41d597406
[libc++][test][NFC] remove old UNSUPPORTED clang from clear_padding.pass.cpp (#212690)
Follow up PR for comment
https://github.com/llvm/llvm-project/pull/211258/changes#r3663614103

I think I must have made an oversight while resolving a merge conflict
2026-07-29 13:54:48 +02:00
Yordan Vásquez
e062a29cf8
[libc++] Mark LWG3133 as Complete and add valarray operator[] safety tests (#208145)
This verifies that libc++ has implemented the resolution of LWG3133,
which modernizes the requirements on `T` for `std::complex<T>` and
`std::valarray<T>` in [numeric.requirements].
- No code changes were needed for `std::valarray<T>`: its `operator[]`
already indexes through a raw pointer and never relies on a
user-overloadable `operator&`, so it already conforms to the revised
wording.
- Added o`perator_hijacker`-based tests to `valarray`'s
`access.pass.cpp`/`const_access.pass.cpp`, confirming `operator[]`
doesn't rely on a user-overloadable `operator&`.
2026-07-29 17:41:55 +08:00
Louis Dionne
583a958f83
[libc++] Reduce sequence container benchmark size ladder (#212281)
The sequence containers were registered for 32, 1024 and 8192. This
patch drops the mid-size point to get roughly a 30% speedup when running
the benchmarks.
2026-07-28 12:48:45 -04:00
Louis Dionne
15b9ee4ee2
[libc++] Drop char8_t instantiation from string benchmarks (#212283)
The string benchmarks instantiated every benchmark for char, char8_t and
wchar_t. char8_t exercises the same code paths as char, so drop it to
get roughly a 30% speedup on this benchmark time.
2026-07-28 12:48:21 -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
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
A. Jiang
ac8b30c74b
[libc++][test] Suppress warning on bitwise shift with bool operands in std::byte tests for MSVC (#212433)
It was intentional in https://llvm.org/PR204116 that tests for
`operator<<`, `operator<<=`, `operator>>`, `operator>>=` used `bool`
operands, because `bool` is an integral type and thus satisfies the
constraints of these operators.

However, MSVC considers `bool` is unsafe as an operand of bitwise shift
operators and emits warning C4804. So this patch suppresses the warning
for MSVC.
2026-07-28 20:22:42 +08:00
A. Jiang
abd3b3a144
[libc++][test][NFC] Format test_macros.h (#212442)
Avoiding errors about untouched lines from clang-format when modifying
conditions in `test_macros.h`.
2026-07-28 19:42:32 +08:00
A. Jiang
3216428265
[libc++][test] Disable test coverage for _BitInt for non-libc++ implementations (#212435)
Currently, library support for `_BitInt(N)` is an extension explicitly
supported by libc++. However, when using Clang with other standard
library implementations, `TEST_HAS_BITINT` is currently `1` as the
condition only detects compiler support of `_BitInt`.

This patch disables `_BitInt` coverage for other implementations for
now.
2026-07-28 19:35:00 +08: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
Hui
0733641570
[libc++][test] re-enable clear padding runtime test (#211258) 2026-07-27 12:32:19 -04:00
Louis Dionne
a3b6e0baca
[libc++] Add benchmark for std::nth_element (#210112) 2026-07-27 12:21:45 -04:00
Louis Dionne
c060161b31
[libc++] Add benchmarks for std::min_element, std::max_element and std::ranges::max (#209590)
Extend missing coverage and increase consistency across how the
benchmarks are written.
2026-07-27 12:21:13 -04:00
Louis Dionne
d2e3e96ded
[libc++] Add benchmarks for std::next_permutation and std::prev_permutation (#210966) 2026-07-27 12:20:39 -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
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
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
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
882a138194
[libc++] Remove workaround for Clang < 20 in clang-tidy plugin (#211314)
The clang-tidy plugin is now always built with Clang >= 20, so the
workaround can be removed.
2026-07-23 09:21:44 -04:00
Nikolas Klauser
d3fead5912
[libc++] Remove some adjacent_view::begin() benchmarks (#210265)
Benchmarking a bunch of very similar values has rather little benefit,
since they behave essentially the same.
2026-07-23 10:17:24 +02: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
Hristo Hristov
045c8987ec
[libc++][NFC] Format and move transform_view's sentinel.pass.cpp (#211252)
As a pre-requisite to: https://github.com/llvm/llvm-project/pull/193891
2026-07-22 13:27:44 -04:00
Nikolas Klauser
02c51adb8f
[libc++] Remove redundant benchmarks for lexicographical_compare_three_way (#210268)
We already test the `_slow_path` and `_fast_path` functions through the
generic `BM_lexicographical_compare_three_way`. We don't need to
benchmark them again.
2026-07-22 10:16:58 -04:00
Vladimir Vereschaka
04327b1e59
Revert "[libc++][test] XFAIL text/text_encoding/environment.pass.cpp test on Armv7/Linux Ubuntu targets." (#211112)
Reverts #206188

XFAIL'ed wrong test
2026-07-22 08:37:28 -04:00
Nikolas Klauser
c23ad1b869
[libc++] Remove {Pause,Resume}Timing from fast push_back benchmarks (#209130)
These benchmarks are expected to run for a very short time, and
`{Pause,Resume}Timing` should only be used when operations are expected
to take a long time. Removing them reduces the amount of noise in these
benchmarks.

Fixes #208719
2026-07-22 10:22:00 +02:00
Lucas Mellone
53199a1b92
[libc++][ranges] Mark LWG3664 as resolved (#210550)
Closes https://github.com/llvm/llvm-project/issues/105066.

When libc++ implemented `ranges::distance` in
c965d5448e, LWG3664 was implemented
together. The patch additionally changed cast result type from `const
decay_t<I>&` to `decay_t<I>`, which partially implemented LWG4242.

Currently, we are using `iter_difference_t<_Ip>` as the return type of
one `operator()` overload while LWG3664 modified that overload to return
`iter_difference_t<decay_t<_Ip>>`. The change is NFC because when
`iter_difference_t<decay_t<_Ip>>` is valid, `iter_difference_t<_Ip>` is
also valid and denotes the same type.

References:
- https://wg21.link/LWG3664
- https://eel.is/c++draft/range.iter.op.distance

---------

Co-authored-by: A. Jiang <de34@live.cn>
2026-07-21 18:20:20 +03: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