Commit Graph

26 Commits

Author SHA1 Message Date
Louis Dionne
129504014a [libc++][NFC] Use struct instead of class for ranges::end
This is consistent with what we do elsewhere.
2022-03-22 15:36:47 -04:00
Joe Loser
d2baefae68
[libc++] Replace _LIBCPP_HAS_NO_CONCEPTS with _LIBCPP_STD_VER > 17. NFCI.
All supported compilers that support C++20 now support concepts. So, remove
`_LIB_LIBCPP_HAS_NO_CONCEPTS` in favor of `_LIBCPP_STD_VER > 17`. Similarly in
the tests, remove `// UNSUPPORTED: libcpp-no-concepts`.

Differential Revision: https://reviews.llvm.org/D121528
2022-03-13 12:32:06 -04:00
Arthur O'Dwyer
1c6e752cfc [libc++] Better handling for zero-sized types.
Zero-sized types are a GCC extension, also supported by Clang.
In theory it's already invalid to `delete` a void pointer or a
pointer-to-incomplete, so we shouldn't need any special code
to catch those cases; but in practice Clang accepts both
constructs with just a warning, and GCC even accepts `sizeof(void)`
with just a warning! So we must keep the static_asserts.
The hard errors are tested in `unique_ptr_dltr_dflt/*.compile.fail.cpp`.

In ranges::begin/end, check `sizeof >= 0` instead of `sizeof != 0`,
so as to permit zero-sized types while still disallowing incomplete
types.

Fixes #54100.

Differential Revision: https://reviews.llvm.org/D120633
2022-03-07 11:50:00 -05:00
Louis Dionne
368faacac7 [libc++] Revert "Protect users from relying on detail headers" & related changes
This commit reverts 5aaefa51 (and also partly 7f285f48e7 and b6d75682f9,
which were related to the original commit). As landed, 5aaefa51 had
unintended consequences on some downstream bots and didn't have proper
coverage upstream due to a few subtle things. Implementing this is
something we should do in libc++, however we'll first need to address
a few issues listed in https://reviews.llvm.org/D106124#3349710.

Differential Revision: https://reviews.llvm.org/D120683
2022-03-01 08:20:24 -05:00
Christopher Di Bella
5aaefa510e [libcxx][modules] protects users from relying on detail headers
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 <__ranges/access.h> instead of
<ranges>, 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.

Differential Revision: https://reviews.llvm.org/D106124
2022-02-26 09:00:25 +00:00
Konstantin Varlamov
55bd22f853 [libc++][ranges] Implement rbegin, rend, crbegin and crend.
Differential Revision: https://reviews.llvm.org/D119057
2022-02-14 03:29:59 -08:00
Konstantin Varlamov
e1e17a6489 [libc++][ranges][NFC] Refactor tests for ranges::{begin,end}.
- add some test cases for `cbegin`/`cend`;
- make class definitions generally follow the order in which they are
  used;
- add a missing include.

Reviewed By: philnik

Differential Revision: https://reviews.llvm.org/D119214
2022-02-11 15:15:51 -08:00
Arthur O'Dwyer
cc1d02ba2d [libc++] No longer support ranges::begin(x) when x is an array of incomplete type.
var-const points out that `ranges::begin` is (non-normatively
but explicitly) always supposed to return a `std::input_or_output_iterator`,
and `Incomplete*` is not a `std::input_or_output_iterator` because it
has no `operator++`. Therefore, we should never return `Incomplete*`
from `ranges::begin(x)`, even when `x` is `Incomplete(&)[]`. Instead,
just SFINAE away.

Differential Revision: https://reviews.llvm.org/D118963
2022-02-04 16:11:39 -05:00
Arthur O'Dwyer
fa6b9e4010 [libc++] Normalize all our '#pragma GCC system_header', and regression-test.
Now we'll notice if a header forgets to include this magic phrase.

Differential Revision: https://reviews.llvm.org/D118800
2022-02-04 12:27:19 -05:00
Nikolas Klauser
9c52a19e32 [libc++][NFC] Add namespace comments in ranges
With this patch there should be no more namespaces without closing comment

Reviewed By: ldionne, Quuxplusone, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D118668
2022-02-01 18:18:13 +01: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
Arthur O'Dwyer
a70fe03961 [libc++] [ranges] SFINAE away ranges::cbegin(const T&&) for non-borrowed T.
Fixes #52952.

Differential Revision: https://reviews.llvm.org/D116991
2022-01-12 13:25:41 -05:00
Arthur O'Dwyer
8507383631 [libc++] [ranges] ADL-proof the [range.access] CPOs.
For example, `std::ranges::range<Holder<Incomplete>*>` should be
well-formed false, not a hard error at compile time.

Differential Revision: https://reviews.llvm.org/D116239
2022-01-04 17:15:42 -05:00
Arthur O'Dwyer
502e5df0e0 [libc++] Implement ranges::{cbegin,cend} per the spec.
The big change here is that they now work as intended for rvalues,
e.g. `ranges::cbegin(std::string_view("hello"))`.
Also, add tests verifying their return types.

Differential Revision: https://reviews.llvm.org/D116199
2022-01-04 16:18:41 -05:00
Arthur O'Dwyer
3042091168 [libc++] [ranges] Whitespace and namespace-style adjustments. NFC.
Largely split out of D116199 to keep that PR smaller.
2021-12-23 14:56:23 -05:00
Arthur O'Dwyer
cb8a0b0797 [libc++] [ranges] Introduce _LIBCPP_AUTO_CAST(x) for auto(x).
Clang is gaining `auto(x)` support in D113393; sadly there
seems to be no feature-test macro for it. Zhihao is opening
a core issue for that macro.

Use `_LIBCPP_AUTO_CAST` where C++20 specifies we should use `auto(x)`;
stop using `__decay_copy(x)` in those places.
In fact, remove `__decay_copy` entirely. As of C++20, it's purely
a paper specification tool signifying "Return just `x`, but it was
perfect-forwarded, so we understand you're going to have to call
its move-constructor sometimes." I believe there's no reason we'd
ever need to do its operation explicitly in code.

This heisenbugs away a test failure on MinGW; see D112214.

Differential Revision: https://reviews.llvm.org/D115686
2021-12-22 12:29:42 -05:00
Arthur O'Dwyer
8ad364ad21 [libc++] [ranges] Remove the static_assert from ranges::begin and ranges::end.
As discussed with ldionne. The problem with this static_assert
is that it makes ranges::begin a pitfall for anyone ever to use
inside a constraint or decltype. Many Ranges things, such as ranges::size,
are specified as "Does X if X is well-formed, or else Y if Y is well-formed,
or else `ranges::end(t) - ranges::begin(t)` if that is well-formed, or else..."
And if there's a static_assert hidden inside `ranges::begin(t)`, then you get
a hard error as soon as you ask the question -- even if the answer would have
been "no, that's not well-formed"!

Constraining on `requires { t + 0; }` or `requires { t + N; }` is verboten
because of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103700 . For ranges::begin,
we can just decay to a pointer even in the incomplete-type case. For ranges::end,
we can safely constrain on `sizeof(*t)`. Yes, this means that an array of incomplete
type has a `ranges::begin` but no `ranges::end`... just like an unbounded array of
complete type. This is a valid manifestation of IFNDR.

All of the new libcxx/test/std/ cases are mandatory behavior, as far as I'm aware.
Tests for the IFNDR cases in ranges::begin and ranges::end remain in `libcxx/test/libcxx/`.
The similar tests for ranges::empty and ranges::data were simply wrong, AFAIK.

Differential Revision: https://reviews.llvm.org/D115838
2021-12-22 10:33:17 -05:00
Louis Dionne
eb8650a757 [runtimes][NFC] Remove filenames at the top of the license notice
We've stopped doing it in libc++ for a while now because these names
would end up rotting as we move things around and copy/paste stuff.
This cleans up all the existing files so as to stop the spreading
as people copy-paste headers around.
2021-11-17 16:30:52 -05: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
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
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
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
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
7e9cf2075a [libc++] s/begin.h/access.h/ in comments. NFCI. 2021-04-30 20:07:00 -04:00
Christopher Di Bella
5a3309f825 [libcxx][ranges] adds range access CPOs
* `std::ranges::begin`
* `std::ranges::cbegin`
* `std::ranges::end`
* `std::ranges::cend`
* `std::ranges::iterator` (required for `end`)

Implements parts of:
    * P0896R4 The One Ranges Proposal`

Co-author: @zoecarver

Depends on D90999, D100160.

Differential Revision: https://reviews.llvm.org/D100255
2021-04-30 16:56:42 +00:00