1398 Commits

Author SHA1 Message Date
David Benjamin
bcf9fb9802
[libc++][hardening] Use bounded iterators in std::vector and std::string (#78929)
~~NB: This PR depends on #78876. Ignore the first commit when reviewing,
and don't merge it until #78876 is resolved. When/if #78876 lands, I'll
clean this up.~~

This partially restores parity with the old, since removed debug build.
We now can re-enable a bunch of the disabled tests. Some things of note:

- `bounded_iter`'s converting constructor has never worked. It needs a
friend declaration to access the other `bound_iter` instantiation's
private fields.

- The old debug iterators also checked that callers did not try to
compare iterators from different objects. `bounded_iter` does not
currently do this, so I've left those disabled. However, I think we
probably should add those. See
https://github.com/llvm/llvm-project/issues/78771#issuecomment-1902999181

- The `std::vector` iterators are bounded up to capacity, not size. This
makes for a weaker safety check. This is because the STL promises not to
invalidate iterators when appending up to the capacity. Since we cannot
retroactively update all the iterators on `push_back()`, I've instead
sized it to the capacity. This is not as good, but at least will stop
the iterator from going off the end of the buffer.

There was also no test for this, so I've added one in the `std`
directory.

- `std::string` has two ambiguities to deal with. First, I opted not to
size it against the capacity. https://eel.is/c++draft/string.require#4
says iterators are invalidated on an non-const operation. Second,
whether the iterator can reach the NUL terminator. The previous debug
tests and the special-case in https://eel.is/c++draft/string.access#2
suggest no. If either of these causes widespread problems, I figure we
can revisit.

- `resize_and_overwrite.pass.cpp` assumed `std::string`'s iterator
supported `s.begin().base()`, but I see no promise of this in the
standard. GCC also doesn't support this. I fixed the test to use
`std::to_address`.

- `alignof.compile.pass.cpp`'s pointer isn't enough of a real pointer.
(It needs to satisfy `NullablePointer`, `LegacyRandomAccessIterator`,
and `LegacyContiguousIterator`.) `__bounded_iter` seems to instantiate
enough to notice. I've added a few more bits to satisfy it.

Fixes #78805
2024-07-22 22:44:25 -07:00
nicole mazzuca
4189226236
[libc++] Update some C++23 statuses to "Nothing to do" or "Complete" (#99621)
- [P2160R1][] "Locks lock lockables"
- [P2212R2][] "Relax Requirements for `time_point::clock`"
- [P1675R2][] "`rethrow_exception` must be allowed to copy"
- [P2340R1][] "Clarifying the status of the 'C headers'"
- [P2460R2][] "Relax requirements on `wchar_t` to match existing
practices"

Are all papers that change wording without changing implementation
behaviour.

Additionally, [P2736R2][] "Referencing The Unicode Standard", is an
already complete paper in 19.0 (as of [LLVM-86543][])

[P2160R1]: https://wg21.link/p2160r1
[P2212R2]: https://wg21.link/p2212r2
[P1675R2]: https://wg21.link/p1675r2
[P2340R1]: https://wg21.link/p2340r1
[P2460R2]: https://wg21.link/p2460r2
[P2736R2]: https://wg21.link/p2736r2
[LLVM-86543]: https://github.com/llvm/llvm-project/pull/86543
2024-07-22 18:33:41 +02:00
Xiaoyang Liu
3d7622ea0b
[libc++][ranges] LWG3618: Unnecessary iter_move for transform_view::iterator (#91809)
## Introduction

This patch implements LWG3618: Unnecessary `iter_move` for
`transform_view::iterator`.

`transform_view`'s iterator currently specifies a customization point
for `iter_move`. This customization point does the same thing that the
default implementation would do, but its sole purpose is to ensure the
appropriate conditional `noexcept` specification.

## Reference

-
[[range.transform.iterator]](https://eel.is/c++draft/range.transform.iterator)
- [LWG3618](https://cplusplus.github.io/LWG/issue3618)
2024-07-22 18:32:37 +02:00
Mark de Wever
14ec4746cc
[libc++] Makes `unique_ptr operator*() noexcept. (#98047)
This implements
 - LWG2762  unique_ptr operator*() should be noexcept.

Differential Revision: https://reviews.llvm.org/D128214
2024-07-21 13:06:02 +02:00
Mark de Wever
afbfb16d29
[libc++][TZDB] Implements zoned_time formatters. (#98347)
Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
- P1361 Integration of chrono with text formatting
- P2372 Fixing locale handling in chrono formatters
2024-07-20 19:24:41 +02:00
PaulXiCao
af0d731b12
[libc++][math] Mathematical Special Functions: Hermite Polynomial (#89982)
Implementing the Hermite polynomials which are part of C++17's
mathematical special functions. The goal is to get early feedback which
will make implementing the other functions easier. Integration of
functions in chunks (e.g. `std::hermite` at first, then `std::laguerre`,
etc.) might make sense as well (also see note on boost.math below).

I started out from this abandoned merge request:
https://reviews.llvm.org/D58876 .

The C++23 standard defines them in-terms of `/* floating-point type */`
arguments. I have not looked into that.

Note, there is still an ongoing discussion on discourse whether
importing boost.math is an option.
2024-07-20 17:50:05 +02:00
nicole mazzuca
04760bfadb
[libc++][ranges] P1223R5: find_last (#99312)
Implements [P1223R5][] completely.

Includes an implementation of `find_last`, `find_last_if`, and
`find_last_if_not`.

[P1223R5]: https://wg21.link/p1223r5
2024-07-19 09:42:16 -07:00
Louis Dionne
da44c0695c
[libc++][docs] Add tip for developers running the test suite on macOS (#99544) 2024-07-19 11:46:35 -04:00
Hristo Hristov
e475bb7ac3
[libc++][memory] P1132R8: out_ptr - a scalable output pointer abstraction (#73618)
Differential Revision: https://reviews.llvm.org/D150525

Implements:
- https://wg21.link/P1132R8 - `out_ptr` - a scalable output pointer
abstraction
- https://eel.is/c++draft/smartptr.adapt - 20.3.4 Smart pointer adaptors
- https://wg21.link/LWG3734 - Inconsistency in `inout_ptr` and `out_ptr`
for empty case
- https://wg21.link/LWG3897- `inout_ptr` will not update raw pointer to
0

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-07-19 06:38:02 +03:00
Iuri Chaer
a0662176a9
[libc++] Speed up set_intersection() by fast-forwarding over ranges of non-matching elements with one-sided binary search. (#75230)
One-sided binary search, aka meta binary search, has been in the public
domain for decades, and has the general advantage of being constant time
in the best case, with the downside of executing at most 2*log(N)
comparisons vs classic binary search's exact log(N). There are two
scenarios in which it really shines: the first one is when operating
over non-random-access iterators, because the classic algorithm requires
knowing the container's size upfront, which adds N iterator increments
to the complexity. The second one is when traversing the container in
order, trying to fast-forward to the next value: in that case the
classic algorithm requires at least O(N*log(N)) comparisons and, for
non-random-access iterators, O(N^2) iterator increments, whereas the
one-sided version will yield O(N) operations on both counts, with a
best-case of O(log(N)) comparisons which is very common in practice.
2024-07-18 16:11:24 -04:00
Nikolas Klauser
0ce11a1a76
[libc++] Add a release note about C++03 being frozen after LLVM 21 (#95894)
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-07-18 18:04:19 +02:00
A. Jiang
684a61506a
[libc++][chrono] Remove non-standard relational operators for std::chrono::weekday (#98730)
These operators are absent in https://eel.is/c++draft/time.syn and a note in
https://eel.is/c++draft/time.cal.wd.overview#1 indicates that the absence is 
intended.

This patch removes the undocumented extension, while providing a migration path
for vendors by providing the `_LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS`
macro. This macro will be honored for the LLVM 19 release and will be removed after 
that, at which point allocator will be removed unconditionally.
2024-07-18 09:58:35 -04:00
Hristo Hristov
cb3de24b5c
[libc++][iterator][ranges] P2997R1: Removing the common reference requirement from the indirectly invocable concepts (#98817)
Implements as DR against C++20: https://wg21.link/P2997R1

References:
- https://eel.is/c++draft/indirectcallable.indirectinvocable
- https://eel.is/c++draft/version.syn#header:%3cversion%3e

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-07-18 14:54:29 +03:00
Hristo Hristov
4a19be5d45
[libc++][strings] P2591R5: Concatenation of strings and string views (#88389)
Implemented: https://wg21.link/P2591R5
- https://eel.is/c++draft/string.syn
- https://eel.is/c++draft/string.op.plus

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-07-18 13:26:37 +03:00
Louis Dionne
81955da03b
[libc++] Remove special handling of the native C++ library in benchmarks (#98529)
There were some ad-hoc settings that allowed running the benchmarks
against the native C++ Standard Library. While this ability is very
useful, it was done before the test suite was quite independent of
libc++ itself. Instead, it is better to streamline running the
benchmarks on the native standard library by using a custom Lit
configuration like we do with the test suite.

A follow-up patch will rework the integration of benchmarks with the Lit
configuration used for the test suite so that we can reuse the same
mechanism for both, making it easy to benchmark the native standard
library.

It will also make benchmarks way more user-friendly to run since we will
be able to run them like we run individual tests, which is a pain point
right now.
2024-07-17 13:20:48 -04:00
Mark de Wever
136737d947
[libc++] Deprecates rel_ops. (#91642)
These operators were deprecated in
  P0768R1 Library Support for the Spaceship (Comparison) Operator

This was discovered while investigating the paper's implementation
status.
2024-07-17 18:21:36 +02:00
Hristo Hristov
60b6f43ea1
[libc++][ranges] LWG4001: iota_view should provide empty (#79687)
Implements: https://wg21.link/LWG4001
- https://eel.is/c++draft/range.iota.view

---------

Co-authored-by: Zingam <zingam@outlook.com>
Co-authored-by: Will Hawkins <whh8b@obs.cr>
2024-07-17 18:10:17 +03:00
Hristo Hristov
8ba9ed6825
[libc++][ranges] LWG4035: single_view should provide empty (#98371)
Implements: https://wg21.link/LWG4035

- https://eel.is/c++draft/range.single.view
2024-07-16 18:13:05 +03:00
Xiaoyang Liu
4e338dce4d
[libc++] P2389R2: dextents Index Type Parameter (#97393)
This patch implements P2389R2, which was adopted at the St. Louis meeting.
It builds upon previous enhancements from P2299R3, which introduced deduction
guides and the `dextents` alias template.
2024-07-15 11:23:34 -04:00
Louis Dionne
ef51e617c4
[libc++] Handle _LIBCPP_HAS_NO_{THREADS,LOCALIZATION} consistently with other carve-outs (#98319)
Previously, we would issue an #error when using a header that requires
threading support or localization support in a configuration where that
is disabled. This is unlike what we do for all the other carve outs like
no-filesystem, no-wide-characters or no-random-device. Instead of
issuing an #error, we normally just remove the problematic parts of the
header.

This patch makes the handling of no-localization and no-threads
consistent with the other carve-outs. I dislike the fact that users
won't get an explicit error message when trying to use e.g. ios in a
build that doesn't support localization, but I think it is better to
handle things consistently. Note that besides the consistency argument,
the #error approach doesn't really work anyways since it would break
down if we moved towards assuming the C locale only in the
no-localization mode.
2024-07-15 10:11:23 -04:00
A. Jiang
ef8207b579
[libc++][docs] LWG3380 made the status of P1614R2 in [meta.trans.other] "Nothing To Do" (#98636)
The changes of https://wg21.link/p1614r2 in [meta.trans.other]
were exactly reverted by https://wg21.link/LWG3380.
2024-07-12 16:12:31 -04:00
Louis Dionne
9bd575dd60
[libc++] Deprecate _LIBCPP_ENABLE_ASSERTIONS & friends (#98364)
In LLVM 19, the old xxx_ENABLE_ASSERTIONS settings should be deprecated
with the goal of removing them entirely in LLVM 20.
2024-07-12 16:07:12 -04:00
Hristo Hristov
31c9c41873
[libc++][tuple][utility] P2968R2: Make std::ignore a first-class object (#97401)
Implements:  https://wg21.link/P2968R2

References:
- https://eel.is/c++draft/tuple.general
- https://eel.is/c++draft/tuple.syn
- https://eel.is/c++draft/tuple.creation
- https://github.com/cplusplus/draft/milestone/31
- https://github.com/cplusplus/draft/pull/7109
- https://github.com/cplusplus/papers/issues/1640
- https://cplusplus.github.io/LWG/issue2933
- https://cplusplus.github.io/LWG/issue3978

---------

Co-authored-by: Hristo Hristov <zingam@outlook.com>
2024-07-11 00:05:23 +03:00
Louis Dionne
45bc85603a [libc++][NFC] Add missing upcoming removal to 19 release notes
This upcoming removal was recorded in the release notes for LLVM 19
as part of the deprecation of the C++20 synchronization library in
pre-C++20 modes, but wasn't included in "Upcoming Deprecations and Removals".
2024-07-10 14:10:30 -04:00
Louis Dionne
33af4bd7a4
[libc++] Add empty release notes file for LLVM 20 (#98355)
While we haven't branched yet, this will make it easier for folks to add
release notes for PRs that won't be merged before the LLVM 19 branch
point.
2024-07-10 14:08:27 -04:00
Mark de Wever
deeb936863
[libc++][format] define __cpp_lib_format. (#98275)
In order to define the format __cpp_lib_format to its initial value
(201907) these papers need to be completed:
- P0645R10 Text Formatting
- P1652R1 Printf corner cases in std::format
- 1361R2 Integration of chrono with text formatting The first two have
been implemented for a while the latter is almost done.

The next value (202106) requires:
- P2216R3 std::format improvements which has been implemented

The next value (202110) requires:
- P2418R2 Add support for std::generator-like types to std::format
- P2372R3 Fixing locale handling in chrono formatters The first one has
been implemented for a while the latter is almost done. The latter paper
is a DR against 1361R2 and both are implemented at the same time.

We've had user feedback that the missing of the __cpp_lib_format makes
their lives harder (https://github.com/llvm/llvm-project/issues/77773).
The missing papers 1361R2 and P2372R3 are very close to completion and
might completed before LLVM-19, but it will be a close call. This has
been discussed in the monthly libc++ meeting and we decided to set the
__cpp_lib_format so it will be set in LLVM-19.

Based on the discussion and the implementation status the
__cpp_lib_format is set to 202110.

Fixes #77773
2024-07-10 17:52:43 +02:00
Mark de Wever
2b1b4e3025
[libc++][TZDB] Implements zoned_time's operator==. (#95140)
Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
- P1614R2 The Mothership has Landed
2024-07-10 16:06:29 +02:00
Mark de Wever
e77b295ada
[libc++][TZDB] Adds zoned_time deduction guides. (#95139)
Completes
- LWG3232 Inconsistency in zoned_time  deduction guides
- LWG3294 zoned_time  deduction guides misinterprets stringchar*

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
2024-07-10 13:46:56 +02:00
h-vetinari
a37c35e807
[libc++] mark P0154 as implemented; fix column alignment issues (#97865)
AFAIU, P0154 support is complete as of
https://github.com/llvm/llvm-project/pull/89446
2024-07-10 08:31:07 +02:00
Mark de Wever
a1d73ace13
[libc++][TZDB] Finishes zoned_time constructors. (#95010)
Completes
- LWG3225 zoned_time converting constructor shall not be noexcept
- LWG3226 zoned_time constructor from string_view should accept
zoned_time<Duration2, TimeZonePtr2>

Implements parts of:
- P0355 Extending to chrono Calendars and Time Zones
2024-07-09 20:15:49 +02:00
Mark de Wever
dda4184808
[libc++][TZDB] Adds basics of zoned_time class. (#94999)
This implements the class, its non-templated constructors and its
getters to verify the construction.

Completes
- LWG3224 zoned_time constructor from TimeZonePtr does not specify
initialization of tp_

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-07-09 20:14:40 +02:00
Louis Dionne
e42f760b65
[libc++] Define the __cpp_lib_atomic_ref feature test macro (#98081)
We forgot to enable it when we landed std::atomic_ref in 42ba740aff.
2024-07-09 11:08:29 -04:00
A. Jiang
ca055bbec7
[libc++][format] LWG4061: Should std::basic_format_context be default-constructible/copyable/movable? (#97251)
See [LWG4061](https://cplusplus.github.io/LWG/issue4061) and
[P3341R0](https://wg21.link/p3341r0). Effectively reverts commit
36ce0c3b1e581ca310ae7d0cbc6af002cc5d0251.


`libcxx/test/std/utilities/format/format.functions/bug_81590.compile.pass.cpp`
has a `format` function that unexpectedly takes the
`basic_format_context` by value, which is made ill-formed by LWG4061.
This PR changes the function to take the context by reference.
2024-07-09 12:23:50 +02:00
A. Jiang
96c9913332
[libc++][format] LWG4106: basic_format_args should not be default-constructible (#97250)
See [LWG4106](https://cplusplus.github.io/LWG/issue4106) and
[P3341R0](https://wg21.link/p3341r0).

The test coverage for the empty state of `basic_format_args` in
`get.pass.cpp` is to be completely removed, because the
non-default-constructibility is covered in `ctor.pass.cpp`.
2024-07-09 12:21:30 +02:00
Mark de Wever
2dadf8d7f5
[libc++] Update status after the St. Louis meeting. (#97951)
This updates:
- The status tables
- Feature test macros
- New headers for modules
2024-07-08 19:35:31 +02:00
Nikolas Klauser
9e9404387d
[libc++] Remove annotations for GCC 13 and update the documentation (#97744)
GCC 14 has been released a while ago. We've updated the CI to use GCC 14
now. This removes any old annotations in the tests and updates the
documentation to reflect the updated version requirements.
2024-07-06 16:52:45 +02:00
Mark de Wever
093ddac68c
[libc++][chrono] Fixes leap seconds. (#90070)
While implementing the UTC clock it turns out that the implementation of
the leap seconds was not correct, it should store the individual value,
not the sum.

It also looks like LWG3359 has not been fully implemented.

Implements parts of:
- LWG3359 <chrono> leap second support should allow for negative leap
seconds
2024-07-04 20:45:15 +02:00
David Spickett
1e6d5ded35 [libcxx][Docs] Correct link syntax in hardening docs 2024-07-01 08:08:42 +01:00
Hui
eaae63d8e1
"[libc++] Try again LWG3233 Broken requirements for shared_ptr converting constructors" (#96103)
Try it again. Use the approach suggested by Tim in the LWG thread :
using function default argument SFINAE

- Revert "[libc++] Revert LWG3233 Broken requirements for shared_ptr
converting constructors (#93071)"
- Revert "[libc++] Revert temporary attempt to implement LWG 4110
(#95263)"
- test for default_delete
- Revert "Revert "[libc++] Revert temporary attempt to implement LWG
4110 (#95263)""
- test for NULL
2024-06-26 07:47:39 +01:00
Louis Dionne
eb12d9b5cb
[libc++] Remove the allocator<const T> extension (#96319)
This effort has quite a history:
- This was first attempted in 2022 via bed3240bf7d1, which broke
std::shared_ptr<T const> and caused the change to be reverted in
9138666f5464.
- We then re-attempted landing the change in 276ca87382b8 after fixing
std::shared_ptr, but reports were made that this broke code en masse
within Google. This led to the patch being reverted again in
a54d028895c9 with the goal to land this again with a migration path for
vendors.

This patch re-lands the removal while providing a migration path for
vendors by providing the `_LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST` macro.
This macro will be honored for the LLVM 19 release and will be removed
after that, at which point allocator<const T> will be removed
unconditionally.

Fixes #73665
2024-06-25 09:19:55 -05:00
ZhangYin
6ec1ddfd72
[libc++] <experimental/simd> Add swap functions of simd reference (#86478) 2024-06-23 12:51:02 +08:00
Nikolas Klauser
1ba8ed0cd7
[libc++] Mark more types as trivially relocatable (#89724)
Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2024-06-17 13:09:04 +02:00
Louis Dionne
e7d563501f [libc++] Revert LWG3223 Broken requirements for shared_ptr converting constructors (#93071)
This reverts commit d868f0970, which was shown to break some code and we
don't know yet whether the code should be valid or not. Reverting until
we've had time to figure it out next week.
2024-06-14 14:41:47 -04:00
Louis Dionne
a66e2a1988
[libc++] Revert temporary attempt to implement LWG 4110 (#95263)
When I filed LWG4110 after the discussion in #93071, I thought it was
going to be a straightforward fix. It turns out that it isn't, so we
should stay in the state where libc++ is Standards conforming even if
that state leads to some reasonable code being rejected by the library.
Once WG21 figures out what to do with this issue and votes on it, we'll
implement it through our normal means.

This reverts f638f7b6a7c2 and 16f2aa1a2ddf.
2024-06-14 14:34:56 -04:00
Mark de Wever
759fb590da
[libc++][modules] Mark as implemented. (#90091)
The feature has been implemented in LLVM 18 as an experimental feature.
This marks the paper as complete and sets the feature-test macro.

Implements
- P2465R3 Standard Library Modules std and std.compat

Fixes: https://github.com/llvm/llvm-project/issues/89579
2024-06-12 19:01:27 +02:00
Mark de Wever
c36961bd96
[libc++] Adds __cpp_lib_three_way_comparison FTM. (#91515)
The paper
  P0768R1 Library Support for the Spaceship (Comparison) Operator
did not add a feature-test macro. This omission has been corrected in
  P1353R0 Missing Feature Test Macros

This enables the FTM for P0768R1

Fixes: https://github.com/llvm/llvm-project/issues/73953

---------

Co-authored-by: S. B. Tam <cpplearner@outlook.com>
2024-06-12 18:59:21 +02:00
Louis Dionne
f638f7b6a7 [libc++] Update with LWG issue number for shared-ptr constructor 2024-06-11 16:48:35 -04:00
Nico Weber
716ed5fccd
[libc++] Undeprecate shared_ptr atomic access APIs (#92920)
This patch reverts 9b832b72 (#87111):
- [libc++] Deprecated `shared_ptr` Atomic Access APIs as per P0718R2
- [libc++] Implemented P2869R3: Remove Deprecated `shared_ptr` Atomic Access APIs from C++26

As explained in [1], the suggested replacement in P2869R3 is `__cpp_lib_atomic_shared_ptr`,
which libc++ does not yet implement. Let's not deprecate the old way of doing things before
the new way of doing things exists.

[1]: https://github.com/llvm/llvm-project/pull/87111#issuecomment-2112740039
2024-06-07 11:31:17 -04:00
Konstantin Varlamov
86070a84c4
[libc++][hardening] Finish documenting hardening. (#92021) 2024-06-06 16:35:33 -07:00
Hui
9595eb10ae
[libc++][test] Close LWG3018 and add tests (#93047) 2024-05-29 18:46:39 +01:00