4432 Commits

Author SHA1 Message Date
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
Louis Dionne
8ab82a2dc3
[libc++] Add a test case for std::bit_cast with std::complex (#97751)
This is extracted from #94620. While libc++ doesn't have the problem
described in that issue, a test case is a good idea to ensure that we
don't regress this behavior in the future. This could happen for example
if we decide to use `_Complex` in the implementation of `std::complex`
while Clang doesn't handle bit_cast with _Complex yet.
2024-07-08 16:19:24 -04: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
Mital Ashok
8426b51e0e
[libcxx][test][NFC] Fix std::pair convertible tests in light of CWG2137 (#97403)
https://cplusplus.github.io/CWG/issues/2137.html

This change was previously made as part of
924701311aa79180e86ad8ce43d253f27d25ec7d (#77768) and later reverted in
6e4930c67508a90bdfd756f6e45417b5253cd741

This change is still needed because the comment is still true: A
standards-conformant compiler is currently supposed to fail this test.

This also means that any future work on CWG2137 with Clang would not
need to modify the libc++ test suite
2024-07-06 15:34:12 -04: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
5aa8ef8e9b
[libc++][test] Updates sized deallocation tests. (#97833)
In #90373 size deallocation was enabled by default. Some test were
disabled to propagate the clang changes to the libc++ CI. These changes
have been propagated so the test filter can be updated.
2024-07-06 11:56:11 +02:00
Nikolas Klauser
5aacf93a89
[libc++] Use _Complex for multiplication and division of complex floating point types (#83575)
This significantly simplifies the implementation and improves the
codegen. The only downside is that the accuracy can be marginally worse,
but that is up to the compiler to decide with this change, which means
it can be controlled by compiler flags.

Differential Revision: https://reviews.llvm.org/D155312
2024-07-05 11:25:59 +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
Nikolas Klauser
655651a023
[libc++] Upgrade to GCC 14 (#97205) 2024-07-04 17:23:31 +02:00
A. Jiang
0865b782f6
[libc++] Fix the signatures of std::rethrow_if_nested (#91365)
Fixes #54470.

See https://eel.is/c++draft/global.functions#2:
    > A call to a non-member function signature described in [support]
    > through [thread] and [depr] shall behave as if the implementation
    > declared no additional non-member function signatures.

and https://eel.is/c++draft/global.functions#3:
    > An implementation shall not declare a non-member function signature
    > with additional default arguments.
2024-07-03 10:51:23 -04:00
Louis Dionne
3497500946
[libc++] Clean up and update deployment target features (#96312)
This patch removes many annotations that are not relevant anymore since
we don't support or test back-deploying to macOS < 10.13. It also cleans
up raw usage of target triples to identify versions of dylibs shipped on
prior versions of macOS, and uses the target-agnostic Lit features
instead. Finally, it reorders both the Lit backdeployment features and
the corresponding availability macros in the library in a way that makes
more sense, and reformulates the Lit backdeployment features in terms of
when a version of LLVM was introduced instead of encoding the system
versions on which it hasn't been introduced yet. Although one can be
derived from the other, encoding the negative form is extremely
error-prone.

Fixes #80901
2024-06-28 10:40:35 -05:00
Louis Dionne
637b7f805a
[libc++] Classify iota_view precondition (#96662)
Fixes #91385
2024-06-26 11:35:15 -05:00
Hui
16f349251f
[libc++] restrict the expected conversion constructor not compete against copy constructor (#96101)
fixes #92676

So right now clang does not like 
```
std::expected<std::any, int> e1;
auto e2 = e1;

```

So basically when clang tries to do overload resolution of `auto e2 =
e1;`

It finds

```
expected(const expected&);  // 1. This is OK
expected(const expected<_Up, _OtherErr>&)  requires __can_convert; // 2. This needs to check its constraints
```

Then in `__can_convert`, one of the check is 

```
_Not<is_constructible<_Tp, expected<_Up, _OtherErr>&>>
```
which is checking 
```
is_constructible<std::any, expected<_Up, _OtherErr>&>
```

Then it looks at `std::any`'s constructor
```
  template < class _ValueType,
             class _Tp = decay_t<_ValueType>,
             class     = enable_if_t< !is_same<_Tp, any>::value && !__is_inplace_type<_ValueType>::value &&
                                      is_copy_constructible<_Tp>::value> >
  any(_ValueType&& __value);
```
In the above, `is_copy_constructible<_Tp>` expands to
```
is_copy_constructible<std::expected<std::any, int>>
```

And the above goes back to the original thing we asked : copy the
`std::expected`, which goes to the overload resolution again.

```
expected(const expected&);
expected(const expected<_Up, _OtherErr>&)  requires __can_convert;
```

So the second overload results in a logical cycle. 

I am not a language lawyer. We could argue that clang should give up on
the second overload which has logical cycle, as the first overload is a
perfect match.

Anyway, the fix in this patch tries to short-circuiting the second
overload's constraint check: that is, if the argument matches exact same
`expected<T, E>`, we give up immediately and let the copy constructor to
deal with it
2024-06-26 12:10:59 +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
Jakub Mazurkiewicz
bb075eeb89
[libc++] LWG3382: NTTP for pair and array (#85811)
Mark LWG3382 as "Nothing To Do" and add tests.
2024-06-25 10:43:15 -05:00
Xiaoyang Liu
8c11d3788c
[libc++] P3029R1: Better mdspan's CTAD - std::extents (#89015)
This patch implements an improvement introduced in P3029R1 that was 
missed in #87873. It adds a deduction of static extents if 
integral_constant-like  constants are passed to `std::extents`.
2024-06-25 10:20:14 -05: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
Louis Dionne
fd62906ddb
[libc++] Fix incorrect overflow checking in std::lcm (#96310)
We should have been using __builtin_mul_overflow from the start instead
of adding a manual (and error-prone) check for overflow.

Fixes #96196
2024-06-25 08:35:23 -05:00
Nikolas Klauser
16d02cd1c5
[libc++] Use __is_nothrow_destructible (#95766)
This changes the behaviour in C++03 mode because we'll now use the
builtin on Clang, but I don't think that's much of a problem.
2024-06-25 11:20:14 +02:00
ZhangYin
6ec1ddfd72
[libc++] <experimental/simd> Add swap functions of simd reference (#86478) 2024-06-23 12:51:02 +08:00
Louis Dionne
db8c7e004a
[libc++] Fix deployment target Lit features (#94791)
We were not making any distinction between e.g. the "Apple-flavored"
libc++ built from trunk and the system-provided standard library on
Apple platforms. For example, any test that would be XFAILed on a
back-deployment target would unexpectedly pass when run on that
deployment target against the tip of trunk Apple-flavored libc++. In
reality, that test would be expected to pass because we're running
against the latest libc++, even if it is Apple-flavored.

To solve this issue, we introduce a new feature that describes whether
the Standard Library in use is the one provided by the system by
default, and that notion is different from the underlying standard
library flavor. We also refactor the existing Lit features to make a
distinction between availability markup and the library we're running
against at runtime, which otherwise limit the flexibility of what we can
express in the test suite. Finally, we refactor some of the
back-deployment versions that were incorrect (such as thinking that LLVM
10 was introduced in macOS 11, when in reality macOS 11 was synced with
LLVM 11).

Fixes #82107
2024-06-21 10:31:22 -04:00
Louis Dionne
fd001c16fe
[libc++] Workaround clang bug in __has_unique_object_representations (#95314)
Clang currently has a bug in the __has_unique_object_representations
builtin where it doesn't provide consistent answers based on the order
of instantiation of templates. This was reported as #95311.

This patch adds a workaround in libc++ to avoid breaking users until
Clang has been fixed. It also revamps the tests a bit.
2024-06-20 16:34:02 -04:00
Louis Dionne
04a75f54a1
[libc++] Properly define _LIBCPP_HAS_NO_UNICODE in __config_site (#95138)
Fixes #93638

Co-authored-by: Mark de Wever <koraq@xs4all.nl>
2024-06-18 14:22:33 -04:00
Nikolas Klauser
cb41740187
[libc++] Refactor<__type_traits/is_swappable.h> (#86822)
This changes the `is_swappable` implementation to use variable templates
first and basing the class templates on that. This avoids instantiating
them when the `_v` versions are used, which are generally less resource
intensive.
2024-06-18 11:01:43 +02:00
Mark de Wever
e48f211ab8
[libc++][TZDB] Disables a failing test. (#95659)
The test fails depending on the timezone database used. Disable it for
now so it can be properly investigated later.
2024-06-15 19:59:05 +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
David Tenty
9afb09e674
[libcxx][test][AIX] address more platform differences in locale tests (#94826)
This is a follow on to https://github.com/llvm/llvm-project/pull/92312,
where we address some more locale platform differences. These are:

- for locale fr_FR AIX libc expects `U202F` as `LC_MONETARY`
`thousands_sep`
- for locale zh_CN AIX libc `LC_MONETARY` has `n_sign_posn == 1`,
indicating the `negative_sign` should come before the `currency_symbol`
string
2024-06-14 11:13:54 -04:00
Louis Dionne
148417bfaa
[libc++] Mark local_time test as a long test (#95170)
It can otherwise timeout under some slow configurations.
2024-06-12 17:24:38 -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
Rodrigo Salazar
11399028ba
[libcxx] Correct and clean-up filesystem operations error_code paths (#88341)
3 error_code related cleanups/corrections in the std::filesystem
operations functions.

1. In `__copy`, the `ec->clear()` is unnecessary as `ErrorHandler` at
the start of each function clears the error_code as part of its
initialization.

2. In `__copy`, in the recursive codepath we are not checking the
error_code result of `it.increment(m_ec2)` immediately after use in the
for loop condition (and we aren't checking it after the final increment
when we don't enter the loop).

3. In `__weakly_canonical`, it makes calls to `__canonical` (which
internally uses OS APIs implementing POSIX `realpath`) and we are not
checking the error code result from the `__canonical` call. Both
`weakly_canonical` and `canonical` are supposed to set the error_code
when underlying OS APIs result in an error
(https://eel.is/c++draft/fs.err.report#3.1). With this change we
propagate up the error_code from `__canonical` caused by any underlying
OS API failure up to the `__weakly_canonical`. Essentially, if
`__canonical` thinks an error code should be set, then
`__weakly_canonical` must as well. Before this change it would be
throwing an exception in the non-error_code form of the function when
`__canonical` fails, while not setting the error code in the error_code
form of the function (an inconsistency).

Added a little coverage in weakly_canonical.pass.cpp for the error_code
forms of the API that was missing. Though I am lacking utilities in
libcxx testing to add granular testing of the failure scenarios (like
forcing realpath to fail for a given path, as it could if you had
something like a flaky remote filesystem).
2024-06-12 12:11:57 -04:00
Zibi Sarbinowski
47afa10bba
[libc++][z/OS] Disable portion of formatter.char.funsigned-char.pass.cpp for no unicode (#94044)
This PR carves out small portion of the test in subject to avoid the
following failure when unicode is not available.

```
# | Assertion failure: result == expected .../formatter.char.funsigned-char.pass.cpp 56
# |
# | Format string   ?}
# | Expected output '\x{80}'
# | Actual output   '�'
```

This was traced down to different definition of
`__code_point_view::__consume()` under macro_LIBCXX_HAS_NO_UNICODE which
is called inside `__formatter::__escape()`. The `__consume()` returns
`__ok` and code assumes that escaped sequence was already written but it
is not., thus the failure. Here is the snippen code we fall into:

```
    typename __unicode::__consume_result __result = __view.__consume();
    if (__result.__status == __unicode::__consume_result::__ok) {
      __escape = __formatter::__is_escaped_sequence_written(__str, __result.__code_point, __escape, __mark);
```
2024-06-12 09:28:39 -04:00
Louis Dionne
f638f7b6a7 [libc++] Update with LWG issue number for shared-ptr constructor 2024-06-11 16:48:35 -04:00
Louis Dionne
16f2aa1a2d
[libc++] Tweak how we check constraints on shared_ptr(nullptr_t) (#94996)
This avoids breaking code that should arguably be valid but technically
isn't after enforcing the constraints on shared_ptr's constructors. A
new LWG issue was filed to fix this in the Standard.

This patch applies the expected resolution of this issue to avoid
flip-flopping users whose code should always be considered valid.

See #93071 for more context.
2024-06-11 16:45:12 -04:00
Florian Mayer
00c5474918 [HWASan] make get_info.local_time.pass.cpp UNSUPPORTED 2024-06-11 09:06:07 -07:00
Florian Mayer
503fb1aaf4 [HWASan] skip libcxx test that times out with hwasan 2024-06-10 10:35:18 -07:00
Mark de Wever
151bd7cab4
[libc++][TZDB] Implements zoned_traits. (#91059)
Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-10 17:13:08 +02:00
Stephan T. Lavavej
88ff2463ea
[libc++][test] Avoid -Wunused-variable warnings in mutex tests (#94907)
After enhancing MSVC's STL to statically initialize our condition_variable,
Clang began noticing that some mutexes in the test suite were unused.
2024-06-10 09:54:56 -04:00
Mark de Wever
da03175cae
[libc++][TZDB] Implements time_zone::to_local. (#91003)
Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-10 12:40:27 +02:00
Mark de Wever
87cedbec1c
[libc++][TZDB] Implements time_zone::to_sys. (#90901)
This implements the overload with the choose argument and adds this
enum.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-10 08:40:04 +02:00
Mark de Wever
77116bd7d2
[libc++][TZDB] Implements time_zone::to_sys. (#90394)
This implements the throwing overload and the exception classes throw by
this overload.

Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-10 00:33:39 +02:00
Mark de Wever
de736d9c6a
[libc++][TZDB] Implements time_zone get_info(local_time). (#89537)
Implements parts of:
- P0355 Extending chrono to Calendars and Time Zones
2024-06-09 18:21:35 +02: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
e9adcc488f
[libc++][regex] Correctly adjust match prefix for zero-length matches. (#94550)
For regex patterns that produce zero-length matches, there is one
(imaginary) match in-between every character in the sequence being
searched (as well as before the first character and after the last
character). It's easiest to demonstrate using replacement:
`std::regex_replace("abc"s, "!", "")` should produce `!a!b!c!`, where
each exclamation mark makes a zero-length match visible.

Currently our implementation doesn't correctly set the prefix of each
zero-length match, "swallowing" the characters separating the imaginary
matches -- e.g. when going through zero-length matches within `abc`, the
corresponding prefixes should be `{'', 'a', 'b', 'c'}`, but before this
patch they will all be empty (`{'', '', '', ''}`). This happens in the
implementation of `regex_iterator::operator++`. Note that the Standard
spells out quite explicitly that the prefix might need to be adjusted
when dealing with zero-length matches in
[`re.regiter.incr`](http://eel.is/c++draft/re.regiter.incr):
> In all cases in which the call to `regex_search` returns `true`,
`match.prefix().first` shall be equal to the previous value of
`match[0].second`... It is unspecified how the implementation makes
these adjustments.

[Reproduction example](https://godbolt.org/z/8ve6G3dav)
```cpp
#include <iostream>
#include <regex>
#include <string>

int main() {
  std::string str = "abc";
  std::regex empty_matching_pattern("");

  { // The underlying problem is that `regex_iterator::operator++` doesn't update
    // the prefix correctly.
    std::sregex_iterator i(str.begin(), str.end(), empty_matching_pattern), e;
    std::cout << "\"";
    for (; i != e; ++i) {
      const std::ssub_match& prefix = i->prefix();
      std::cout << prefix.str();
    }
    std::cout << "\"\n";
    // Before the patch: ""
    // After the patch: "abc"
  }

  { // `regex_replace` makes the problem very visible.
    std::string replaced = std::regex_replace(str, empty_matching_pattern, "!");
    std::cout << "\"" << replaced << "\"\n";
    // Before the patch: "!!!!"
    // After the patch: "!a!b!c!"
  }
}
```

Fixes #64451

rdar://119912002
2024-06-07 11:15:02 -04:00
Jake Egan
790992dd40
[libc++][test][AIX] Only XFAIL atomic tests for before clang 19 (#94646)
These tests pass on 64-bit. They were fixed by 5fdd094837c6 on 32-bit.
So XFAIL only for 32-bit before clang 19.
2024-06-07 11:06:42 -04:00
David Tenty
df168427b3
[NFC][libc++][test][AIX] fix SIMD test XFAIL for clang before 19 (#94509)
058e4454 added an XFAIL for this test on AIX because of a backend
limitation. That backend limitation
has been resolved by 0295c2ad and will be available for clang 19, so we
should update the test to
limit the XFAIL to clang versions before that.
2024-06-06 11:29:15 -04:00