Commit Graph

3775 Commits

Author SHA1 Message Date
Arthur O'Dwyer bf150e8dab [libc++] [ranges] ADL-proof ranges::iter_{swap,move}.
As discovered in D117817, `std::ranges::input_range<Holder<Incomplete>*[10]>`
hard-errored before this patch. That's because `input_range` requires
`iter_rvalue_reference_t`, which requires `iter_move`, which was
not ADL-proofed.

Add ADL-proofing tests to all the range refinements.
`output_range` and `common_range` shouldn't be affected,
and all the others subsume `input_range` anyway, but we might as
well be thorough.

Differential Revision: https://reviews.llvm.org/D118213
2022-01-31 14:14:26 -05:00
Arthur O'Dwyer c965d5448e [libc++] [ranges] Implement std::ranges::distance
This includes an experimental workaround for
LWG3664 "LWG3392 broke std::ranges::distance(a, a+3)",
but the workaround may be incomplete, I'm not sure.
This should be re-audited when LWG3664 is actually adopted,
to see if we need to change anything about our implementation.

See also https://github.com/microsoft/STL/pull/2500

Differential Revision: https://reviews.llvm.org/D117940
2022-01-31 12:23:10 -05:00
Arthur O'Dwyer 23f73ff5f6 [libc++] [NFC] Audit LWG issues for "Nothing To Do" and "Complete".
Each "Nothing To Do" issue only changed nits in the English wording,
not anything to do with the code.
Each "Complete" issue was completed already, as far as I can tell.
I tried to err on the side of caution: I didn't mark a few issues
whose P/Rs were very invasive and would take time to verify, and I
didn't mark a lot of issues involving features we haven't even started
yet.

Differential Revision: https://reviews.llvm.org/D117960
2022-01-31 12:10:22 -05:00
Arthur O'Dwyer 2eb2ff2a02 [libc++] Merge _LIBCPP_HAS_NO_RANGES into _LIBCPP_HAS_NO_CONCEPTS. NFC.
The macro that opts out of `std::ranges::` functionality is called
`_LIBCPP_HAS_NO_INCOMPLETE_RANGES`, and is unrelated to this macro
which is specifically about _compiler_ support for the _syntax_.

The only non-mechanical diff here is in `<__config>`.

Differential Revision: https://reviews.llvm.org/D118507
2022-01-31 12:10:22 -05:00
Nikolas Klauser f3514af492 [libc++][ranges] Add ranges::in_in_out_result
Add `ranges::in_in_out_result`

Reviewed By: Quuxplusone, Mordante, #libc

Spies: CaseyCarter, libcxx-commits, mgorny

Differential Revision: https://reviews.llvm.org/D117512
2022-01-31 16:33:45 +01:00
Arthur O'Dwyer d1c4c75531 [libc++] Fix the last instances of `namespace ranges::inline...`. NFC.
Make these look the same as everywhere else.
2022-01-29 11:10:04 -05:00
Martin Storsjö de5d38ef2d [libcxx] Allow using thread safety annotations in MinGW mode
These were omitted in all Windows configurations, but it turns out
that they work just fine in MinGW mode.

This allows converting a couple cases of "XFAIL: LIBCXX-WINDOWS-FIXME"
into "XFAIL: msvc" as the bug is specific to MSVC mode (clang-cl).

Differential Revision: https://reviews.llvm.org/D118192
2022-01-28 11:20:58 +02:00
Arthur O'Dwyer bf20a09790 [libc++] [P1614] Implement the second half of [cmp.alg]: compare_{strong,weak,partial}_fallback.
The tests for these are just copy-pasted from the tests for std::{strong,weak,partial}_order,
and then I added an extra clause in each (test_2()) to test the stuff that's not just the same
as std::*_order.

This also includes the fix for https://wg21.link/LWG3465 (which falls naturally out of the
"you must write it three times" style, but I've added test cases for it also).

There is an action item here to go back and give good diagnostics for SFINAE failures
in these CPOs. I've filed this as https://github.com/llvm/llvm-project/issues/53456 .

Differential Revision: https://reviews.llvm.org/D111514
2022-01-27 17:48:01 -05:00
Brian Cain d5ab243c6f Omit atomic_{,un}signed_lock_free if unsupported
On targets that have limited atomic support, e.g. ones that define
ATOMIC_*_LOCK_FREE to '1' ("sometimes lock free"), we would end up
referencing yet-undefined __libcpp_{,un}signed_lock_free.

This commit adds a guard to prevent these references for such
targets.

Differential Revision: https://reviews.llvm.org/D118391
2022-01-27 14:29:08 -08:00
Arthur O'Dwyer 9021f3682c [libc++] [ranges] ref_view and empty_view are borrowed ranges. Normalize borrowed_range tests.
Differential Revision: https://reviews.llvm.org/D118164
2022-01-27 14:21:51 -05:00
Arthur O'Dwyer 8c98ce4dfa [libc++] Fix a typo in reverse_iterator::operator=.
We should be checking `is_assignable<It&, ...>`.
`is_assignable<It, ...>` checks for an rvalue left-hand side, which
is basically never assignable-to.
Found while looking into https://cplusplus.github.io/LWG/issue3435 .

Differential Revision: https://reviews.llvm.org/D117660
2022-01-27 14:21:50 -05:00
Louis Dionne d27cbfa9d3 [libc++] Fix bug in ranges::advance
In `ranges::advance(iter, n, bound)`, we'd incorrectly handle the case
where bound < iter and n is 0:

    int a[10];
    int *p = a+5;
    int *bound = a+3;
    std::ranges::advance(p, 0, bound);
    assert(p - a == 5); // we'd return 3 before this patch

This was caused by an incorrect handling of 0 inside __magnitude_geq.

Differential Revision: https://reviews.llvm.org/D117240
2022-01-27 10:57:54 -05:00
Louis Dionne 0902eb30ad [libc++] Fix common_iterator for output_iterators
We were missing a constraint in common_iterator's iterator_traits and
we were eagerly instantiating iter_value_t even when invalid.

Thanks to Casey Carter for finding this bug.

Differential Revision: https://reviews.llvm.org/D117449
2022-01-27 10:57:04 -05:00
Arthur O'Dwyer 7ea4fe7ede [libc++] Fix LWG3390: move_iterator now handles move-only iterators.
This can't really be tested until C++20 move_iterator is completely implemented.

Differential Revision: https://reviews.llvm.org/D117327
2022-01-26 23:50:26 -05:00
Arthur O'Dwyer 4b3e0d2a7e [libc++] Fix LWG3533 "Make `base() const&` consistent..."
Fixed in counted_iterator and transform_view::iterator.
The LWG issue also affected elements_view::iterator, but we haven't
implemented that one yet, and whoever does implement it will get
the fix for free if they just follow the working draft's wording.

Drive-by stop calling `.base()` on test iterators in the test,
and improve the transform_view::iterator/sentinel tests.

Differential Revision: https://reviews.llvm.org/D117329
2022-01-26 19:38:39 -05:00
Arthur O'Dwyer c99a585399 [libc++] Make C++03 reference_wrapper more like C++11.
Remove a bunch of LIBCPP_CXX03_LANG. This is the result of a
rabbithole to re-eliminate the workaround I introduced into
std::cref in D117953. It turns out that Clang's C++03 mode
(the only compiler we care about C++03 for) now supports all
the things we were originally eschewing via LIBCPP_CXX03_LANG;
we can fully support these reference_wrapper features in
C++03 mode, and un-XFAIL the relevant tests.

Drive-by constexprify a few more tests.

Differential Revision: https://reviews.llvm.org/D117974
2022-01-26 19:34:03 -05:00
Arthur O'Dwyer 16031cbf2b [libc++] Fix LWG3557 "static_cast expression in convertible_to has the wrong operand"
https://cplusplus.github.io/LWG/issue3557
I think the code change is unobservable, so we could just close this as
"Nothing To Do" instead; but it seems appropriate to follow the Standard's
wording here as closely as possible.

Differential Revision: https://reviews.llvm.org/D117964
2022-01-26 19:32:46 -05:00
Arthur O'Dwyer ff84c635b7 [libc++] [ranges] Fix LWG3470 "convertible-to-non-slicing seems to reject valid case"
Differential Revision: https://reviews.llvm.org/D117941
2022-01-26 19:30:12 -05:00
Arthur O'Dwyer a13c10588c [libc++] [test] Fix LWG3146 "Excessive unwrapping in std::ref/cref"
Drive-by constexprify the existing tests, too.

Differential Revision: https://reviews.llvm.org/D117953
2022-01-25 19:30:32 -05:00
Arthur O'Dwyer 8b29b84c99 [libc++] Fix LWG3422 "Issues of seed_seq's constructors"
https://cplusplus.github.io/LWG/issue3422

Also add a static_assert to check the "Mandates:" on the
iterator-pair constructor. Oddly, the `InputIterator` parameter
itself is merely preconditioned, not constrained, to satisfy the
input iterator requirements.

Also drive-by rename `init` to `__init`.

Differential Revision: https://reviews.llvm.org/D117962
2022-01-24 20:14:25 -05:00
Nikolas Klauser 014a673441 [libc++] Remove std::basic_string's base class in ABIv2
Remove `std::basic_string`'s base class in ABI version 2

Reviewed By: Quuxplusone, ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116334
2022-01-25 00:21:53 +01:00
Nikolas Klauser 52f37c24c3 [libc++][NFC] remove this-> when calling member functions in <string>
remove `this->` when calling member functions

Reviewed By: Quuxplusone, Mordante, ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116324
2022-01-25 00:21:51 +01:00
Louis Dionne 0407ab4114 [libc++] Make sure basic_string::reserve(n) never shrinks in all Standard modes
Since basic_string::reserve(n) is instantiated in the shared library but also
available to the compiler for inlining, its definition should not depend on
things like the Standard mode in use. Indeed, that flag may not match between
how the shared library is compiled and how users are compiling their own code,
resulting in ODR violations.

However, note that we retain the behavior of basic_string::reserve() to
shrink the string for backwards compatibility reasons. While it would
technically be conforming to not shrink, we believe user expectation is
for it to shrink, and so existing code might have been written based on
that assumption. We prefer to not break such code, even though that makes
basic_string::reserve() and basic_string::reserve(0) not equivalent anymore.

Fixes llvm-project#53170

Differential Revision: https://reviews.llvm.org/D117332
2022-01-24 15:43:13 -05:00
Mark de Wever 4684857abf [libc++][format] Finish P0645 Text Formatting.
This adjust the version macro and sets it as completed. All parts of the paper
have been implemented, except for the parts replaced by later papers and
LWG-issues.

Adjusted the synopsis to match the synopsis in the Standard. Not yet
implemented parts of P2216 and P2418 still use the P0645 wording.

Completes:
- P0645 Text Formatting

Depends on D115991

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D115999
2022-01-24 20:10:14 +01:00
Arthur O'Dwyer eadf7268d5 [libc++] Fix bugs in common_iterator; add test coverage.
Differential Revision: https://reviews.llvm.org/D117400
2022-01-24 13:45:38 -05:00
Mark de Wever ade6d0d8fa [libc++][format] Adds formatter handle.
This implements the handler according to P0645. P2418 changes the wording
in the Standard. That isn't implemented and requires changes in more
places. LWG3631 applies modifications to P2418, but is currently
unresolved.

Implements parts of:
* P0645 Text Formatting

Depends on D115989

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D115991
2022-01-24 18:15:08 +01:00
Mark de Wever 2b8b48c5a0 [libc++][format] Disable default formatter.
[format.formatter.spec]/5 lists the requirements for the default
formatter. The original implementation didn't implement this. This
implements the default formatter according to the Standard.

This adds additional test to validate the default formatter is disabled
and the required standard formatters are enabled.

While adding the tests it seems the formatters needed a constraint for the
character types they were valid for.

Implements parts of:
- P0645 Text Formatting

Depends on D115988

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D115989
2022-01-24 18:14:41 +01:00
Mark de Wever 787ccd345c [libc++][format] Adds formatter pointer.
This implements the last required formatter specialization.

Completes:
- LWG 3251 Are std::format alignment specifiers applied to string arguments?
- LWG 3340 Formatting functions should throw on argument/format string mismatch in §[format.functions]
- LWG 3540 §[format.arg] There should be no const in basic_format_arg(const T* p)

Implements parts of:
- P0645 Text Formatting

Depends on D114001

Reviewed By: ldionne, vitaut, #libc

Differential Revision: https://reviews.llvm.org/D115988
2022-01-24 18:13:02 +01:00
Mark de Wever db2944e34b [libc++][format] Adds formatter floating-point.
This properly implements the formatter for floating-point types.

Completes:
- P1652R1 Printf corner cases in std::format
- LWG 3250 std::format: # (alternate form) for NaN and inf
- LWG 3243 std::format and negative zeroes

Implements parts of:
- P0645 Text Formatting

Reviewed By: #libc, ldionne, vitaut

Differential Revision: https://reviews.llvm.org/D114001
2022-01-24 18:12:24 +01:00
Arthur O'Dwyer 5d78fef6db [libc++] Fix LWG3437 "__cpp_lib_polymorphic_allocator is in the wrong header"
https://cplusplus.github.io/LWG/issue3437

Differential Revision: https://reviews.llvm.org/D117963
2022-01-23 10:30:09 -05:00
Arthur O'Dwyer 938944445a [libc++] Mark LWG3541 as "Complete". NFC.
Differential Revision: https://reviews.llvm.org/D117956
2022-01-23 10:15:17 -05:00
Joe Loser 2513b79030
[libc++] Implement LWG3549: view_interface need not inherit from view_base
Implement LWG3549 by making `view_interface` not inherit from `view_base`. Types
are still views if they have a public and unambiguous derivation from
`view_interface`, so adjust the `enable_view` machinery as such to account for
that.

Differential Revision: https://reviews.llvm.org/D117714
2022-01-22 22:52:46 -05:00
Mark de Wever 26544b98f7 [libc++] Use addressof in unordered_set.
This addresses the usage of `operator&` in `<unordered_set>`.

(Note there are still more headers with the same issue.)

Reviewed By: #libc, philnik, Quuxplusone

Differential Revision: https://reviews.llvm.org/D117917
2022-01-22 11:41:13 +01:00
Muiez Ahmed 4f8ea3c84f [SystemZ][z/OS][NFC] Remove extra symbol 2022-01-21 16:18:46 -05:00
Mark de Wever d6e2c95d22 [libc++] Use addressof in unordered_map.
This addresses the usage of `operator&` in `<unordered_map>`.

(Note there are still more headers with the same issue.)

Reviewed By: #libc, Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D117393
2022-01-21 20:43:45 +01:00
Mark de Wever e4a556268e Revert "[libc++] Use addressof in unordered_map."
This reverts commit cab9616938.

This breaks the CI.
2022-01-21 17:59:07 +01:00
Mark de Wever cab9616938 [libc++] Use addressof in unordered_map.
This addresses the usage of `operator&` in `<unordered_map>`.

(Note there are still more headers with the same issue.)

Reviewed By: #libc, Quuxplusone, ldionne

Differential Revision: https://reviews.llvm.org/D117393
2022-01-21 17:34:29 +01:00
Casey Carter 864b5b49fd [libcxx] chrono::month_weekday should not be default constructible
It was not in P0355R7, nor has it ever been so in a working draft.

Drive-by:
* tests should test something: fix loop bounds so initial value is not >= final value
* calender type streaming tests are useless - let's remove them
* don't declare printf, especially if you don't intend to use it

Differential Revision: https://reviews.llvm.org/D117638
2022-01-20 11:47:56 -08:00
Arthur O'Dwyer 63a991d035 [libc++] Eliminate the `__function_like` helper.
As prefigured in the comments on D115315.
This gives us one unified style for all niebloids,
and also simplifies the modulemap.

Differential Revision: https://reviews.llvm.org/D116570
2022-01-20 14:40:16 -05:00
Nikolas Klauser 4822447522 [libc++] basic_string::resize_and_overwrite: Adopt LWG3645 (Not voted in yet)
Adopt LWG3645, which fixes the value categories of basic_string::resize_and_overwrite
https://timsong-cpp.github.io/lwg-issues/3645

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116815
2022-01-20 18:41:09 +01:00
Casey Carter 4e00a1921f [libcxx][test] compiler options are non-portable
... it's easier to suppress warnings internally, where we can detect the compiler.

* Rename `TEST_COMPILER_C1XX` to `TEST_COMPILER_MSVC`
* Rename all `TEST_WORKAROUND_C1XX_<meow>` to `TEST_WORKAROUND_MSVC_<meow>`

Differential Revision: https://reviews.llvm.org/D117422
2022-01-18 11:34:57 -08:00
Nikolas Klauser 275e7d197c [libc++][NFC] Use _LIBCPP_DEBUG_ASSERT in <unordered_map>
Use `_LIBCPP_DEBUG_ASSERT` in <unordered_map>

Reviewed By: ldionne, Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D117401
2022-01-18 20:31:02 +01:00
Alex Brachet 1dbe32dd9c [libc++] Use reserved identifier for template parameter
`T` is not a valid identifier for libc++ to use, use `_Tp` instead. Caught from D116957

Reviewed By: Quuxplusone

Differential Revision: https://reviews.llvm.org/D117582
2022-01-18 19:20:25 +00:00
Louis Dionne df51be85e4 [libc++] Split a few utilities out of __threading_support
This change is the basis for a further refactoring where I'm going to
split up the various implementations we have in __threading_support to
make that code easier to understand.

Note that I had to make __convert_to_timespec a template to break
circular dependencies. Concretely, we never seem to use it with anything
other than ::timespec, but I am wary of hardcoding that assumption as
part of this change, since I suspect there's a reason for going through
these hoops in the first place.

Differential Revision: https://reviews.llvm.org/D116944
2022-01-18 12:23:44 -05:00
Arthur O'Dwyer 459b4b725f [libc++] [API BREAK] Change `fs::path::iterator::iterator_category` to `input_iterator_tag`.
This essentially reverts e02ed1c255 and puts in a new fix, which makes `path::iterator`
a true C++20 `bidirectional_iterator`, but downgrades it to an `input_iterator` in C++17.

Fixes #37852.

Differential Revision: https://reviews.llvm.org/D116489
2022-01-17 16:33:23 -05:00
Nikolas Klauser caf5548c7c [libc++] Introduce __debug_db_insert_i()
Introduce `__debug_db_insert_i()`

Reviewed By: ldionne, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D117410
2022-01-17 20:31:21 +01:00
Nikolas Klauser 311207bbea [libc++][P2321R2] Add specializations of basic_common_reference and common_type for tuple
Add specializations of `basic_common_reference` and `common_type` for `tuple`

Reviewed By: ldionne, Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D116538
2022-01-17 19:49:57 +01:00
Nikolas Klauser d7630b37ce [libc++][NFC] Use _LIBCPP_DEBUG_ASSERT in <vector>
Use `_LIBCPP_DEBUG_ASSERT` in `<vector>`

Reviewed By: Quuxplusone, ldionne, Mordante, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D117402
2022-01-17 19:28:16 +01:00
Arthur O'Dwyer 0359b85c61 [libc++] [ABI BREAK] Conform lognormal_distribution::param_type.
Fixes #52906.

Differential Revision: https://reviews.llvm.org/D116344
2022-01-17 10:22:41 -05:00
Arthur O'Dwyer e93f98f09c [libc++] [test] Check for another kind of modulemap typo in lint_modulemap.sh.py.
Verify that the name of the private submodule matches the name of the detail header.

Differential Revision: https://reviews.llvm.org/D117438
2022-01-17 10:20:34 -05:00