4747 Commits

Author SHA1 Message Date
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
Hui
13f7a1fb59
[libc++] LWG 3987 provide iterator.range access from flat_{map,set} (#137524)
fixes #105309
2025-07-06 12:25:18 +01:00
Hui
9eb4fc7006
[libc++] constexpr flat_set (#140360)
Fixes #128675
2025-07-05 17:38:45 +01:00
Nikolas Klauser
ca697096aa
[libc++] Granularize <locale> (#146650) 2025-07-05 18:11:58 +02:00
David Spickett
d17a248fc6
[libcxx][test] Correct syntax of lit directives in some tests (#146886)
"XFAIL " does not do anything, you need to have the colon afterwards.
"XFAIL: ".

Found by searching for: (XFAIL|REQUIRES|UNSUPPORTED)[^:]
2025-07-04 12:48:16 +01:00
Louis Dionne
8f6a964c89
[libc++] Fix tests broken on the Buildkite CI (#146733)
The Buildkite CI was unintentionally disabled for a few weeks. This
patch fixes the
CI jobs now that is has been re-enabled.
2025-07-04 11:03:18 +02:00
Eric Fiselier
01d0171e7a Address formatting mistake in libc++ test 2025-06-30 13:53:24 -04:00
Eric
4aaab69314
[libc++] Fix wait_on_destruct.pass.cpp hanging sometimes (#146240)
This test was deadlocking on my machine. 

It seems to me the intention of `in_async.wait(...)` was to wait for the
value to be set to true, which requires a call of `wait(false)` (waits
if value matches argument).

~As a drive by change scoped_lock to unique_lock, since there shouldn't
be any functional difference between the two in this test.~

I've addressed the issues with the `in_async` by switching to a
condition variable instead, since my first attempt at fixing this with
`in_async` wasn't sufficient.
2025-06-30 11:54:12 -04:00
Hristo Hristov
267945b665
[libc++][NFC] Refactored equality comparisons tests for pair and expected (#145668)
Refactored `std::expected` and `std::pair` tests to use the
canonicalized names from `test_comparisions.h`, which are shared between
tests.

This was split from https://github.com/llvm/llvm-project/pull/139368 as
per comment
https://github.com/llvm/llvm-project/pull/139368#pullrequestreview-2916040573

Towards implementing [P2944R3: Comparisons for
reference_wrapper](https://github.com/llvm/llvm-project/issues/105424)

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-06-29 16:34:49 +03:00
Hui
34b2e934ea
[libc++] Introduce __product_iterator_traits and optimise flat_map::insert (#139454)
Fixes #108624

This allows `flat_map::insert(Iter, Iter)` to directly forward to
underlying containers' `insert(Iter, Iter)`, instead of inserting one
element at a time, when input models "product iterator". atm,
`flat_map::iterator` and `zip_view::iterator` are "product iterator"s.

This gives about almost 10x speed up in my benchmark with -03 (for both
before and after)

```cpp
Benchmark                                                          Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------
flat_map::insert_product_iterator_flat_map/32                   -0.5028         -0.5320           149            74           149            70
flat_map::insert_product_iterator_flat_map/1024                 -0.8617         -0.8618          3113           430          3112           430
flat_map::insert_product_iterator_flat_map/8192                 -0.8877         -0.8877         26682          2995         26679          2995
flat_map::insert_product_iterator_flat_map/65536                -0.8769         -0.8769        226235         27844        226221         27841
flat_map::insert_product_iterator_zip/32                        -0.5844         -0.5844           162            67           162            67
flat_map::insert_product_iterator_zip/1024                      -0.8754         -0.8754          3427           427          3427           427
flat_map::insert_product_iterator_zip/8192                      -0.8934         -0.8934         28134          3000         28132          3000
flat_map::insert_product_iterator_zip/65536                     -0.8783         -0.8783        229783         27960        229767         27958
OVERALL_GEOMEAN                                                 -0.8319         -0.8332             0             0             0             0
```

---------

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2025-06-28 13:42:50 +01:00
Hristo Hristov
a19d37044b
[libc++] P2944R3: Constrained comparisions - tuple (#145677)
Implements P2944R3 partially, which adds constrained comparisons
`std::tuple`.
The missing overloads introduced in [P2165R4](https://wg21.link/P2165R4)
are not implemented.

Uses
[`__all`](f7af33a9eb/libcxx/include/__type_traits/conjunction.h (L45))
instead of a fold expression, see comment:
https://github.com/llvm/llvm-project/pull/141396#discussion_r2161166077

Relates to #136765

# References

[tuple.rel](https://wg21.link//tuple.rel)
2025-06-27 20:12:18 +03:00
Nikolas Klauser
4c8fab399b
[libc++] Avoid type-punning between __hash_value_type and pair (#143501)
This patch is very similar to #134819 in nature. Before this patch, we
were dereferencing pointers to objects which were never constructed. Now
we always assume that nodes store `pair<const KeyT, ValueT>` for
unordered_maps instead, as they actually do.
2025-06-26 19:43:59 +02:00
Qinkun Bao
04b60d29ba Disable HWSan for thread_creae_failure.pass.
See https://github.com/llvm/llvm-project/pull/130145
2025-06-26 15:41:31 +00:00
Qinkun Bao
06a4394b50 Disable HWSan for thread_creae_failure.pass.
See https://github.com/llvm/llvm-project/pull/130145
2025-06-26 14:49:12 +00:00
Nikolas Klauser
0905767610 [libc++] Address remaining comments from #130145
I've accidentally merged the PR before addressing all
comments. This patch fixes the remaining ones.
2025-06-26 12:34:19 +02:00
Nikolas Klauser
696c0f92e0
[libc++] Don't try to wait on a thread that hasn't started in std::async, take 2 (#130145)
If the creation of a thread fails, this causes an idle loop that will
never end because the thread wasn't started in the first place.

This also adds a test for the regression reported in #125433 to make
sure we're not reintroducing it later.

Fixes #125428
2025-06-26 12:13:19 +02:00
Hristo Hristov
f2f4b557aa
[libc++] P2944R3: Constrained comparisions - variant (#141396)
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-25 12:12:23 +03:00
Hui
0b8f3cc6b7
[libc++] Fix no-localisation CI failure on <complex> (#145213) 2025-06-24 13:56:17 -04:00
Peng Liu
d80766152c
[libc++] Fix bitset conversion functions and refactor constructor (#121348)
This patch addresses several implementation issues in `bitset`'s
conversion functions `to_ullong` and `to_ulong`, and refactors its
converting constructor `__bitset(unsigned long long __v)` to a more
generic and elegant implementation.
2025-06-24 12:38:10 -04:00
Hui
831fcb5e91
[libc++] constexpr flat_map (#137453)
Fixes #128673
2025-06-21 13:41:32 +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
Hristo Hristov
945ce1aa3d
[libc++] Update the value of __cpp_lib_constrained_equality after P3379R0 (#144553)
https://wg21.link/P3379R0 updated the value of __cpp_lib_constrained_equality,
but we forgot to update it when we implemented the paper.
2025-06-20 12:36:46 -04:00
Nikolas Klauser
20245bbf66 [libc++][NFC] Format abs.pass.cpp test
I will modify the test in an upcoming PR. I'm formatting it now to avoid
a bunch of whitespace changes in that PR.
2025-06-19 10:41:12 +02:00
Nikolas Klauser
584cc37687
[libc++] Move std::abs into __math/abs.h (#139586)
`template <class = int>` is also added to our implementations to avoid
an ambiguity between the libc's version and our version when both are
visible.

This avoids including `<stdlib.h>` in `<math.h>`.
2025-06-19 10:37:18 +02:00
S. B. Tam
a9a71b6d31
[libc++][test] Don't pass ill-formed UTF-8 to MAKE_STRING_VIEW (#136403) 2025-06-19 15:21:28 +08:00
Peng Liu
9827440f1e
[libc++] Optimize ranges::{for_each, for_each_n} for segmented iterators (#132896)
Previously, the segmented iterator optimization was limited to `std::{for_each, for_each_n}`. This patch
extends the optimization to `std::ranges::for_each` and `std::ranges::for_each_n`, ensuring consistent
optimizations across these algorithms. This patch first generalizes the `std` algorithms by introducing
a `Projection` parameter, which is set to `__identity` for the `std` algorithms. Then we let the `ranges`
algorithms to directly call their `std` counterparts with a general `__proj` argument. Benchmarks
demonstrate performance improvements of up to 21.4x for ``std::deque::iterator`` and 22.3x for
``join_view`` of ``vector<vector<char>>``.

Addresses a subtask of #102817.
2025-06-18 12:22:47 -04: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
Louis Dionne
8d1610afd0 [libc++] Mark two assertion tests as unsupported in C++03 mode
Our assertion checking facility requires at least C++11, so these
tests were failing when run in C++03 mode.
2025-06-17 16:51:35 -04:00
Hristo Hristov
a0c00ccd5f
[libc++] P2944R3: Constrained comparisons - update reference_wrapper implementation (#139368)
Updates the implementation `std::reference_wrapper` -
[P2944R3](https://wg21.link/P2944R3) as discussed in
https://github.com/llvm/llvm-project/pull/117664#discussion_r1857826166
This PR also refactors the tests in preparation to implements the
constrained comparisons for `optional`, `variant` etc.

- Moves the test helpers (concepts and types) for testing constrained
comparisons to `test_comparisons.h`.
- Updates the `std::reference_wrapper` implementation to use the concept
`__core_convertible_to<bool>` as per comments in #135759.

Closes #138233

# References:
- [refwrap.comparisons](https://wg21.link/refwrap.comparisons)

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-06-15 07:45:48 +03:00
A. Jiang
bba4ded3c2
[libc++] Fix constructing bitset from non-null-terminated arrays (#143691)
Unconditional evaluation of `char_traits<_CharT>::length(__str)` is problematic, because it causes
UB when `__str` points to a non-null-terminated array. We should only call `length` (currently, in
`basic_string_view`'s constructor) when `__n == npos` per [bitset.cons]/8.

Drive-by change: Reduction of conditional compilation, given that
- both `basic_string_view<_CharT>::size_type` and `basic_string<_CharT>::size_type` must be 
  `size_t`, and thus
- both `basic_string_view<_CharT>::npos` and `basic_string<_CharT>::npos` must be `size_t(-1)`.

For the type sameness in the standard wording, see:
- [string.view.template.general]
- [basic.string.general]
- [allocator.traits.types]/6
- [default.allocator.general]/1

Fixes #143684
2025-06-12 10:53:41 -04:00
Nikolas Klauser
42c82fcc29
[libc++] Upgrade to GCC 15 (#138293) 2025-06-11 20:19:26 +02:00
Peng Liu
38fb0117ab
[libc++] Make forward_list constexpr as part of P3372R3 (#129435)
Fixes #128658
2025-06-11 12:13:36 -04:00
maflcko
a17e97e677
[libc++] Add missing C++20 [time.point.arithmetic] (#143165)
This was part of https://wg21.link/p0355r7, but apparently never
implemented.

---------

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Co-authored-by: Hristo Hristov <zingam@outlook.com>
2025-06-11 08:43:23 +02:00
Louis Dionne
616f83530f
[libc++] Move swap test to a .compile.pass.cpp (#143167) 2025-06-10 15:22:42 -04:00
Aiden Grossman
20a6b63f1b
[libcxx] Include __fwd/span.h in <mdspan>
This patch includes __fwd/span.h in <mdspan> so that we get the
declaration of dynamic_extent inside <mdspan>. We also clean up quite a
few tests that were manually included <span> for dynamic_extent.

This is based on feedback from #142693.

Reviewers: philnik777, ldionne

Reviewed By: philnik777

Pull Request: https://github.com/llvm/llvm-project/pull/142925
2025-06-08 21:58:36 +00:00
Hui
692c5cdb56
[libc++] Do not call reserve in flat containers if underlying container is user defined (#140379)
This is brought up in the LWG reflector. We currently call `reserve` if
the underlying container has one. But the spec does not specify what
`reserve` should do for Sequence Container. So in theory if the
underlying container is user defined type and it can have a function
called `reserve` which does something completely different.

The fix is to just call `reserve` for STL containers if it has one
2025-06-07 08:47:46 +01:00
Hui
155fd97a66
[libc++] flat_meow transparent comparator string literals (#133654)
See discussion in https://cplusplus.github.io/LWG/issue4239

    std::flat_map<std::string, int, std::less<>> m;
    m.try_emplace("abc", 5);  // hard error

The reason is that we specify in 23.6.8.7 [flat.map.modifiers]/p21
the effect to be as if `ranges::upper_bound` is called.

`ranges::upper_bound` requires indirect_strict_weak_order, which
requires the comparator to be invocable for all combinations. In this
case, it requires

    const char (&)[4] < const char (&)[4]

to be well-formed, which is no longer the case in C++26 after
https://wg21.link/P2865R6.

This patch uses `std::upper_bound` instead.
2025-06-06 13:05:36 -04:00
A. Jiang
479f992291
[libc++] Fix basic_string::shrink_to_fit for constant evaluation (#142712)
Currently, when the string shrink into the SSO buffer, the `__rep_.__s`
member isn't activated before the `traits_type::copy` call
yet, so internal `__builtin_memmove` call writing to the buffer causes
constant evaluation failure. The existing test coverage seems a bit
defective and doesn't cover this case - `shrink_to_fit` is called on the
copy of string after erasure, not the original string object.

This PR reorders the `__set_short_size` call, which starts the lifetime
of the SSO buffer, before the copy operation. Test coverage is achieved
by calling `shrink_to_fit` on the original erased string.
2025-06-05 07:23:49 +08:00
Peng Liu
ec5610c4a2
[libc++] Ensure strong exception guarantee for forward_list::resize (#131025)
The current implementation of `forward_list::resize` does not meet the
strong exception safety guarantee required by [forward.list.modifiers]:

    If an exception is thrown by any of these member functions there is no
    effect on the container.

This patch refactors `resize()` to provide strong exception safety and
introduces additional tests to validate the strong exception guarantees
for other `forward_list` modifiers.

Fixes #118366.
2025-06-04 13:04:19 -04:00
A. Jiang
fdb11c1be6
[libc++] Disallow specializing common_reference (#141465)
`common_reference` isn't an exception for [meta.rqmts]/4, so it's better
to disallow users to specialize it.

`indirectly_readable.compile.pass.cpp` was a bit problematic. It
attempted to opt-out common reference type in some wrong ways. Also, the
standard effectively forbids opting-out common reference type for `T&`
and `T&&`. This patch removes and adjusts some problematic cases.

---------

Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-06-04 20:41:58 +08: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
Louis Dionne
d0fb83531b
[libc++] Remove invalid char_traits instantiations from a test (#142016)
We had a test which created invalid char_traits instantiations for
non-character types. This patch removes them.
2025-06-03 11:58:42 -04:00
A. Jiang
769c42f4a5
[libc++] Fix padding calculation for function reference types (#142125)
#109028 caused `sizeof` to be sometimes applied to function reference
types, which makes a program ill-formed. This PR handles reference types
by specializations to prevent such bogus `sizeof` expression to be
instantiated.

Fixes #142118.
2025-06-03 11:54:49 -04:00
A. Jiang
437ad06f76
[libc++] Use __reference_constructs_from_temporary if eligible (#141916)
Currently, libc++'s `<tuple>` is using the deprecated
`__reference_binds_to_temporary` intrinsic. This PR starts to use
`__reference_constructs_from_temporary` if possible.

It seems that `__reference_constructs_from_temporary` should be used via
an internal type traits provided in
`<__type_traits/reference_constructs_from_temporary.h>`. But given the
old intrinsic was directly used, this PR doesn't switch to the current
convention yet.

P2255R2 is related. Although the paper indicated that constructors of
`tuple` should be deleted in such a case.

---------

Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
2025-06-03 10:34:45 +08:00
Ksar
b71255705b
[libc++] P2165R4: Update deduction guides for map containers and container adaptors (#136011)
Fixes #135351

This PR update CATD guides to associative containers (`std::map`,
`std::multimap`, `std::unordered_map`, `std::unordered_multimap`,
`std::flat_map`, `std::flat_multimap`).

- Updated template alias for deduction guides for the relevant
associative containers.
- Added a new test to verify the deduction guides with `std::map`,
`std::multimap`, `std::unordered_map`, `std::unordered_multimap`,
`std::flat_map`, `std::flat_multimap`.
2025-05-30 15:17:06 +08:00
Martin Storsjö
74a102fc1c
[libcxx] [test] Change an MSVC mode XFAIL into UNSUPPORTED (#141609)
The underlying bug in vcruntime [1] has been fixed in the latest version
of MSVC (released two weeks ago); this will cause the test which is
currently marked XFAIL to start erroring, when it starts passing
unexpectedly.

This version of MSVC may soon start appearing in the Github Actions
runner images used for our CI.

We could try to detect the state of this bug, but in practice, such
detection code would essentially be a copy of this whole test.

Therefore, just mark this test UNSUPPORTED for the MSVC mode builds. If
we at some point require new enough MSVC libraries, we could remove the
marking entirely.

[1]
https://developercommunity.visualstudio.com/t/vcruntime-nothrow-array-operator-new-fal/10373274
2025-05-28 09:21:30 +03:00
Martin Storsjö
cd7104eb87
[libcxx] [test] Extend mingw target checks to cover the arm64ec architecture too (#141227) 2025-05-23 19:13:51 +03:00
Peng Liu
09c266b75d
[libc++] Optimize std::for_each_n for segmented iterators (#135468)
This patch enhances the performance of `std::for_each_n` when used with
segmented iterators, leading to significant performance improvements,
summarized in the tables below. This addresses a subtask of
https://github.com/llvm/llvm-project/issues/102817.
2025-05-21 12:10:50 -04:00
Nikolas Klauser
3a86e0bd29
[libc++] Optimize std::getline (#121346)
```
-----------------------------------------------
Benchmark                   old             new
-----------------------------------------------
BM_getline_string        318 ns         32.4 ns
```
2025-05-19 10:59:36 +02:00
Nikolas Klauser
f6867709a7
[libc++] Fix set::operator= when instantiating with a std::pair (#140385)
This has been introduced by #134819, most likely due to a merge conflict
I didn't resolve properly (I thought I did in that patch what I'm now
doing here).
2025-05-18 12:40:34 +02:00