Commit Graph

3712 Commits

Author SHA1 Message Date
Arthur O'Dwyer 8320017b79 [libc++] [ranges] Uncomment operator<=> in transform and iota iterators.
The existing tests for transform_view::iterator weren't quite right,
and can be simplified now that we have more of C++20 available to us.
Having done that, let's use the same pattern for iota_view::iterator
as well.

Differential Revision: https://reviews.llvm.org/D110774
2021-10-02 21:26:27 -04:00
Mark de Wever ac7031b2b2 [libc++][format] Implement Unicode support.
This adds the width estimation functions to the std-format-spec.

Implements parts of:
- P0645 Text Formatting
- P1868 width: clarifying units of width and precision in std::format

Reviewed By: #libc, ldionne, vitaut

Differential Revision: https://reviews.llvm.org/D103413
2021-10-02 11:57:40 +02:00
Arthur O'Dwyer 2a6b99d5f8 [libc++] Revert the part of my b82683b that affected <version>.
This reverts part of commit b82683b2eb.
I hadn't intended to remove the `// -*- C++ -*-` comment line
from `libcxx/include/version`, only from the generated tests.
Thanks to Raul Tambre for the catch.
2021-10-01 13:01:51 -04:00
Arthur O'Dwyer b82683b2eb [libc++] [test] Remove "// -*- C++ -*-" comments from generated .cpp files.
Even if these comments have a benefit in .h files (for editors that
care about language but can't be configured to treat .h as C++ code),
they certainly have no benefit for files with the .cpp extension.

Discussed in D110794.
2021-10-01 12:04:19 -04:00
Arthur O'Dwyer ae0e037f53 [libc++] Simplify the _LIBCPP_CONSTEXPR markings on starts_with() etc.
This came out of review comments on D110598.

Differential Revision: https://reviews.llvm.org/D110637
2021-09-29 19:00:58 -04:00
Louis Dionne 940755515d [libc++] Add the std::views::common range adaptor
Differential Revision: https://reviews.llvm.org/D110433
2021-09-29 17:27:34 -04:00
Arthur O'Dwyer 969359e3b8 [libc++] [compare] Named comparison functions, is_eq etc.
Some of these were previously half-implemented in "ordering.h";
now they're all implemented, and tested.
Note that `constexpr` functions are implicitly `inline`, so the
standard wording omits `inline` on these; but Louis and I agree
that that's surprising and it's better to be explicit about it.

Differential Revision: https://reviews.llvm.org/D110515
2021-09-29 16:03:48 -04:00
Louis Dionne 86df5a2fa8 [libc++] Simplify std::ranges::subrange
Instead of using a base class to store the members and the optional
size, use [[no_unique_address]] to achieve the same thing without
needing a base class.

Also, as a fly-by:
- Change subrange from struct to class (per the standard)
- Improve the diagnostic for when one doesn't provide a size to the ctor of a sized subrange
- Replace this->member by just member since it's not in a dependent base anymore

This change would be an ABI break due to [[no_unique_address]], but we
haven't shipped ranges anywhere yet, so this shouldn't affect anyone.

Differential Revision: https://reviews.llvm.org/D110370
2021-09-28 17:34:01 -04:00
Arthur O'Dwyer a7d084a18d [libc++] [compare] Rip out more vestiges of *_equality. NFCI.
There's really no reason to even have two different enums here,
but *definitely* we shouldn't have *three*, and they don't need
so many synonymous enumerator values.

Differential Revision: https://reviews.llvm.org/D110516
2021-09-28 12:23:41 -04:00
Joe Loser 9451d9da95
[libc++][NFC] s/enable_if<...>::type/enable_if_t<...> in span
There is some use of `enable_if<...>::type` when the rest of the file
uses `enable_if_t`. So, use `enable_if_t` consistently throughout.
2021-09-27 19:21:07 -04:00
Louis Dionne 1e628d0c14 [libc++] Do not enable P1951 before C++23, since it's a breaking change
In reaction to the issues raised by Richard in https://llvm.org/D109066,
this commit does not apply P1951 as a DR in previous standard modes,
since it breaks valid code.

I do believe it should be applied as a DR, however ideally we'd get some
sort of statement from the Committee to this effect (and all implementations
would behave consistently). In the meantime, only implement P1951 starting
with C++23 -- we can always come back and apply it as a DR if that's what
the Committee says.

Differential Revision: https://reviews.llvm.org/D110347
2021-09-27 17:06:44 -04:00
Louis Dionne e6126faba0 [libc++] Remove unused macro in __config
That macro was being defined but not used anywhere in libc++, so it
must be safe to remove it.

As a fly-by fix, also remove mentions of this macro in other places
in LLVM, to make sure they were not depending on the value defined in
libc++.

Differential Revision: https://reviews.llvm.org/D110289
2021-09-23 13:09:32 -04:00
Louis Dionne 1711a6ec65 [libc++] Remove uses of _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
All supported compilers provide support for variable templates now.

Differential Revision: https://reviews.llvm.org/D110284
2021-09-23 08:53:59 -04:00
Kent Ross f4abdb0c07 [libc++][spaceship] Implement std::pair::operator<=>
Implements parts of P1614, including synth-three-way and three way comparison for std::pair.

Reviewed By: #libc, Quuxplusone, Mordante

Differential Revision: https://reviews.llvm.org/D107721
2021-09-22 22:36:46 -07:00
Arthur O'Dwyer 85d4e29fd8 [libc++] Fix __wrap_iter to be a proper contiguous iterator.
Instead of overloading `__to_address`, let's specialize `pointer_traits`.
Function overloads need to be in scope at the point where they're called,
whereas template specializations do not. (User code can provide pointer_traits
specializations to be used by already-included library code, so obviously
`__wrap_iter` can do the same.)

`pointer_traits<__wrap_iter<It>>` cannot provide `pointer_to`, because
you generally cannot create a `__wrap_iter` without also knowing the
identity of the container into which you're trying to create an iterator.
I believe this is OK; contiguous iterators are required to provide
`to_address` but *not* necessarily `pointer_to`.

Differential Revision: https://reviews.llvm.org/D110198
2021-09-22 18:51:46 -04:00
Louis Dionne 474816384f [libc++][NFC] Add missing whitespace in <compare> 2021-09-22 16:41:18 -04:00
Louis Dionne cb793e1a36 [libc++][NFCI] Remove uses of _LIBCPP_INLINE_VAR
All supported compilers provide support for inline variables in C++17 now.
Also, as a fly-by fix, replace some uses of _LIBCPP_CONSTEXPR by just
constexpr.

The only exception in this patch is `std::ignore`, which is provided
prior to C++17. Since it is defined in an anonymous namespace, it always
has internal linkage anyway, so using an inline variable there doesn't
provide any benefit. Instead, `inline` was removed entirely on `std::ignore`.

Differential Revision: https://reviews.llvm.org/D110243
2021-09-22 16:03:00 -04:00
Joe Loser 400b33e18d
[libc++] Disallow volatile types in std::allocator
LWG 2447 is marked as `Complete`, but there is no `static_assert` to
reject volatile types in `std::allocator`. See the discussion at
https://reviews.llvm.org/D108856.

Add `static_assert` in `std::allocator` to disallow volatile types. Since this
is an implementation choice, mark the binding test as `libc++` only.

Remove tests that use containers backed by `std::allocator` that test
the container when used with a volatile type.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D109056
2021-09-22 11:47:38 -04:00
Louis Dionne 84d07f4dfe [libc++] Add some missing _LIBCPP_HIDE_FROM_ABI markup
Also, as a fly-by fix, use `inline` directly to define inline variables
(all compilers support it).

Differential Revision: https://reviews.llvm.org/D110208
2021-09-21 23:11:23 -04:00
David Tenty 7a320b279d [libcxx][AIX] Remove locale fallbacks for old OS levels
These routines were add years ago during initial porting attempts to AIX and are mostly build hacks for routines which we're missing at the time, but are available now on recent AIX OS levels.

Thus builds on modern AIX OS levels no longer need these and they cause problems if you try to build the library with a generic triple (i.e. powerpc-ibm-aix) as we'll pull them in and encounter duplicate definitions from the OS.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D110183
2021-09-21 21:14:50 -04:00
Yuanfang Chen 45c0ebe00e [libc++] Surpress -Wunused-value warning in variant
The idiom helps with parameter unpacking so the return value is not
important. Make it explicit.
2021-09-21 15:33:10 -07:00
Arthur O'Dwyer c9af0e61fa [libc++] counting_semaphore should not be default-constructible.
Neither the current C++2b draft, nor any revision of [p1135],
nor libstdc++, claims that `counting_semaphore` should be
default-constructible. I think this was just a copy-paste issue
somehow.

Also, `explicit` was missing from the constructor.

Also, `constexpr` remains missing; but that's probably more of a
technical limitation, since apparently there are some platforms
where we don't (can't??) use the atomic implementation and
have to rely on pthreads, which obviously isn't constexpr.

Differential Revision: https://reviews.llvm.org/D110042
2021-09-21 16:19:31 -04:00
Mark de Wever a04a6ce772 [libc++][format] Adds parser std-format-spec.
This implements the generic std.format.spec framework for all types.

The Unicode support will be added in a separate patch.

Implements parts of:
- P0645 Text Formatting

Completes:
- LWG-3242 std::format: missing rules for arg-id in width and precision
- P1892 Extended locale-specific presentation specifiers for std::format

Reviewed By: #libc, ldionne, vitaut

Differential Revision: https://reviews.llvm.org/D103368
2021-09-21 18:29:58 +02:00
Arthur O'Dwyer d5db71d19f [libc++] [P0919] Some belated review on D87171.
- Simplify the structure of the new tests.
- Test const containers as well as non-const containers,
    since it's easy to do so.
- Remove redundant enable-iffing of helper structs' member functions.
    (They're not instantiated unless they're called, and who would call them?)
- Fix indentation and use more consistent SFINAE method in <unordered_map>.
- Add _LIBCPP_INLINE_VISIBILITY on some swap functions.

Differential Revision: https://reviews.llvm.org/D109011
2021-09-20 14:46:38 -04:00
Arthur O'Dwyer df81bb71aa [libc++] [LIBCXX-DEBUG-FIXME] Constexpr char_traits::copy mustn't compare unrelated pointers.
Now that __builtin_is_constant_evaluated() is present on all supported
compilers, we can use it to skip the UB-inducing assert in cases where
the computation might be happening at constexpr time.

Differential Revision: https://reviews.llvm.org/D101674
2021-09-20 14:44:59 -04:00
Arthur O'Dwyer d7d7060127 Eliminate _LIBCPP_EQUAL_DELETE in favor of `=delete`.
All supported compilers have supported `=delete` as an extension
in C++03 mode for many years at this point.

Differential Revision: https://reviews.llvm.org/D109942
2021-09-20 13:26:59 -04:00
Muiez Ahmed 4247381e26 [SystemZ][z/OS] Missing wchar functions libc++
The aim is to add the missing z/OS specific implementations for mbsnrtowcs and wcsnrtombs, as part of libc++.

Differential Revision: https://reviews.llvm.org/D98207
2021-09-13 09:43:21 -04:00
Xing Xue f53fafbacb [libc++] Add missing short wchar handling for codecvt_utf8, codecvt_utf16 and codecvt_utf8_utf16
Summary:
AIX have 2 byte wchar in 32 bit mode and 4 byte wchar in 64 bit mode.
This patch add more missing short wchar handling under the existing _LIBCPP_SHORT_WCHAR macro.

Marked test case ctor_move.pass.cpp as XFAIL for 32-bit mode on AIX because UTF-8 constants used cannot be converted to 2-byte wchar (by xingxue).

Authored by: jasonliu

Reviewed by: ldionne, zibi, SeanP, libc++

Differential Revision: https://reviews.llvm.org/D100777
2021-09-09 16:20:36 -04:00
Louis Dionne ad2b7a14f0 [libc++][NFC] Add #endif comment for long #if-#endif block 2021-09-09 14:43:10 -04:00
Louis Dionne 720b556036 [libc++][NFC] Move __char_traits_length_checked outside of wchar_t definitions
This will simplify an upcoming diff.
2021-09-09 13:24:11 -04:00
Louis Dionne 71752e0008 [libc++][NFC] Remove #endif comments for really small conditionals on _LIBCPP_HAS_NO_UNICODE_CHARS
We generally don't put a comment on the #endif when the #if block is so small
that it's unambiguous what the #endif refers to.
2021-09-09 11:25:10 -04:00
Louis Dionne b1fb3d75c9 [libc++] Implement C++20's P0476R2: std::bit_cast
Thanks to Arthur O'Dwyer for fixing up some of the tests.

Differential Revision: https://reviews.llvm.org/D75960
2021-09-09 11:05:54 -04:00
Louis Dionne 312ad74aea [libc++] Implement P1951, default arguments for pair's forwarding constructor
Differential Revision: https://reviews.llvm.org/D109066
2021-09-09 08:28:22 -04:00
Louis Dionne b4e88d4db1 [libc++][NFC] Rename _EnableIf to __enable_if_t for consistency
In other places in the code, we use lowercase spelling for things that
are not available in prior standards.

Differential Revision: https://reviews.llvm.org/D109435
2021-09-08 15:20:58 -04:00
Arthur O'Dwyer 16bf43398a [libc++] Comma-operator-proof a lot of algorithm/container code.
Detected by evil-izing the widely used `MoveOnly` testing type.
I had to patch some tests that were themselves using its comma operator,
but I think that's a worthwhile cost in order to catch more places
in our headers that needed comma-proofing.

The trick here is that even `++ptr, SomeClass()` can find a comma operator
by ADL, if `ptr` is of type `Evil*`. (A comma between two operands
of non-class-or-enum type is always treated as the built-in
comma, without ADL. But if either operand is class-or-enum, then
ADL happens for _both_ operands' types.)

Differential Revision: https://reviews.llvm.org/D109414
2021-09-08 13:34:01 -04:00
Louis Dionne 4e0ea2cf2e [libc++] Use enable_if_t instead of _EnableIf
I just ran into a compiler error involving __bind_back and some overloads
that were being disabled with _EnableIf. I noticed that the error message
was quite bad and did not mention the reason for the overload being
excluded. Specifically, the error looked like this:

     candidate template ignored: substitution failure [with _Args =
     <ContiguousView>]: no member named '_EnableIfImpl' in 'std::_MetaBase<false>'

Instead, when using enable_if or enable_if_t, the compiler is clever and
can produce better diagnostics, like so:

     candidate template ignored: requirement 'is_invocable_v<
          std::__bind_back_op<1, std::integer_sequence<unsigned long, 0>>,
          std::ranges::views::__transform::__fn &, std::tuple<PlusOne> &,
          ContiguousView>' was not satisfied [with _Args = <ContiguousView>]

Basically, it tries to do a poor man's implementation of concepts, which
is already a lot better than simply complaining about substitution failure.

Hence, this commit uses enable_if_t instead of _EnableIf whenever
possible. That is both more straightforward than using the internal
helper, and also leads to better error messages in those cases.

I understand the motivation for _EnableIf's implementation was to improve
compile-time performance, however I believe striving to improve error
messages is even more important for our QOI, hence this patch. Furthermore,
it is unclear that _EnableIf actually improved compile-time performance
in any noticeable way (see discussion in the review for details).

Differential Revision: https://reviews.llvm.org/D108216
2021-09-08 09:09:28 -04:00
Louis Dionne 08d56432ad [libc++][NFC] Add missing synopsis for node handles
This was manually taken from https://llvm.org/D100311.
2021-09-07 15:26:33 -04:00
Arthur O'Dwyer 0a5ebc692b [libc++] Remove a stray `const` on ranges::data and ranges::ssize. NFCI.
These are specced as `inline constexpr auto`; the extra `const`
isn't doing anything except being inconsistent with the other CPOs.
Now all the implemented CPOs can be detected by
    git grep 'inline constexpr auto.*fn' ../libcxx/include/
and I think that's beautiful.
2021-09-07 13:59:21 -04:00
Arthur O'Dwyer dadbe88a13 [libc++] Fix std::to_address(array).
There were basically two bugs here:

When C++20 `to_address` is called on `int arr[10]`, then `const _Ptr&` becomes
a reference to a const array, and then we dispatch to `__to_address<const int(&)[10]>`,
which, oops, gives us a `const int*` result instead of an `int*` result.
Solution: We need to provide the two standard-specified overloads of
`std::to_address` in exactly the same way that we provide two overloads
of `__to_address`.

When `__to_address` is called on a pointer type, `__to_address(const _Ptr&)`
is disabled so we successfully avoid trying to instantiate pointer_traits of
that pointer type. But when it's called on an array type, it's not disabled
for array types, so we go ahead and instantiate pointer_traits<int[10]>,
which goes boom. Solution: We need to disable `__to_address(const _Ptr&)`
for both pointer and array types. Also disable it for function types,
so that they get the nice error message; and put a test on it.

Differential Revision: https://reviews.llvm.org/D109331
2021-09-07 13:56:25 -04:00
Ruslan Arutyunyan 8ce2675b13 [libc++][compare] Implement three_way_comparable[_with] concepts
Implementation of `three_way_comparable` and `three_way_comparable_with` concepts from <compare> header.

Please note that I have temporarily removed `<compare>` header from `<utility>` due to cyclic dependency that prevents using `<concepts>` header in `<compare>` one.

I tried to quickly resolve those issues including applying suggestions from @cjdb and dive deeper by myself but the problem seems more complicated that we thought initially.

I am in progress to prepare the patch with resolving this cyclic dependency between headers but for now I decided to put all that I have to the review to unblock people that depend on that functionality. At first glance the patch with resolving cyclic dependency is not so small (unless I find the way to make it smaller and cleaner) so I don't want to mix everything to one review.

Reviewed By: ldionne, cjdb, #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D103478
2021-09-05 12:38:08 -07:00
Mark de Wever d7444d9f41 [libc++][format] Implement formatters.
This implements the initial version of the `std::formatter` class and its specializations. It also implements the following formatting functions:
- `format`
- `vformat`
- `format_to`
- `vformat_to`
- `format_to_n`
- `formatted_size`

All functions have a `char` and `wchar_t` version. Parsing the format-spec and
using the parsed format-spec hasn't been implemented. The code isn't optimized,
neither for speed, nor for size.

The goal is to have the rudimentary basics working, which can be used as a
basis to improve upon. The formatters used in this commit are simple stubs that
will be replaced by real formatters in later commits.

The formatters that are slated to be replaced in this patch series don't have
an availability macro to avoid merge conflicts.

Note the formatter for `bool` uses `0` and `1` instead of "false" and
"true". This will be fixed when the stub is replaced with a real
formatter.

Implements parts of:
- P0645 Text Formatting

Completes:
- LWG3539 format_to must not copy models of output_iterator<const charT&>

Reviewed By: ldionne, #libc, vitaut

Differential Revision: https://reviews.llvm.org/D96664
2021-09-04 11:41:08 +02:00
Louis Dionne fd66b44ec1 [libc++] Add an assertion in the subrange constructors with a size hint
Those constructors are very easy to misuse -- one could easily think that
the size passed to the constructor is the size of the range to exhibit
from the subrange. Instead, it's a size hint and it's UB to get it wrong.
Hence, when it's cheap to compute the real size of the range, it's cheap
to make sure that the user didn't get it wrong.

Differential Revision: https://reviews.llvm.org/D108827
2021-09-03 16:04:02 -04:00
Louis Dionne c137a0754c [libc++] Remove _LIBCPP_HAS_NO_LONG_LONG in favour of using_if_exists
_LIBCPP_HAS_NO_LONG_LONG was only defined on FreeBSD. Instead, use the
using_if_exists attribute to skip over declarations that are not available
on the base system. Note that there's an annoying limitation that we can't
conditionally define a function based on whether the base system provides
a function, so for example we still need preprocessor logic to define the
abs() and div() overloads.

Differential Revision: https://reviews.llvm.org/D108630
2021-09-03 14:26:59 -04:00
Arthur O'Dwyer d1e50738d7 [libc++] Define insert_iterator::iter with ranges::iterator_t.
The `insert_iterator::iter` member is defined as `Container::iterator` but
the standard requires `iter` to be defined in terms of `ranges::iterator_t` as
of C++20. So, if in C++20 or later, define the `iter` member as
`ranges::iterator_t`.

Original patch by Joe Loser!

Differential Revision: https://reviews.llvm.org/D108575
2021-09-02 16:15:53 -04:00
Mark de Wever 803141c7a7 [libc++] Remove an unused internal concept.
Removed as suggested by @Quuxplusone during the review of D109075.
2021-09-02 19:27:49 +02:00
Mark de Wever 1637921134 [libc++][NFC] Move concepts to a subheader.
D103357 added some new concepts. Since the header `<concepts>` has moved
all its concepts to a separate header these new concepts feel out of
place. Move them to the appropriate header.

Reviewed By: #libc, Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D109075
2021-09-02 19:22:15 +02:00
Mark de Wever 67794e784e [libc++][nfc] Fixes ppc64le-sanitizer build issue.
After landing D103357 the worker ppc64le-sanitizer fails on `__bool`.
This replaces all occurrences with `__boolean`.
2021-09-02 08:13:59 +02:00
Mark de Wever 0922ce56f4 [libc++][format] Add __format_arg_store.
This implements the struct `__format_arg_store` and its dependencies:
* the class basic_format_arg,
* the class basic_format_args,
* the class basic_format_context,
* the function make_format_args,
* the function wmake_format_args,
* the function visit_format_arg,
* several Standard required typedefs.

The following parts will be implemented in a later patch:

* the child class `basic_format_arg::handle`,
* the function `basic_format_arg::basic_format_arg(const T* p)`.

The following extension has been implemented:
* the class basic_format_arg supports `__[u]int128_t` on platform where libc++ supports 128 bit integrals.

Implements parts of:
* P0645 Text Formatting

Completes:
* LWG3371 visit_format_arg and make_format_args are not hidden friends
* LWG3542 basic_format_arg mishandles basic_string_view with custom traits

Note https://mordante.github.io/blog/2021/06/05/format.html gives a bit more information about the goals and non-goals of this initial patch series.

Reviewed By: #libc, ldionne, vitaut

Differential Revision: https://reviews.llvm.org/D103357
2021-09-01 19:45:02 +02:00
Louis Dionne a4cb5aefd5 [libc++] Remove some workarounds for unsupported GCC and Clang versions
There is a lot more we can do, in particular in <type_traits>, but this
removes some workarounds that were gated on checking a specific compiler
version.

Differential Revision: https://reviews.llvm.org/D108923
2021-09-01 10:57:14 -04:00
Louis Dionne 3557c7c122 [libc++] Remove workarounds for [[nodebug]] not working properly on typedefs in older Clangs
Clang used to support [[nodebug]] everywhere except on typedefs. Since
we don't support such old Clangs anymore, we can get rid of _LIBCPP_NODEBUG_TYPE
in favour of always using _LIBCPP_NODEBUG.

Differential Revision: https://reviews.llvm.org/D108996
2021-09-01 10:51:09 -04:00
Louis Dionne 8f9cc3bc29 [libc++][NFC] Use std::enable_if instead of _EnableB helper in pair
This doesn't impact the compile-time efficiency, but we get better
diagnostics when an overload is disabled.
2021-09-01 10:48:09 -04:00
Joe Loser 2d400db63c
[libcxx] contiguous iterator concept: don't require pointer or complete element types
`contiguous_iterator` requires the iterator type passed is either a
pointer type or that the element type of the iterator is a complete
object type. These constraints are not part of the current wording in
defining the `contiguous_iterator` concept - adjust the concept to
reflect this.

Inspired from discussion at https://reviews.llvm.org/D108645.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D108855
2021-09-01 08:32:41 -04:00
Louis Dionne 1c9b7d0ecc [libc++][NFC] Remove redundant friend declaration for operator==
This must have been meant to be friend-declaring operator!=, but it
turns out that it's not even necessary to make it a friend since it
does not access any private state.

rdar://82568613
2021-08-31 17:02:58 -04:00
Louis Dionne 928cad59c7 [libc++][NFC] Rename _LIBCPP_NODISCARD_ATTRIBUTE to _LIBCPP_NODISCARD
Differential Revision: https://reviews.llvm.org/D108940
2021-08-31 16:06:31 -04:00
Louis Dionne e781e03e40 [libc++] Remove workaround for broken __is_trivially_copyable on old GCC
All supported versions of GCC now do the right thing.

Differential Revision: https://reviews.llvm.org/D108997
2021-08-31 16:05:29 -04:00
Arthur O'Dwyer c5e7981aec [libc++] Add missing space in (__map_value_compare&__y) etc. NFCI. 2021-08-31 14:30:20 -04:00
Mark de Wever e983a659e5 [libc++][NFC] split <charconv>.
This move the helper types `chars_format`, `to_chars_result` and
`from_chars_result` to a separate header. The first two are needed for
D70631 the third for consistency.

The header `__charconv/ryu.h` uses these types and it can't depend on the
types in `<charconv>` in a modular build. Moving them to the ryu header
would be an odd place and doesn't work since the header is included in the
middle of `<charconv>`.

Reviewed By: #libc, ldionne, Quuxplusone

Differential Revision: https://reviews.llvm.org/D108927
2021-08-31 18:45:19 +02:00
Louis Dionne e79474d337 [libc++][NFC] Add missing HIDE_FROM_ABI on implementation detail __launder 2021-08-31 10:29:29 -04:00
Xiang Xiao 3285c7a436 [libcxx] Remove the locale fallback for NuttX
Since these functions can handled by NuttX's libc now

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D108895
2021-08-31 09:46:55 -04:00
Louis Dionne c8b14c03ec [libc++][NFC] Fix include guard for decay_copy.h and remove underscores from the header
We don't use double underscores for private header names when they are
in a subdirectory with double underscores already.

Differential Revision: https://reviews.llvm.org/D108820
2021-08-27 12:45:53 -04:00
Louis Dionne 64184b4af0 [libc++][NFC] Remove useless _LIBCPP_PUSH_MACROS
Only files that actually use min/max are required to do this dance.

Differential Revision: https://reviews.llvm.org/D108778
2021-08-27 12:41:55 -04:00
Joe Loser 51414d9982 [libc++][NFC] Remove extra __ranges/take_view.h entry in CMakeLists.txt
Differential Revision: https://reviews.llvm.org/D108802
2021-08-27 10:08:33 -04:00
Louis Dionne 19e806e88d [libc++][NFC] Sort headers alphabetically 2021-08-26 14:18:09 -04:00
Louis Dionne ee44dd8062 [libc++] Implement the underlying mechanism for range adaptors
This patch implements the underlying mechanism for range adaptors. It
does so based on http://wg21.link/p2387, even though that paper hasn't
been adopted yet. In the future, if p2387 is adopted, it would suffice
to rename `__bind_back` to `std::bind_back` and `__range_adaptor_closure`
to `std::range_adaptor_closure` to implement that paper by the spec.

Differential Revision: https://reviews.llvm.org/D107098
2021-08-26 14:07:21 -04:00
Louis Dionne a4357bc496 [libc++] Fix incorrect bypassing of <wctype.h>
Differential Revision: https://reviews.llvm.org/D108709
2021-08-26 13:26:31 -04:00
Arthur O'Dwyer 15acca5ccd [libc++] Revert a use of `static_cast` for `_VSTD::forward`. NFCI.
As requested in D107584.

Differential Revision: https://reviews.llvm.org/D108743
2021-08-26 11:35:07 -04:00
Dimitry Andric 18da6db838 [libc++][NFC] Remove duplicate ranges entry in CMakeLists.txt.
The second entry got added accidentally as part of 5a3309f825.

Reviewed By: cjdb

Differential Revision: https://reviews.llvm.org/D108726
2021-08-25 23:49:43 +02:00
Louis Dionne 77b32055ec [libc++] Assume that compilers support extended constexpr in C++14 mode
We don't support any compiler that doesn't support C++14 constexpr when
compiling in C++14 mode anymore, so we can just assume that we have C++14
extended constexpr when compiling in C++14 mode. This allows us to remove
some workarounds for older compilers.

Differential Revision: https://reviews.llvm.org/D108638
2021-08-25 08:41:07 -04:00
Louis Dionne 87dd51983c [libc++] Remove support for CloudABI, which has been abandoned
Based on https://github.com/NuxiNL/cloudlibc, it appears that the CloudABI
project has been abandoned. This patch removes a bunch of CloudABI specific
logic that had been added to support that platform.

Note that some knobs like LIBCXX_ENABLE_STDIN and LIBCXX_ENABLE_STDOUT
coud be useful in their own right, however those are currently broken.
If we want to re-add such knobs in the future, we can do it like we've
done it for localization & friends so that we can officially support
that configuration.

Differential Revision: https://reviews.llvm.org/D108637
2021-08-24 14:11:32 -04:00
Louis Dionne 2540c77360 [libc++][NFC] Reindent error message 2021-08-23 15:34:51 -04:00
Arthur O'Dwyer ca7926bd79 [libc++] Eliminate needless `add_lvalue_reference` from <algorithm> helpers. NFCI.
When `_Compare` is a function parameter already (so it's not `void`
and it's not an abominable function type), `add_lvalue_reference_t<_Compare>`
is simply a synonym for `_Compare&`. We don't need to pull in `<type_traits>`
and instantiate a template trait to figure that out.

Differential Revision: https://reviews.llvm.org/D108400
2021-08-22 11:43:12 -04:00
Joe Loser 9807626bc7 [libc++] Include <__iterator/distance.h> instead of <iterator> in a few algorithm headers
A few headers in algorithm include `<iterator>` when
`<__iterator/distance.h>` would suffice. Change them
to just include `<__iterator.distance.h>`.

Differential Revision: https://reviews.llvm.org/D108393
2021-08-20 15:02:33 -04:00
Louis Dionne f3bc0e51ab [libc++] Bypass calling exception-throwing functions in the dylib with -fno-exceptions
basic_string and vector currently have a hard dependency on the compiled
library because they need to call __vector_base_common::__throw_xxx(),
which are externally instantiated in the compiled library. That makes
sense when exceptions are enabled (because we're trying to localize the
exception-throwing code to the compiled library), but it doesn't really
make sense when exceptions are disabled, and the __throw_xxx functions
are just calling abort() anyways.

This patch simply overrides the __throw_xxx() functions so that they
don't rely on the compiled library when exceptions are disabled.

Differential Revision: https://reviews.llvm.org/D108389
2021-08-20 08:38:58 -04:00
Kent Ross 7e325d4c0c [libc++][NFC] Remove unused include in <compare>.
`<type_traits>` was included in the first iteration of `<compare>` when
it was created as a monolithic header, then never removed. Removing it
now is a beneficial no-op since it is not guaranteed by the standard
and is already included by all of its subheaders.

Reviewed By: cjdb, #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D107801
2021-08-19 23:13:44 +00:00
Louis Dionne 475f831b17 [libc++][NFCI] Remove unnecessary exception-throwing base classes
__split_buffer_common was entirely unused, and __deque_base_common
was unused except for two calls to __throw_out_of_range(), which have
been inlined.

The usual intent of the __xxx_base_common base classes is to localize
where the exception-throwing code is instantiated, however that wasn't
the case here because we never explicitly instantiated those base classes
in the shared library, unlike what we do for basic_string and vector.

Differential Revision: https://reviews.llvm.org/D108384
2021-08-19 13:59:57 -04:00
Louis Dionne ebc01bbc7a [libc++] Skip logic for detecting C11 features when using_if_exists is supported
In the future, we'll want to rely exclusively on using_if_exists for this
job, but for now, only rely on it when the compiler supports that attribute.
That removes the possibility for getting the logic wrong.

Differential Revision: https://reviews.llvm.org/D108297
2021-08-18 11:53:34 -04:00
Arthur O'Dwyer 0fb189952c [libc++] Implement structured binding for std::ranges::subrange.
The `get` half of this machinery was already implemented, but the `tuple_size`
and `tuple_element` parts were hiding in [ranges.syn] and therefore missed.

Differential Revision: https://reviews.llvm.org/D108054
2021-08-18 10:01:45 -04:00
Arthur O'Dwyer 38812f4ac1 [libc++] [P1614] Implement std::compare_three_way_result.
Differential Revision: https://reviews.llvm.org/D103581
2021-08-18 10:01:24 -04:00
Louis Dionne 0166690401 [libc++] Remove workarounds for the lack of deduction guides in C++17
All supported compilers have supported deduction guides in C++17 for a
while, so this isn't necessary anymore.

Differential Revision: https://reviews.llvm.org/D108213
2021-08-18 08:57:25 -04:00
Louis Dionne b28cb53eac [libc++][NFC] Format expression-equivalent wrappers consistently
Differential Revision: https://reviews.llvm.org/D108144
2021-08-17 12:00:32 -04:00
Louis Dionne ceff0b7258 [libc++] Do not require movability in __non_propagating_cache::__emplace_deref
As explained in http://eel.is/c++draft/range.nonprop.cache#note-1, we
should allow copy and move elision to happen when calling emplace_deref
in non-propagating-cache. Before this change, the only way to emplace
into the non-propagating-cache was to call `__set(*it)`, which materialized
`*it` when binding it to the reference argument of `__set` and disabled
move elision.

As a fly-by change, this also renames `__set` to `__emplace` for consistency
and adds tests for it.

Differential Revision: https://reviews.llvm.org/D107932
2021-08-17 11:32:40 -04:00
zoecarver 9ed0778179 [libcxx][ranges] Move `namespace views` into `namespace ranges` and add an alias.
Differential Revision: https://reviews.llvm.org/D108047
2021-08-13 16:12:19 -07:00
zoecarver df324bba5c [libcxx][ranges] Add `ranges::join_view`.
Differential Revision: https://reviews.llvm.org/D107671
2021-08-13 11:31:08 -07:00
zoecarver 7b20e05c71 [libcxx][ranges] Add `ranges::iota_view`.
Differential Revision: https://reviews.llvm.org/D107396
2021-08-13 11:31:08 -07:00
zoecarver 4ac87e3378 [libcxx][ranges] Add `unreachable_sentinel`.
Differential Revision: https://reviews.llvm.org/D107920
2021-08-12 10:11:27 -07:00
Louis Dionne 7c81024a06 [libc++] Remove workarounds for missing __builtin_addressof
All supported compilers implement __builtin_addressof. Even MSVC implements
addressof as a simple call to __builtin_addressof, so it would work if we
were to port libc++ to that compiler.

Differential Revision: https://reviews.llvm.org/D107905
2021-08-11 17:05:12 -04:00
Arthur O'Dwyer c1a8f12873 [libc++] Restore `basic_ios`'s implicit conversion to `bool` in C++03 mode.
efriedma noted that D104682 broke this test case, reduced from SPEC2006.

    #include <istream>
    bool a(std::istream a) {
        return a.getline(0,0) == 0;
    }

We can unbreak it by restoring the conversion to something-convertible-to-bool.
We chose `void*` in order to match libstdc++.

For more ancient history, see PR19460: https://bugs.llvm.org/show_bug.cgi?id=19460

Differential Revision: https://reviews.llvm.org/D107663
2021-08-11 13:36:29 -04:00
Mark de Wever d2bc4fa3c7 [libc++][doc] Improve contributor documentation.
Addresses the post-commit review comments of D107596.
2021-08-11 17:33:54 +02:00
Louis Dionne 15071d2945 [libc++] Remove _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
All supported compilers have implemented __has_unique_object_representations
for a while, so it's reasonable to remove the workaround.

Differential Revision: https://reviews.llvm.org/D107834
2021-08-11 10:11:40 -04:00
Louis Dionne 7be03cc782 [libc++] Remove _LIBCPP_HAS_NO_IS_AGGREGATE
All supported compilers have been supporting __is_aggregate for a long
time now, so it's reasonable to remove this workaround.

Differential Revision: https://reviews.llvm.org/D107833
2021-08-11 10:10:53 -04:00
Louis Dionne 89a7bdb1f3 [libc++] Add the __bind_back and __compose helpers
Those are going to be used to implement range adaptors,
see D107098 for details.

Differential Revision: https://reviews.llvm.org/D107785
2021-08-11 10:08:20 -04:00
Arthur O'Dwyer e27f364c61 [libc++] IWYU to fix Modules complaints in <__ranges/reverse_view.h>.
And now we can use granular concepts headers!
2021-08-10 22:02:41 -04:00
Arthur O'Dwyer 58915667d0 [libc++][modularisation] Split up <concepts> into granular headers.
This is the complete split of <concepts>, with nothing left in the main header.

Differential Revision: https://reviews.llvm.org/D107584
2021-08-10 22:02:41 -04:00
zoecarver f9e58f35e9 [libcxx][ranges] Add `views::counted` CPO.
Differential Revision: https://reviews.llvm.org/D106923
2021-08-10 16:42:28 -07:00
Mark de Wever 1123100a16 [libcxx] Remove _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
All supported compilers should support
_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED so this can be removed.

Reviewed By: ldionne, #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D107239
2021-08-10 18:59:55 +02:00
zoecarver 9d982c67ba [libcxx][ranges] Add `ranges::reverse_view`.
Differential Revision: https://reviews.llvm.org/D107096
2021-08-09 15:09:59 -07:00
Louis Dionne f599e7a789 [libc++] Refactor __perfect_forward, bind_front and not_fn
This patch fixes the constrains on the __perfect_forward constructor
and its call operators, which were incorrect. In particular, it makes
sure that we closely follow [func.require], which basically says that
we must deliver the bound arguments with the appropriate value category
or make the call ill-formed, but not silently fall back to using a
different value category.

As a fly-by, this patch also:
- Adds types __bind_front_t and __not_fn_t to make the result of
  calling bind_front and not_fn more opaque, and improve diagnostics
  for users.
- Adds a bunch of tests for bind_front and remove some that are now
  redundant.
- Adds some missing _LIBCPP_HIDE_FROM_ABI annotations.

Immense thanks to @tcanens for raising awareness about this issue, and
providing help with the = delete bits.

Differential Revision: https://reviews.llvm.org/D107199
2021-08-09 15:32:00 -04:00
Mark de Wever 96ed451f8d [libc++][NFC] Remove MSVC specific code.
Switching `__builtin_clzll`  to `__libcpp_clz` should work on all
platforms and no longer require MSVC specific code.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D107709
2021-08-09 18:13:49 +02:00
Arthur O'Dwyer f221d905b1 [libc++] IWYU to fix Modules complaints about _LIBCPP_ASSERT. NFCI.
This fixes all places that used _LIBCPP_ASSERT without including <__debug>.

    git grep -l _LIBCPP_ASSERT | xargs git grep -L __debug
2021-08-06 09:20:59 -04:00
Arthur O'Dwyer ac42f76090 [libc++] s/_VSTD::_IsSame/_IsSame/. NFCI. 2021-08-05 23:29:53 -04:00
Arthur O'Dwyer 892990c56c [libc++] IWYU to fix complaints when compiling with Modules. NFCI.
Differential Revision: https://reviews.llvm.org/D107583
2021-08-05 14:30:08 -04:00
Mark de Wever d618a1cc5c [libc++] Improve LIBCXX_ENABLE_INCOMPLETE_FEATURES.
@tcanens pointed out the current behavior of the macro breaks the usage
pattern described in http://wg21.link/SD6
```
#  if __has_include(<optional>)
#    include <optional>
#    if __cpp_lib_optional >= 201606
#      define have_optional 1
#    endif
```

To support this usage pattern the hard errror is removed. Instead the
header includes nothing but the `<version>` header.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D107134
2021-07-30 14:36:03 -04:00
zoecarver 481ad59b9f [libcxx][ranges] Add `std::ranges::single_view`.
Differential Revision: https://reviews.llvm.org/D106840
2021-07-30 10:53:20 -07:00
Louis Dionne c99f5b2af1 [libc++] Handle arrays in std::destroy_at
Also, improve tests for std::destroy and std::destroy_n so that they
check for array support.

These changes are part of http://wg21.link/p0896 (the One Ranges proposal).

Differential Revision: https://reviews.llvm.org/D106916
2021-07-30 09:39:36 -04:00
Arthur O'Dwyer d4840175c9 [libc++] Remove excess whitespace in synopsis comment. NFCI. 2021-07-29 01:34:31 -04:00
Ruslan Arutyunyan 61c35fb0c2 [libc++][modularisation] Split <compare> into internal headers.
Differential Revision: https://reviews.llvm.org/D106107
2021-07-28 22:28:26 -04:00
Jason Liu 363a8a0598 [libc++] money_get::do_get() set failbit and eofbit if iterator begin equals end
Summary:
Currently, if we pass in the same iterator for begin and end,
the long double version of do_get would throw a runtime error.

However, according to standard (https://eel.is/c++draft/locale.money.get#virtuals-1),
we should set the failbit and eofbit when no more characters are available.

Differential Revision: https://reviews.llvm.org/D100510
2021-07-28 22:23:09 -04:00
Arthur O'Dwyer 3894a8a476 [libc++] Implement the resolutions of LWG3506 and LWG3522.
Implement the changes in all language modes.

LWG3506 "Missing allocator-extended constructors for priority_queue"
makes the following changes:
- New allocator-extended constructors for priority_queue.
- New deduction guides targeting those constructors.

LWG3522: "Missing requirement on InputIterator template parameter
for priority_queue constructors". The iterator parameter should be
constrained to actually be an iterator type. `priority_queue{1,2}`
should be SFINAE-friendly ill-formed.

Also, do a drive-by fix in the allocator-extended move constructor:
there's no need to do a `make_heap` after moving from `__q.c` into
our own `c`, because that container was already heapified when it
was part of `__q`. [priqueue.cons.alloc] actually specifies the
behavior and does *not* mention calling `make_heap`. I think this
was just a copy-paste thinko. It dates back to the initial import
of libc++.

Differential Revision: https://reviews.llvm.org/D106824
Differential Revision: https://reviews.llvm.org/D106827
2021-07-28 21:15:20 -04:00
zoecarver 0f4b41e038 [libcxx][ranges] Add ranges::take_view.
Differential Revision: https://reviews.llvm.org/D106507
2021-07-28 12:14:21 -07:00
Mark de Wever 4e65688571 [libc++][nfc] Improve error diagnostics.
The error message for disabled filesystem and locale support is now done
in the same fashion as ranges and format in D106763.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D106935
2021-07-28 17:57:23 +02:00
David Spickett 4fd42e2e80 [libcxx] Bump __libcpp_version to 14 after branch
This was missed in 08c766a731
and caused test failures in the buildkite bots:
libcpp_version.pass.cpp:22:1:
error: static_assert failed due to requirement '14000 == libcpp_version'
"_LIBCPP_VERSION doesn't match __libcpp_version
2021-07-28 11:07:06 +00:00
Tom Stellard 08c766a731 Bump the trunk major version to 14
and clear the release notes.
2021-07-27 21:58:25 -07:00
Louis Dionne 2e4755ff60 [libc++] Fix a few warnings in system headers with GCC
This isn't fixing all of them, but at least it's making some progress.

Differential Revision: https://reviews.llvm.org/D106283
2021-07-27 20:09:01 -04:00
zoecarver 8a48e6dda9 [libcxx][ranges] Add `counted_iterator`.
Differential Revision: https://reviews.llvm.org/D106205
2021-07-27 15:50:11 -07:00
Mark de Wever 71909de374 [libc++] Disable incomplete library features.
Adds a new CMake option to disable the usage of incomplete headers.
These incomplete headers are not guaranteed to be ABI stable. This
option is intended to be used by vendors so they can avoid their users
from code that's not ready for production usage.

The option is enabled by default.

Differential Revision: https://reviews.llvm.org/D106763
2021-07-27 22:37:35 +02:00
Marek Kurdej 775caa58fc [libc++] [c++2b] [P2166] Prohibit string and string_view construction from nullptr.
* https://wg21.link/P2166

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D106801
2021-07-27 16:20:21 +02:00
Christopher Di Bella 9563f3b571 [libcxx][NFC] adjusts 41b17c44 so it meets requested feedback
Feedback requested in D106735 applied in Diff 3 seem to have
reverted in Diff 4. This patch fixes that up.

Differential Revision: https://reviews.llvm.org/D106829
2021-07-27 01:11:04 +00:00
Arthur O'Dwyer 1e1b5706c3 [libc++] Fix spacing in <vector>. NFCI.
Thanks to gAlfonso-bit for the patch!

Differential Revision: https://reviews.llvm.org/D106691
2021-07-26 18:23:50 -04:00
Arthur O'Dwyer 41b17c444d [libc++] Fix signed overflow inside ranges::advance.
See LWG reflector thread of 2021-07-23 titled
'Question on ranges::advance and "past-the-sentinel iterators"'.
Test case heavily based on one graciously provided by Casey Carter.

Differential Revision: https://reviews.llvm.org/D106735
2021-07-26 16:41:21 -04:00
Arthur O'Dwyer 25666a74c5 [libc++] Remove "pass by const value" in <random>. NFCI. 2021-07-26 16:41:20 -04:00
Louis Dionne 7b28c5d376 [libc++] Implement the output_iterator and output_range concepts
Differential Revision: https://reviews.llvm.org/D106704
2021-07-26 15:05:17 -04:00
Louis Dionne fbaf7f0bc7 [libc++] Add range_size_t
Differential Revision: https://reviews.llvm.org/D106708
2021-07-26 12:19:26 -04:00
Louis Dionne 3ca6dea05d [libc++][NFC] Change a few instances of > > to >> in C++20 code 2021-07-26 11:22:47 -04:00
zoecarver e5d8b93e5a [libcxx][ranges] Add `ranges::common_view`.
Differential Revision: https://reviews.llvm.org/D105753
2021-07-23 09:08:49 -07:00
Louis Dionne f86570cd52 [libc++] Avoid triggering warnings for implicit conversion
This started as fixing a typo in a ADDITIONAL_COMPILE_FLAGS directive
which turned out to uncover a few places where we warned about signedness
changes.

As a fly-by fix, this updates the various __advance overloads
for style consistency.

Differential Revision: https://reviews.llvm.org/D106372
2021-07-23 10:53:10 -04:00
Christopher Di Bella 0cf65382ad [libcxx][modularisation] properly modularises advance, next, and prev
`__function_like` wasn't being exported, so certain properties of the
`ranges` functions weren't being propagated in modules land.

Differential Revision: https://reviews.llvm.org/D105078
2021-07-22 23:30:02 +00:00
Louis Dionne 3959c95deb [libc++] Add helper type non-propagating-cache
Differential Revision: https://reviews.llvm.org/D102121
2021-07-22 14:30:16 -04:00
Christopher Di Bella 74fd3cb8cd [libcxx][ranges] implements dangling, borrowed_iterator_t, borrowed_subrange_t
* Implements part of P0896 'The One Ranges Proposal'
* Implements http://wg21.link/range.dangling

Reviewed By: zoecarver

Differential Revision: https://reviews.llvm.org/D105205
2021-07-21 21:34:13 +00:00
Marek Kurdej 1daf0e2256 [libc++] Add `__libcpp_copysign` conditionally constexpr overloads.
This is a spin-off from D79555 review, that with this patch will be able to use `__libcpp_copysign` instead of adhoc `__copysign_constexpr` helper.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D106364
2021-07-21 16:57:43 +02:00
Mark de Wever b49961987f [lbc++][nfc] Use _LIBCPP_HIDE_FROM_ABI.
This replaces _LIBCPP_INLINE_VISIBILITY with _LIBCPP_HIDE_FROM_ABI. It's
not intended to do for other parts of libc++. This change makes it easy
to search and replace all occurrences of the patches in review.
2021-07-21 08:02:15 +02:00
zoecarver 1a29403d2f [libcxx][ranges] Add common_iterator.
Differential Revision: https://reviews.llvm.org/D103335
2021-07-20 08:12:44 -07:00
Louis Dionne d153e7d0a5 [libc++] Add a bunch of missing _LIBCPP_HIDE_FROM_ABI in <ranges>
We've been forgetting to add those to most of the <ranges> review.
To avoid forgetting in the future, I added an item in the pre-commit
checklist.

Differential Revision: https://reviews.llvm.org/D106287
2021-07-19 19:33:28 -04:00
Christopher Di Bella 182ba8ab1b [libcxx][ranges] makes `ranges::subrange` a borrowed range
Differential Revision: https://reviews.llvm.org/D106207
2021-07-17 17:25:56 +00:00
Christopher Di Bella e37bbfe59c [libcxx][modules] protects users from relying on libc++ detail headers (1/n)
libc++ has started splicing standard library headers into much more
fine-grained content for maintainability. It's very likely that outdated
and naive tooling (some of which is outside of LLVM's scope) will
suggest users include things such as `<__algorithm/find.h>` instead of
`<algorithm>`, and Hyrum's law suggests that users will eventually begin
to rely on this without the help of tooling. As such, this commit
intends to protect users from themselves, by making it a hard error for
anyone outside of the standard library to include libc++ detail headers.

This is the first of four patches. Patch #2 will solve the problem for
pre-processor `#include`s; patches #3 and #4 will solve the problem for
`<__tree>` and `<__hash_table>` (since I've never touched the test cases
that are failing for these two, I want to split them out into their own
commits to be extra careful). Patch #5 will concern itself with
`<__threading_support>`, which intersects with libcxxabi (which I know
even less about).

Differential Revision: https://reviews.llvm.org/D105932
2021-07-16 22:39:18 +00:00
Christopher Di Bella 6cb05ca392 [libcxx][modularisation] adds several headers to the module map
* <__algorithm/iter_swap.h>
* <__algorithm/swap_ranges.h>
* <__functional/is_transparent.h>
* <__memory/uses_allocator.h>
* <__ranges/drop_view.h>
* <__ranges/transform_view.h>
* <shared_mutex>
* <span>

Also updates header inclusions that were affected.

**NOTE:** This is a proper subset of D105932. Since the content has
already been LGTM'd, I intend to merge this patch without review,
pending green CI. I decided it would be better to move these changes
into their own commit since the former patch has undergone further
changes and will need yet another light review. In the event any of
that gets rolled back (for whatever reason), the changes in this patch
won't be affected.

Differential Revision: https://reviews.llvm.org/D106040
2021-07-16 16:06:54 +00:00
Louis Dionne 3001b48d76 [libc++] Implement views::all_t and ranges::viewable_range
Differential Revision: https://reviews.llvm.org/D105816
2021-07-15 07:54:33 -04:00
Arthur O'Dwyer 4118858b4e [libc++] NFCI: Restore code duplication in wrap_iter, with test.
It turns out that D105040 broke `std::rel_ops`; we actually do need
both a one-template-parameter and a two-template-parameter version of
all the comparison operators, because if we have only the heterogeneous
two-parameter version, then `x > x` is ambiguous:

    template<class T, class U> int f(S<T>, S<U>) { return 1; }
    template<class T> int f(T, T) { return 2; }  // rel_ops
    S<int> s; f(s,s);  // ambiguous between #1 and #2

Adding the one-template-parameter version fixes the ambiguity:

    template<class T, class U> int f(S<T>, S<U>) { return 1; }
    template<class T> int f(T, T) { return 2; }  // rel_ops
    template<class T> int f(S<T>, S<T>) { return 3; }
    S<int> s; f(s,s);  // #3 beats both #1 and #2

We have the same problem with `reverse_iterator` as with `__wrap_iter`.
But so do libstdc++ and Microsoft, so we're not going to worry about it.

Differential Revision: https://reviews.llvm.org/D105894
2021-07-14 20:10:52 -04:00
Louis Dionne f192616ce9 [libc++] NFC: Fix synopsis comments and sort includes in ranges 2021-07-12 09:56:09 -04:00
zoecarver 0e09a41b41 [libcxx][ranges] Add `ranges::transform_view`.
Reviewed By: cjdb, ldionne, #libc

Differential Revision: https://reviews.llvm.org/D103056
2021-07-09 10:13:57 -07:00
zoecarver 0849427fae [libcxx][nfc] Remove <variant>'s dependence on <array>.
This will allow us to use variant in common_iterator. We do this by introducing a new `__light_array` type that variant uses instead of `std::array`.

Differential Revision: https://reviews.llvm.org/D105597
2021-07-09 10:13:57 -07:00
Louis Dionne 74fb868942 [libc++] Add XFAIL for Clang ToT with modules
This is what I should have done instead of 6afd6e96ce.
2021-07-08 14:40:18 -04:00
Louis Dionne 6afd6e96ce [libc++] Workaround failures with modules on Clang ToT 2021-07-08 11:50:54 -04:00
Mark de Wever 321c2ea91c [libc++][NFC] Move monostate to its own header.
The format library uses `std::monostate`, but not a `std::variant`.
Moving `std::monostate` to its own header allows the format library to
reduce the amount of included code.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D105582
2021-07-08 17:35:26 +02:00
Louis Dionne 6829db727e [libc++] Implement copyable-box from Ranges
Differential Revision: https://reviews.llvm.org/D102135
2021-07-07 06:14:24 -04:00
Louis Dionne 5d2511c389 [libc++] NFC: Sort header lists and remove outdated comments in modulemap 2021-07-06 14:45:52 -04:00
Christopher Di Bella 8517a26d44 [libcxx][modularisation] splices `<iterator>` into individual headers
Differential Revision: https://reviews.llvm.org/D105076
2021-07-06 17:59:21 +00:00
Louis Dionne 681aa574c0 [libc++] NFC: Sort headers in CMakeLists.txt 2021-07-05 09:25:15 -04:00
wmbat 2ff5a56e1a [libcxx][type_traits] remove `std::is_literal_type` and `std::result_of` for C++20
C++17 deprecated `std::is_literal_type` and `std::result_of`, C++20 removed them.

Implements parts of:
    * P0174R2 'Deprecating Vestigial Library Parts in C++17'.
    * P0619R4 'Reviewing Deprecated Facilities of C++17 for C++20'.

Reviewed By: ldionne, Mordante, Quuxplusone, #libc

Differential Revision: https://reviews.llvm.org/D102992
2021-07-02 17:10:19 +00:00
Arthur O'Dwyer 64a0241d64 [libc++] IWYU <__utility/pair.h> in <__functional/hash.h>. NFCI.
This was the only thing preventing any one of our detail headers from
compiling on its own.
2021-07-01 18:12:30 -04:00
zoecarver edc1f0c12c [libcxx][ranges] Implement indirectly_swappable.
Differential Revision: https://reviews.llvm.org/D105304
2021-07-01 15:08:23 -07:00
jasonliu a319eafd16 [libc++] Provide c++03 alternative for va_copy if available in xlocale.h
Summary:
If we are on c++03 mode for some reason, and __builtin_va_copy is
available, then use it instead of error out on not having va_copy
in 03 mode.

Reviewed by: ldionne

Differential Revision: https://reviews.llvm.org/D100336
2021-07-01 18:02:38 +00:00
Christopher Di Bella 050b064f15 [libcxx][functional][modular] splices <functional> into modular headers
Differential Revision: https://reviews.llvm.org/D104942
2021-07-01 14:01:49 -04:00
zoecarver 000444214f [libcxx] Update optional star operator to be noexcept.
Differential Revision: https://reviews.llvm.org/D105296
2021-07-01 10:42:46 -07:00
Arthur O'Dwyer e5fbe9f315 [libc++] graph_header_deps.py: Detect files that include themselves.
This wasn't happening before, which led to one slipping in.
2021-06-30 17:37:43 -04:00
Louis Dionne a562853a51 [libc++] NFC: Fix return-by-const-value and pass-by-const-value typos
While we can debate on the value of passing by const value, there is no
arguing that it's confusing to do so in some circumstances, such as when
marking a pointer parameter as being const (did you mean a pointer-to-const?).
This commit fixes a few issues along those lines.
2021-06-29 13:57:04 -04:00
Louis Dionne d03aa7d6b6 [libc++] NFCI: Remove __functional/search.h
The __search helper function was once split into __functional for circular
dependency reasons, however this is not an issue anymore now that we have
finer grained headers.
2021-06-29 11:40:47 -04:00
Louis Dionne 7756216547 [libc++] NFCI: Remove code duplication and obsolete declarations in wrap_iter
Differential Revision: https://reviews.llvm.org/D105040
2021-06-29 10:51:07 -04:00
Arthur O'Dwyer a8d1182f66 [libc++] Remove some _LIBCPP_CXX03_LANG from iostreams headers.
With the STL containers, I didn't enable move operations in C++03 mode
because that would change the overload resolution for things that today
are copy operations. With iostreams, though, the copy operations aren't
present at all, and so I see no problem with enabling move operations
even in (Clang's greatly extended) C++03 mode.

Clang's C++03 mode does not support delegating constructors.

Differential Revision: https://reviews.llvm.org/D104310
2021-06-28 12:55:26 -04:00
Louis Dionne f32f3db9fc [libc++] Split the various iterator types out of <iterator>
Differential Revision: https://reviews.llvm.org/D104669
2021-06-28 12:25:40 -04:00
Jonathan Crowther 8d5c0b8768 [libc++] Remove unnecessary reinterpret_cast from typeinfo
In typeinfo there is a reinterpret_cast between a uintptr_t and size_t. These are two integer types and therefore a reinterpret_cast is not right for this situation. It looks like it may have been copied and pasted from above in the file. An implicit cast works in it's place.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D104814
2021-06-28 10:00:33 -04:00
Arthur O'Dwyer 585496803c [libc++] Enable the rvalue overloads of operator<< and operator>> even in C++03.
Continuing to eliminate no-longer-needed uses of _LIBCPP_CXX03_LANG.

Differential Revision: https://reviews.llvm.org/D104725
2021-06-25 14:59:58 -04:00
Mark de Wever e00969c0b7 [libc++][NFC] Rename include guard. 2021-06-25 17:34:30 +02:00
Christopher Di Bella 69d5a66621 [libcxx][modularisation] splits `<utility>` into self-contained headers
* moves `std::hash` and `std::unary_function` into `__functional`
* Everything else goes into `__utility/${NAME}.h`

Differential Revision: https://reviews.llvm.org/D104002
2021-06-25 00:29:01 +00:00
zoecarver 46afddec41 [libcxx][nfc] Update the synopsis comment in <ranges> to include drop_view. 2021-06-24 11:09:25 -07:00
zoecarver ba032a614a [libcxx][ranges] Enable borrowed range for drop view when T has borrowing enabled. 2021-06-24 11:09:25 -07:00
Christopher Di Bella 6adbc83ee9 [libcxx][modularisation] moves <utility> content out of <type_traits>
Moves:

* `std::move`, `std::forward`, `std::declval`, and `std::swap` into
  `__utility/${FUNCTION_NAME}`.
* `std::swap_ranges` and `std::iter_swap` into
  `__algorithm/${FUNCTION_NAME}`

Differential Revision: https://reviews.llvm.org/D103734
2021-06-24 17:57:29 +00:00
Christopher Di Bella d87f159ab6 [libcxx][NFC] removes `swap`'s dependency on `swap_ranges`
Under the as-if rule, we can directly implement the array overload for
`std::swap`. By removing this circular dependency where `swap` is
implemented in terms of `swap_ranges` and `swap_ranges` is defined in
terms of `swap`, we can split them into their own headers. This will:

* limit the surface area in which Hyrum's law can bite us;
* force users to include the correct headers;
* make finding the definitions trivial (`swap` is a utility;
  `swap_ranges` is an algorithm).

Differential Revision: https://reviews.llvm.org/D104760
2021-06-24 17:57:29 +00:00
zoecarver 3450398738 [libcxx][ranges] Add contiguous_range.
Differential Revision: https://reviews.llvm.org/D104262
2021-06-24 10:40:05 -07:00
zoecarver 560170fa2d [libcxx][views] Add drop_view.
The first view in the libc++ ranges library 🚀

Differential Revision: https://reviews.llvm.org/D102037
2021-06-23 10:10:50 -07:00
Christopher Di Bella cafae05619 [libcxx][NFC] prepares `<type_traits>` for moving out forward and swap
* `<type_traits>` depends on `std::forward`, so we replaced it with
  `static_cast<T&&>`.
* `swap`'s return type is confusing, so it's been rearranged to improve
   readabilitiy.
2021-06-23 01:23:45 +00:00
Louis Dionne 87dbe6c4ef [libc++] NFC: Add missing all.h to the modulemap 2021-06-22 13:47:41 -04:00
Arthur O'Dwyer 317e92a3e8 [libc++] Enable `explicit` conversion operators, even in C++03 mode.
C++03 didn't support `explicit` conversion operators;
but Clang's C++03 mode does, as an extension, so we can use it.
This lets us make the conversion explicit in `std::function` (even in '03),
and remove some silly metaprogramming in `std::basic_ios`.

Drive-by improvements to the tests for these operators, in addition
to making sure all these tests also run in `c++03` mode.

Differential Revision: https://reviews.llvm.org/D104682
2021-06-22 13:35:59 -04:00
zoecarver 40d6d2c49d [libcxx][ranges] Add `ranges::iter_swap`.
Differential Revision: https://reviews.llvm.org/D102809
2021-06-22 09:52:40 -07:00
Hyundeok Park 7adf713a5e [libc++] Change forward_list::swap to use propagate_on_container_swap for noexcept specification
The current implementation of `std::forward_list::swap` uses
`propagate_on_container_move_assignment` for `noexcept` specification.
This patch changes it to use `propagate_on_container_swap`, as it should.

Fixes https://llvm.org/PR50224.

Differential Revision: https://reviews.llvm.org/D101899
2021-06-22 12:42:02 -04:00
zoecarver 075f2370c7 [libcxx][ranges] Add `indirectly_movable` and `indirectly_movable_storable`.
Differential Revision: https://reviews.llvm.org/D102639
2021-06-21 12:39:25 -07:00
Fanbo Meng c02160c17b [libc++] Remove unused variable
Removing  `__current` as it becomes unused-but-set after 2cf78d4ead.

Reviewed By: ldionne, abhina.sreeskantharajan, #libc

Differential Revision: https://reviews.llvm.org/D104544
2021-06-21 11:39:53 -04:00
Raul Tambre 56aac567ac [libcxx] Implement P0883R2 ("Fixing Atomic Initialization")
Reviewed By: Quuxplusone

Differential Revision: https://reviews.llvm.org/D103769
2021-06-20 17:37:42 +03:00
Louis Dionne 134723edd5 [libcxx] Move all algorithms into their own headers
This is a fairly mechanical change, it just moves each algorithm into
its own header. This is intended to be a NFC.

This commit re-applies 7ed7d4ccb8, which was reverted in 692d7166f7
because the Modules build got broken. The modules build has now been
fixed, so we're re-committing this.

Differential Revision: https://reviews.llvm.org/D103583

Attribution note
----------------
I'm only committing this. This commit is a mix of D103583, D103330 and
D104171 authored by:

Co-authored-by: Christopher Di Bella <cjdb@google.com>
Co-authored-by: zoecarver <z.zoelec2@gmail.com>
2021-06-19 07:49:06 -04:00
Arthur O'Dwyer dd15c2723c [libc++] [P1518R2] Better CTAD behavior for containers with allocators.
P1518 does the following in C++23 but we'll just do it in C++17 as well:
- Stop requiring `Alloc` to be an allocator on some container-adaptor deduction guides
- Stop deducing from `Allocator` on some sequence container constructors
- Stop deducing from `Allocator` on some other container constructors (libc++ already did this)

The affected constructors are the "allocator-extended" versions of
constructors where the non-allocator arguments are already sufficient
to deduce the allocator type. For example,

    std::pmr::vector<int> v1;
    std::vector v2(v1, std::pmr::new_delete_resource());
    std::stack s2(v1, std::pmr::new_delete_resource());

Differential Revision: https://reviews.llvm.org/D97742
2021-06-18 15:54:46 -04:00
Louis Dionne 71e4d434dc [libc++] Make sure std::allocator<void> is always trivial
When we removed the allocator<void> specialization, the triviality of
std::allocator<void> changed because the primary template had a
non-trivial default constructor and the specialization didn't
(so std::allocator<void> went from trivial to non-trivial).

This commit fixes that oversight by giving a trivial constructor to
the primary template when instantiated on cv-void.

This was reported in https://llvm.org/PR50299.

Differential Revision: https://reviews.llvm.org/D104398
2021-06-17 16:11:50 -04:00
Christopher Di Bella d827af03bc [libcxx][module-map] 🎨 updates module map to account for ranges headers
Corresponding module map update for D104414, split out for rollback
reasons.

Differential Revision: https://reviews.llvm.org/D104415
2021-06-17 16:52:35 +00:00
Christopher Di Bella a22c55c69b [libcxx][iwyu] 🎨 adds more headers to IWYU
A few slipped through the cracks because D104175 and D104170 didn't
concern themselves with newer commits.

Differential Revision: https://reviews.llvm.org/D104414
2021-06-17 16:52:34 +00:00
Christopher Di Bella c5076d8371 Revert "Revert "[libcxx][module-map] creates submodules for private headers""
This reverts commit d9633f229c as a
workaround was discovered.

Differential Revision: https://reviews.llvm.org/D104170
2021-06-16 16:36:41 +00:00
Louis Dionne 87784cc6fb [libc++] Undeprecate the std::allocator<void> specialization
While the std::allocator<void> specialization was deprecated by
https://wg21.link/p0174#2.2, the *use* of std::allocator<void> by users
was not. The intent was that std::allocator<void> could still be used
in C++17 and C++20, but starting with C++20 (with the removal of the
specialization), std::allocator<void> would use the primary template.
That intent was called out in wg21.link/p0619r4#3.9.

As a result of this patch, _LIBCPP_ENABLE_CXX20_REMOVED_ALLOCATOR_MEMBERS
will also not control whether the explicit specialization is provided or
not. It shouldn't matter, since in C++20, one can simply use the primary
template.

Fixes http://llvm.org/PR50299

Differential Revision: https://reviews.llvm.org/D104323
2021-06-16 09:54:29 -04:00
Christopher Di Bella 332da1c283 [libcxx][iwyu] ensures we IWYU as prep for modules
This has been broken out of D104170 since it should be merged whether or
not we go ahead with the module map changes.

Differential Revision: https://reviews.llvm.org/D104175
2021-06-15 19:43:25 +00:00
Arthur O'Dwyer dc066888bd [libc++] [P0619] Add _LIBCPP_ABI_NO_BINDER_BASES and remove binder typedefs in C++20.
Differential Revision: https://reviews.llvm.org/D103753
2021-06-15 15:05:44 -04:00
Jordan Rupprecht 6d33362daf [libcxx][atomic] Fix failure mapping in compare_exchange_{strong,weak}.
https://eel.is/c++draft/atomics.types.operations#23 says: ... the value of failure is order except that a value of `memory_order::acq_rel` shall be replaced by the value `memory_order::acquire` and a value of `memory_order::release` shall be replaced by the value `memory_order::relaxed`.

This failure mapping is only handled for `_LIBCPP_HAS_GCC_ATOMIC_IMP`. We are seeing bad code generation for `compare_exchange_strong(cmp, 1, std::memory_order_acq_rel)` when using libc++ in place of libstdc++: https://godbolt.org/z/v3onrrq4G.

This was caught by tsan tests after D99434, `[TSAN] Honor failure memory orders in AtomicCAS`, but appears to be an issue in non-tsan code.

Reviewed By: ldionne, dvyukov

Differential Revision: https://reviews.llvm.org/D103846
2021-06-15 07:55:23 -07:00
zoecarver c820b494d6 [libcxx][ranges] Implement views::all.
Differential Revision: https://reviews.llvm.org/D102028
2021-06-14 10:41:00 -04:00
Louis Dionne 8e93aa304b [libc++] Refactor the tests for std::prev, next and advance
This started as an attempt to fix a GCC 11 warning of misplaced parentheses.
I then noticed that trying to fix the parentheses warning actually triggered
errors in the tests, showing that we were incorrectly assuming that the
implementation of ranges::advance was using operator+= or operator-=.

This commit fixes that issue and makes the tests easier to follow by
localizing the assertions it makes.

Differential Revision: https://reviews.llvm.org/D103272
2021-06-14 08:13:14 -04:00
zoecarver 7eba4856c7 [libcxx][ranges] Add class ref_view.
Differential Revision: https://reviews.llvm.org/D102020
2021-06-11 11:02:39 -07:00
Louis Dionne c54d3050f7 [libc++] NFC: Move indirect_concepts.h to __iterator/concepts.h
There's no fundamental reason to separate those from the other iterator
concepts.

Differential Revision: https://reviews.llvm.org/D104048
2021-06-11 12:57:04 -04:00
Louis Dionne f84dbd2f2b [libc++] Enable the synchronization library on Apple platforms
The synchronization library was marked as disabled on Apple platforms
up to now because we were not 100% sure that it was going to be ABI
stable. However, it's been some time since we shipped it in upstream
libc++ now and there's been no changes so far. This patch enables the
synchronization library on Apple platforms, and hence commits the ABI
stability as far as that vendor is concerned.

Differential Revision: https://reviews.llvm.org/D96790
2021-06-11 12:45:18 -04:00
zoecarver 9106047ee3 [libcxx][ranges] Add range.subrange.
Basically the title.

Differential Revision: https://reviews.llvm.org/D102006
2021-06-11 09:34:41 -07:00
Christopher Di Bella 462f8f0611 [libcxx][ranges] removes default_initializable from weakly_incrementable and view
also:

* removes default constructors from predefined iterators
* makes span and string_view views

Partially implements P2325.
Partially resolves LWG3326.

Differential Revision: https://reviews.llvm.org/D102468
2021-06-10 22:45:36 +00:00
Louis Dionne 859c924c5f [libc++] Remove unnecessary header in enable_view.h (which caused a cycle) 2021-06-10 16:35:30 -04:00
Christopher Di Bella bbb3d03f93 [libcxx][ranges][nfc] moves view concepts into `__ranges/concepts.h` 2021-06-10 19:35:00 +00:00
Christopher Di Bella 546449938a [libcxx][optional] adds missing constexpr operations
Makes the following operations constexpr:
  * `std::swap(optional, optional)`
  * `optional(optional<U> const&)`
  * `optional(optional<U>&&)`
  * `~optional()`
  * `operator=(nullopt_t)`
  * `operator=(U&&)`
  * `operator=(optional<U> const&)`
  * `operator=(optional<U>&&)`
  * `emplace(Args&&...)`
  * `emplace(initializer_list<U>, Args&&...)`
  * `swap(optional&)`
  * `reset()`

P2231 has been accepted by plenary, with the committee recommending
implementers retroactively apply to C++20. It's necessary for us to
implement _`semiregular-box`_ and _`non-propagating-cache`_, both of
which are required for ranges (otherwise we'll need to reimplement
`std::optional` with these members `constexpr`ified).

Differential Revision: https://reviews.llvm.org/D102119
2021-06-10 05:52:47 +00:00
Louis Dionne b648c611ed [libc++] Fix libc++ build with assertions enabled
This fixes http://llvm.org/PR50534. This is another take on D103960
which is less disruptive.

Differential Revision: https://reviews.llvm.org/D103964
2021-06-09 12:58:53 -04:00
Daniel McIntosh ee2a92c29d [libcxx] Remove VLA from libcxx locale header
The buffer size (`__nbuf`) in `num_put::do_put` is currently not an
integral/core constant expression. As a result, `__nar` is a Variable Length
Array (VLA). VLAs are a GNU extension and not part of the base C++ standard, so
unless there is good reason to do so they probably shouldn't be used in any of
the standard library headers. The call to `__iob.flags()` is the only thing
keeping `__nbuf` from being a compile time constant, so the solution here is to
simply err on the side of caution and always allocate a buffer large enough to
fit the base prefix.

Note that, while the base prefix for hex (`0x`) is slightly longer than the
base prefix for octal (`0`), this isn't a concern. The difference in the space
needed for the value portion of the string is enough to make up for this.
(Unless we're working with small, oddly sized types such as a hypothetical
`uint9_t`, the space needed for the value portion in octal is at least 1 more
than the space needed for the value portion in hex).

This PR also adds `constexpr` to `__nbuf` to enforce compile time const-ness
going forward.

Reviewed By: Mordante, #libc, Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D103558
2021-06-08 13:59:34 -04:00
Petr Hosek 692d7166f7 Revert "[libcxx][gardening] Move all algorithms into their own headers."
This reverts commit 7ed7d4ccb8 as it
uncovered a Clang bug PR50592.
2021-06-07 17:15:20 -07:00
Petr Hosek d9633f229c Revert "[libcxx][module-map] creates submodules for private headers"
This reverts commit f1417eb9b1 as it
uncovered a Clang bug PR50592.
2021-06-07 17:10:05 -07:00
Louis Dionne 85966df3aa [libc++] Rename 'and' to '&&' 2021-06-07 13:48:51 -04:00
Louis Dionne fb4e464618 [libc++] Simplify a few macros in __config
Several macros were guarded with a check along the lines of:

 #ifndef MACRO
 #  define MACRO ...
 #endif

However, some of these macros are never intended to be defined by users,
so it's pointless to make this check (i.e. the first #ifndef is always
true). This commit removes those checks.

The motivation for doing this cleanup is to remove the impression that
arbitrary configurations macros can be defined by users when including
libc++ headers, which doesn't work reliably and leads to macro spaghetti.
If one needs to be able to override a knob in the __config, that's fine,
but the proper way to do that is to document the macro as being a public
facing knob in the documentation, and most likely to migrate that macro
to __config_site (depending on the nature of the macro).

Differential Revision: https://reviews.llvm.org/D103705
2021-06-07 12:45:59 -04:00
Arthur O'Dwyer 469d18c064 [libc++] Fix result-type and value_type computation in <valarray>.
The `operator[]` of `_UnaryOp` and `_BinaryOp` returns the result of
calling `__op_`, so its return type should be `__result_type`, not
e.g. `_A0::value_type`. However, `_UnaryOp::value_type` also should
never have been `_A0::value_type`; it needs to be the correct type
for the result of the unary op, e.g. `bool` when the op is `logical_not`.

This turns out to matter when multiple operators are nested, e.g.
`+(v == v)` needs to have a `value_type` of `bool`, not `int`,
even when `v` is of type `valarray<int>`.

Differential Revision: https://reviews.llvm.org/D103416
2021-06-05 12:29:36 -04:00
zoecarver 89599e8b20 [libcxx][ranges] Add concepts in range.utility.helpers.
There are no changes to public APIs.

Differential Revision: https://reviews.llvm.org/D103493
2021-06-04 09:56:31 -07:00
zoecarver d31a2e7554 [libcxx][ranges] Add `ranges::empty_view`.
Differential Revision: https://reviews.llvm.org/D103208
2021-06-04 09:38:49 -07:00
zoecarver 7ed7d4ccb8 [libcxx][gardening] Move all algorithms into their own headers.
This is a fairly mechanical change, it just moves each algorithm into its own header. This is a NFC.

Note: during this change, I burned down all the includes, so this follows "include only and exactly what you use."

Differential Revision: https://reviews.llvm.org/D103583
2021-06-04 09:37:12 -07:00
Louis Dionne a9c9183ca4 [libc++] Use the using_if_exists attribute when provided
As discussed on cfe-dev [1], use the using_if_exists Clang attribute when
the compiler supports it. This makes it easier to port libc++ on top of
new platforms that don't fully support the C Standard library.

Previously, libc++ would fail to build when trying to import a missing
declaration in a <cXXXX> header. With the attribute, the declaration will
simply not be imported into namespace std, and hence it won't be available
for libc++ to use. In many cases, the declarations were *not* actually
required for libc++ to work (they were only surfaced for users to use
them as std::XXXX), so not importing them into namespace std is acceptable.

The same thing could be achieved by conscious usage of `#ifdef` along
with platform detection, however that quickly creates a maintenance
problem as libc++ is ported to new platforms. Furthermore, this problem
is exacerbated when mixed with vendor internal-only platforms, which can
lead to difficulties maintaining a downstream fork of the library.

For the time being, we only use the using_if_exists attribute when it
is supported. At some point in the future, we will start removing #ifdef
paths that are unnecessary when the attribute is supported, and folks
who need those #ifdef paths will be required to use a compiler that
supports the attribute.

[1]: http://lists.llvm.org/pipermail/cfe-dev/2020-June/066038.html

Differential Revision: https://reviews.llvm.org/D90257
2021-06-04 09:55:21 -04:00
Louis Dionne db757ba7c5 [libc++] Define _LIBCPP_NO_NATIVE_SEMAPHORES even outside of pthread
<semaphore> needs to know about whether native semaphores are supported
or not, even if we're not using the pthread API.
2021-06-03 18:18:42 -04:00
Louis Dionne e4d3a993c2 [libc++] Implement LWG3435 (constraints on reverse_iterator and move_iterator) 2021-06-03 15:49:41 -04:00
Christopher Di Bella f1417eb9b1 [libcxx][module-map] creates submodules for private headers
Most of our private headers need to be treated as submodules so that
Clang modules can export things correctly. Previous commits that split
monolithic headers into smaller chunks were unaware of this requirement,
and so this is being addressed in one fell swoop. Moving forward, most
new headers will need to have their own submodule (anything that's
conditionally included is exempt from this rule, which means `__support`
headers aren't made into submodules).

This hasn't been marked NFC, since I'm not 100% sure that's the case.

Differential Revision: https://reviews.llvm.org/D103551
2021-06-03 18:18:30 +00:00
Louis Dionne 2cf78d4ead [libc++] Remove unused variable warnings
Since D100581, Clang started flagging this variable which is set but
never read. Based on comparing this function with __match_at_start_posix_nosubs
(which is very similar), I am pretty confident that `__j` was simply left
behind as an oversight in Howard's 6afe8b0a23.

Also workaround some unused variable warnings in the <random> tests.
It's pretty lame that we're not asserting the skew and kurtosis of
the binomial and negative binomial distributions, but that should be
tackled separately.

Differential Revision: https://reviews.llvm.org/D103533
2021-06-03 09:43:08 -04:00
Louis Dionne 05d164b25c Revert "[libc++] NFC: Move unwrap_iter to its own header"
This reverts commit 924ea3bb53 *again*, this time because it broke the
LLDB build with modules. We need to figure out what's up with the libc++
modules build once and for all.

Differential Revision: https://reviews.llvm.org/D103369
2021-06-02 15:58:27 -04:00
Daniel McIntosh 06e047227d [libcxx][NFC] Tidy up calculation of __nbuf in num_put::do_put, and add comments
In 07ef8e6796 and 3ed9f6ebde, `__nbuf` started to diverge from the amount
of space that was actually needed for the buffer. For 32-bit longs for example,
we allocate a buffer that is one larger than needed. Moreover, it is no longer
clear exactly where the extra +1 or +2 comes from - they're just numbers pulled
from thin air. This PR cleans up how `__nbuf` is calculated, and adds comments
to further clarify where each part comes from.

Specifically, it corrects the underestimation of the max size buffer needed
that the above two commits had to compensate for. The root cause looks to be
the use of signed type parameters to numeric_limits<>::digits. Since digits
only counts non-sign bits, the calculation was acting as though (for a signed
64-bit type) the longest value we would print was 2^63 in octal. However,
printing in octal treats values as unsigned, so it is actually 2^64. Thus,
using unsigned types and changing the final +2 to a +1 is probably a better
option.

Reviewed By: #libc, ldionne, Mordante

Differential Revision: https://reviews.llvm.org/D103339
2021-06-02 11:46:17 -04:00
Louis Dionne 924ea3bb53 [libc++] NFC: Move unwrap_iter to its own header
This re-applies 9968896cd6, which was reverted in b13edf6e90 because
it broke the build.

Differential Revision: https://reviews.llvm.org/D103369
2021-06-01 21:46:59 -04:00
zoecarver 065cf3f9d7 [libcxx][ranges] Add `default_sentinel` and `default_sentinel_t`.
Refs https://eel.is/c++draft/default.sentinel and https://eel.is/c++draft/iterator.synopsis

Differential Revision: https://reviews.llvm.org/D103487
2021-06-01 14:03:54 -07:00
zoecarver 5671ff20d9 [libcxx] Implement view.interface.
This will unblock work on ranges::view. Based on D101396.

Refs http://eel.is/c++draft/view.interface.

Differential Revision: https://reviews.llvm.org/D101737
2021-06-01 12:34:47 -07:00
Martin Storsjö c8644ae1e9 [libcxx] Define LIBCPP_HAS_TIMESPEC_GET for MSVC configurations
This define was out of sync with the corresponding define in tests, it
was added inconsistently in 171c77b7da.

Modern MSVC environments do have these typedefs and functions.

Differential Revision: https://reviews.llvm.org/D103398
2021-05-31 22:13:22 +03:00
Christopher Di Bella bf92bdad77 [libcxx][nfc] moves std `advance`, `next`, and `prev` into their headers
Differential Revision: https://reviews.llvm.org/D103329
2021-05-31 17:14:52 +00:00
Louis Dionne 41bdf64d3e [libc++] Update all the pre-defined iterator types for C++20
Make sure we provide the correct It::difference_type member and update
the tests and synopses to be accurate.

Supersedes D102657 and D103101 (thanks to the original authors).

Differential Revision: https://reviews.llvm.org/D103273
2021-05-31 11:59:40 -04:00
Arthur O'Dwyer d39f5c3cb9 [libc++] Avoid `result_type` and `unary/binary_function` in <valarray>.
Give each of the relevant functional operators a `__result_type`
instead, so that we can keep using those typedefs in <valarray>
even when the public binder typedefs are removed in C++20.

Differential Revision: https://reviews.llvm.org/D103371
2021-05-31 11:29:16 -04:00
Arthur O'Dwyer bfbd73f87d [libc++] Alphabetize and include-what-you-use. NFCI.
Differential Revision: https://reviews.llvm.org/D102781
2021-05-29 19:54:48 -04:00
Arthur O'Dwyer c9385297ce [libc++] [modules] Add __threading_support to the modulemap.
It looks to me as if *every* helper header needs to be added to the modulemap,
actually; which is unfortunate since we keep proliferating them at such a
rapid pace.
2021-05-29 19:54:38 -04:00
Mark de Wever b13edf6e90 Revert "[libc++] NFC: Move unwrap_iter to its own header"
This reverts commit 9968896cd6.

This commit seems to cause the build failures of main.
2021-05-29 09:50:26 +02:00
Louis Dionne 9968896cd6 [libc++] NFC: Move unwrap_iter to its own header 2021-05-28 12:42:07 -04:00
Louis Dionne 58b29a4efc [libc++] Add all indirect callable concepts and projected
Differential Revision: https://reviews.llvm.org/D101277
2021-05-28 10:10:44 -04:00
Louis Dionne 1055cb91b4 [libc++] Deprecate std::iterator and remove it as a base class
C++17 deprecated std::iterator and removed it as a base class for all
iterator adaptors. We implement that change, but we still provide a way
to inherit from std::iterator in the few cases where doing otherwise
would be an ABI break.

Supersedes D101729 and the std::iterator base parts of D103101 and D102657.

Differential Revision: https://reviews.llvm.org/D103171
2021-05-27 11:34:04 -04:00
Christopher Di Bella 0dc7fd1bc1 [libcxx][iterator] adds `std::ranges::prev`
Implements part of P0896 'The One Ranges Proposal'.
Implements [range.iter.op.prev].

Depends on D102563.

Differential Revision: https://reviews.llvm.org/D102564
2021-05-27 04:41:27 +00:00
Christopher Di Bella 857fa7b7b1 [libcxx][iterator] adds `std::ranges::next`
Implements part of P0896 'The One Ranges Proposal'.
Implements [range.iter.op.next].

Depends on D101922.

Differential Revision: https://reviews.llvm.org/D102563
2021-05-27 04:41:26 +00:00
Mark de Wever 963495f0d4 [libc++][format] Adds availability macros for std::format.
This prevents std::format to be available until there's an ABI stable
version. (This only impacts the Apple platform.)

Depends on D102703

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D102705
2021-05-26 17:54:33 +02:00
Mark de Wever de9df3f5b9 [libc++][NFC] Move basic_format_parse_context to its own header.
This is a preparation to split the format header in smaller parts for the
upcoming patches.

Depends on D101723

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D102703
2021-05-26 17:50:09 +02:00
Mark de Wever 16342e3994 [libc++][NFC] Move format_error to its own header.
Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D101723
2021-05-26 17:43:23 +02:00
Christopher Di Bella 36d0fdf9ac [libcxx][iterator] adds `std::ranges::advance`
Implements part of P0896 'The One Ranges Proposal'.
Implements [range.iter.op.advance].

Differential Revision: https://reviews.llvm.org/D101922
2021-05-26 04:27:30 +00:00
Arthur O'Dwyer d42d9e10b6 [libc++] [P0619] Hide not1 and not2 under _LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS.
This also provides some of the scaffolding needed by D102992 and D101729, and mops up after D101730 etc.

Differential Revision: https://reviews.llvm.org/D103055
2021-05-25 16:57:16 -04:00
Martin Storsjö 3a6be27978 [libcxx] Make the visibility attributes consistent for __narrow_to_utf8/__widen_from_utf8
Use the same visiblity attributes as for all other template
specializations in the same file; declare the specialization itself
using _LIBCPP_TYPE_VIS, and don't use _LIBCPP_EXPORTED_FROM_ABI on
the destructor. Methods that are excluded from the ABI are marked
with _LIBCPP_INLINE_VISIBILITY.

This makes the vtable exported from DLL builds of libc++. Practically,
it doesn't make any difference for the CI configuration, but it
can make a difference in mingw setups.

Differential Revision: https://reviews.llvm.org/D102717
2021-05-25 22:57:16 +03:00
Arthur O'Dwyer fc9248877d [libc++] Assume that __wrap_iter always wraps a fancy pointer.
Not only do we conscientiously avoid using `__wrap_iter` for non-contiguous
iterators (in vector, string, span...) but also we make the assumption
(in regex) that `__wrap_iter<_Iter>` is contiguous for all `_Iter`.

So `__wrap_iter<reverse_iterator<int*>>` should be considered IFNDR,
and every `__wrap_iter` should correctly advertise contiguity in C++20.

Drive-by simplify some type traits.

Reviewed as part of https://reviews.llvm.org/D102781
2021-05-24 17:30:21 -04:00
zoecarver 8110a73164 [libcxx][gardening] Re-order includes across libcxx.
This commit alphabetizes all includes in libcxx. This is a NFC.

This can also serve as a pseudo "announcement" for how we should order these headers going forward (note: double underscores go before other headers).

Differential Revision: https://reviews.llvm.org/D102941
2021-05-21 13:22:10 -07:00
zoecarver 9db55b314b [libcxx][ranges] Add ranges::data CPO.
This is the second to last one! Based on D101396. Depends on D100255. Refs D101079 and D101193.

Differential Revision: https://reviews.llvm.org/D101476
2021-05-21 11:07:23 -07:00
zoecarver c40b02608e [libcxx][ranges] Implement `ranges::borrowed_range`.
Differential Revision: https://reviews.llvm.org/D102426
2021-05-20 11:51:44 -07:00
Christopher Di Bella d8fad66149 [libcxx][ranges] adds concept `sized_range` and cleans up `ranges::size`
* adds `sized_range` and conformance tests
* moves `disable_sized_range` into namespace `std::ranges`
* removes explicit type parameter

Implements part of P0896 'The One Ranges Proposal'.

Differential Revision: https://reviews.llvm.org/D102434
2021-05-19 18:16:45 +00:00
Amy Huang 7c2f58278e Apply [[standalone_debug]] to some types in the STL.
Add this attribute to some types to ensure that they have
debug info.
The debug info for these classes are required for debuggers to display
some STL types. With constructor homing (a new debug info optimization)
their debug info isn't emitted because their constructors are never
called.

The list of types with the attribute added are __hash_value_type,
__value_type, __tree_node_base, __tree_node, __hash_node, __list_node,
and __forward_list_node.

Differential Revision: https://reviews.llvm.org/D98750
2021-05-18 17:01:07 -07:00
Arthur O'Dwyer 06b40e80ae [libc++] Alphabetize header inclusions and include-what-you-use <__debug>. NFCI. 2021-05-18 19:56:30 -04:00
Arthur O'Dwyer e130fbe24e [libc++] Some fixes to the <bit> utilities.
Fix __bitop_unsigned_integer and rename to __libcpp_is_unsigned_integer.
There are only five unsigned integer types, so we should just list them out.
Also provide `__libcpp_is_signed_integer`, even though the Standard doesn't
consume that trait anywhere yet.

Notice that `concept uniform_random_bit_generator` is specifically specified
to rely on `concept unsigned_integral` and *not* `__is_unsigned_integer`.
Instantiating `std::ranges::sample` with a type `U` satisfying
`uniform_random_bit_generator` where `unsigned_integral<U::result_type>`
and not `__is_unsigned_integer<U::result_type>` is simply IFNDR.

Orthogonally, fix an undefined behavior in std::countr_zero(__uint128_t).

Orthogonally, improve tests for the <bit> manipulation functions.
It was these new tests that detected the bug in countr_zero.

Differential Revision: https://reviews.llvm.org/D102328
2021-05-18 19:56:30 -04:00
Kristina Bessonova a18b5f0188 [libcxx] NFC. Add missed articles to _LIPCPP_ASSERT messages in <list> 2021-05-17 10:15:43 +02:00
zoecarver bede7523b1 [libcxx][ranges] Add `contiguous_iterator`.
Differential Revision: https://reviews.llvm.org/D101396
2021-05-14 15:27:40 -07:00
zoecarver 98e4fd0701 [libcxx][ranges] Fix `ranges::empty` when begin, end, and empty members are provided.
Before this commit, we'd get a compilation error because the operator() overload was ambiguous.

Differential Revision: https://reviews.llvm.org/D102263
2021-05-13 10:07:57 -07:00
Kristina Bessonova 8a86787847 [libcxx] NFC. Fix misprint unodered -> unordered
Differential Revision: https://reviews.llvm.org/D102354
2021-05-13 09:57:29 +02:00
Christopher Di Bella 46c17429bc [libcxx] modifies `_CmpUnspecifiedParam` ignore types outside its domain
D85051's honeypot solution was a bit too aggressive swallowed up the
comparison types, which made comparing objects of different ordering
types ambiguous.

Depends on D101707.

Differential Revision: https://reviews.llvm.org/D101708
2021-05-13 00:45:39 +00:00
Mark de Wever c273f5ef7d [libc++][nfc] remove duplicated __to_unsigned.
Both `<type_traits>` and `<charconv>` implemented this function with
different names and a slightly different behavior. This removes the
version in `<charconv>` and improves the version in `<typetraits>`.

- The code can be used again in C++11.
-  The original claimed C++14 support, but `[[nodiscard]]` is not
   available in  C++14.
- Adds `_LIBCPP_INLINE_VISIBILITY`.

Reviewed By: zoecarver, #libc, Quuxplusone

Differential Revision: https://reviews.llvm.org/D102332
2021-05-12 21:09:49 +02:00
Kristina Bessonova 96100f1508 [libcxx] NFC. Correct wordings of _LIBCPP_ASSERT debug messages
Differential Revision: https://reviews.llvm.org/D102195
2021-05-12 13:49:57 +02:00