Commit Graph

132 Commits

Author SHA1 Message Date
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
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 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
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
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
Mark de Wever a354fd56c5 [libc++] Adds __utility/to_underlying.h.
During the review of D97115 it was mentioned adding the `<utility>`
header for `__to_underlying` was a bit unfortunate. Nowadays we tend to
implement smaller headers, so a good reason to move `std::to_underlying`
to its own header and adjust `<charconv>` to use the new header.

Differential Revision: https://reviews.llvm.org/D101233
2021-04-25 13:27:19 +02:00
Arthur O'Dwyer 5c40c994c3 [libc++] s/_LIBCPP_NO_HAS_CHAR8_T/_LIBCPP_HAS_NO_CHAR8_T/g
This was raised in D94511.

Differential Revision: https://reviews.llvm.org/D100736
2021-04-21 12:49:07 -04:00
Louis Dionne 4cd6ca102a [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -04:00
Kamlesh Kumar 36c3918ec5 [libc++] [C++20] [P0586] Implement safe integral comparisons
* https://wg21.link/P0586

Reviewed By: #libc, curdeius, Quuxplusone

Differential Revision: https://reviews.llvm.org/D94511
2021-04-20 04:52:59 +05:30
Arthur O'Dwyer 4b7bad9eae [libc++] Implement D2351R0 "Mark all library static cast wrappers as [[nodiscard]]"
These [[nodiscard]] annotations are added as a conforming extension;
it's unclear whether the paper will actually be adopted and make them
mandatory, but they do seem like good ideas regardless.

https://isocpp.org/files/papers/D2351R0.pdf

This patch implements the paper's effect on:
- std::to_integer, std::to_underlying
- std::forward, std::move, std::move_if_noexcept
- std::as_const
- std::identity

The paper also affects (but libc++ does not yet have an implementation of):
- std::bit_cast

Differential Revision: https://reviews.llvm.org/D99895
2021-04-12 12:29:15 -04:00
Arthur O'Dwyer 2d0f1fa472 [libc++] Header inclusion tests.
As mandated by the Standard's various synopses, e.g. [iterator.synopsis].
Searching the TeX source for '#include' is a good way to find all of these
mandates.

The new tests are all autogenerated by utils/generate_header_inclusion_tests.py.
I was SHOCKED by how many mandates there are, and how many of them
libc++ wasn't conforming with.

Differential Revision: https://reviews.llvm.org/D99309
2021-04-06 15:31:56 -04:00
Martin Storsjö 948dd664c3 [libcxx] Fix the type attribute for a couple templates
Use `_LIBCPP_TEMPLATE_VIS` instead of `_LIBCPP_TYPE_VIS` for a template
class.

This fixes the nodiscard_extensions.pass.cpp and a couple
func.search.default test cases when built in MSVC/DLL configurations.

Differential Revision: https://reviews.llvm.org/D99932
2021-04-06 19:54:34 +03:00
Arthur O'Dwyer 06e2b737aa [libc++] [P1032] Misc constexpr bits in <iterator>, <string_view>, <tuple>, <utility>.
This completes the implementation of P1032's changes to <iterator>,
<string_view>, <tuple>, and <utility> in C++20.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1032r1.html

Drive-by fix a couple of unintended rvalues in "*iterators*/*.fail.cpp".

Differential Revision: https://reviews.llvm.org/D96385
2021-03-25 10:34:35 -04:00
Marek Kurdej 43e4214173 [libc++] [C++2b] [P1682] Add to_underlying.
* https://wg21.link/P1682

Reviewed By: ldionne, Mordante, #libc

Differential Revision: https://reviews.llvm.org/D97365
2021-03-05 10:31:21 +01:00
Yuriy Chernyshov b526d87618 [libc++] Add std::hash<char8_t> specialization if char8_t is enabled
Differential Revision: https://reviews.llvm.org/D92325
2020-12-08 13:46:18 -05:00
Arthur O'Dwyer d586f92c94 [libc++] Consistently replace `std::` qualification with `_VSTD::` or nothing. NFCI.
I used a lot of `git grep` to find places where `std::` was being used
outside of comments and assert-messages. There were three outcomes:

- Qualified function calls, e.g. `std::move` becomes `_VSTD::move`.
    This is the most common case.

- Typenames that don't need qualification, e.g. `std::allocator` becomes `allocator`.
    Leaving these as `_VSTD::allocator` would also be fine, but I decided
    that removing the qualification is more consistent with existing practice.

- Names that specifically need un-versioned `std::` qualification,
    or that I wasn't sure about. For example, I didn't touch any code in
    <atomic>, <math.h>, <new>, or any ext/ or experimental/ headers;
    and I didn't touch any instances of `std::type_info`.

In some deduction guides, we were accidentally using `class Alloc = typename std::allocator<T>`,
despite `std::allocator<T>`'s type-ness not being template-dependent.
Because `std::allocator` is a qualified name, this did parse as we intended;
but what we meant was simply `class Alloc = allocator<T>`.

Differential Revision: https://reviews.llvm.org/D92250
2020-12-01 22:13:39 -05:00
Harald van Dijk fba0b65f72
[libc++] hash<long double>: adjust for x86-64 ILP32
x86-64 ILP32 mode (x32) uses 32-bit size_t, so share the code with ix86 to zero out padding bits, not with x86-64 LP64 mode.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D91349
2020-11-29 13:52:28 +00:00
Michael Schellenberger Costa 737a4501e8 Add constexpr to pair
Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D80558
2020-09-02 21:21:24 +02:00
Eric Fiselier c8ad8686ac Refactor default constructor SFINAE in pair and tuple.
Refactor the  recent implicit default constructor changes to match the
existing SFINAE style.

llvm-svn: 373263
2019-09-30 20:55:30 +00:00
Louis Dionne e16f2cb678 [libc++] Take 2: Implement LWG 2510
Summary:
LWG2510 makes tag types like allocator_arg_t explicitly default
constructible instead of implicitly default constructible. It also
makes the constructors for std::pair and std::tuple conditionally
explicit based on the explicit-ness of the default constructibility
for the pair/tuple's elements.

This was previously committed as r372777 and reverted in r372832 due to
the commit breaking LLVM's build in C++14 mode. This issue has now been
addressed.

Reviewers: mclow.lists

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

Tags: #libc

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

llvm-svn: 372983
2019-09-26 14:51:10 +00:00
Ilya Biryukov a3d337a9a7 Revert r372777: [libc++] Implement LWG 2510 and its follow-ups
This also reverts:
 - r372778: [libc++] Implement LWG 3158
 - r372782: [libc++] Try fixing tests that fail on GCC 5 and older
 - r372787: Purge mentions of GCC 4 from the test suite

Reason: the change breaks compilation of LLVM with libc++, for details see
http://lists.llvm.org/pipermail/libcxx-dev/2019-September/000599.html

llvm-svn: 372832
2019-09-25 09:10:38 +00:00
Louis Dionne 95411dd426 [libc++] Implement LWG 2510
Summary:
LWG2510 makes tag types like allocator_arg_t explicitly default
constructible instead of implicitly default constructible. It also
makes the constructors for std::pair and std::tuple conditionally
explicit based on the explicit-ness of the default constructibility
for the pair/tuple's elements.

Reviewers: mclow.lists, EricWF

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

Tags: #libc

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

llvm-svn: 372777
2019-09-24 20:18:54 +00:00
Zoe Carver b51d5605b1 Consolidate swap, swap_ranges, and iter_swap in <type_traits>.
NFC. Thanks to @Quuxplusone (Arthur O'Dwyer) for this change.

llvm-svn: 371639
2019-09-11 17:39:24 +00:00
Louis Dionne e35c5121da [NFC][libc++] Add missing EXPLICIT to pair and tuple synopsis
The constructors for std::pair and std::tuple have been made conditionally
explicit, however the synopsis in the headers do not reflect that.

llvm-svn: 366735
2019-07-22 20:45:23 +00:00
Zoe Carver 28e0187175 This patch makes swap functions constexpr. Both swap overloads, swap_ranges and iter_swap are updated (with tests).
llvm-svn: 365238
2019-07-05 20:13:34 +00:00
Bruce Mitchener ba41d3b1fd Fix -Wdouble-promotion warnings.
Reviewers: mclow.lists

Subscribers: christof, ldionne, cfe-commits, libcxx-commits

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

llvm-svn: 364798
2019-07-01 16:13:31 +00:00
Eric Fiselier 14d4869209 Apply [[nodebug]] to typedefs throughout the STL.
When applied to a typedef or alias template, the [[nodebug]] attribute
makes the typedef transparent to the debugger, so instead of seeing
`std::__function::__alloc_func<remove_reference<void(&)()>::type,
allocator<remove_reference<void(&)()>, void()>::_Target` you see
`void(&)()` as the type of the variable in your debugger.

Removing all this SFINAE noise from debug info has huge binary size
wins, in addition to improving the readability.

For now this change is on by default. Users can override it by
specifying -D_LIBCPP_NODEBUG_TYPE=

llvm-svn: 363117
2019-06-12 02:03:31 +00:00
Louis Dionne 2b0c7abba3 [libc++] Declare std::tuple_element as struct instead of class
Similarly to https://reviews.llvm.org/rL350972, this revision changes
std::tuple_element from class to struct.

Fixes PR41331.
Thanks to Jan Wilken Dörrie for the patch.

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

llvm-svn: 357411
2019-04-01 16:39:34 +00:00
Chandler Carruth 57b08b0944 Update more file headers across all of the LLVM projects in the monorepo
to reflect the new license. These used slightly different spellings that
defeated my regular expressions.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351648
2019-01-19 10:56:40 +00:00
Eric Fiselier d01a4aa068 Fix PR40230 - std::pair may have padding on FreeBSD.
Summary:
FreeBSD ships a very old and deprecated ABI for std::pair where the copy and move constructors are not allowed to be trivial. D25389 change how this was implemented by introducing a non-trivial base class. This patch, introduced in October 2016, introduced an ABI bug that caused nested `std::pair` instantiations to have padding. For example:

```
using PairT = std::pair< std::pair<char, char>, char >;
static_assert(offsetof(PairT, first) == 0, "First member should exist at offset zero"); // Fails on FreeBSD!
```

The bug occurs because the base class for the first element (the nested pair) cannot be put at offset zero because the top-level pair already has the same base class laid out there.

This patch fixes that ABI bug by templating the dummy base class on the same parameters as the pair.

Technically this fix is an ABI break for users who depend on the "broken" ABI introduced in 2016. I'm putting this up for review so that the FreeBSD maintainers can sign off on fixing the ABI by breaking the ABI.
Another option, since we have to "break" the ABI to fix it, would be to move FreeBSD off the deprecated non-trivial pair ABI instead.

Also see:

* https://llvm.org/PR40230
* https://reviews.llvm.org/D21329



Reviewers: rsmith, dim, emaste

Reviewed By: rsmith

Subscribers: mclow.lists, krytarowski, christof, ldionne, libcxx-commits

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

llvm-svn: 351290
2019-01-16 01:54:34 +00:00
Marshall Clow e495760140 Change from a to a . Fixes PR#39871.
llvm-svn: 350972
2019-01-11 21:57:12 +00:00
Louis Dionne 9f77b1a1de [pair] Mark constructors as conditionally noexcept
Summary:
std::tuple marks its constructors as noexcept when the corresponding
memberwise constructors are noexcept too -- this commit improves std::pair
so that it behaves the same.

This is a re-application of r348824, which broke the build in C++03 mode
because a test was marked as supported in C++03 when it shouldn't be.

Note:
I did not add support in the explicit and non-explicit `pair(_Tuple&& __p)`
constructors because those are non-standard extensions, and supporting them
properly is tedious (we have to copy the rvalue-referenceness of the deduced
_Tuple&& onto the result of tuple_element).

<rdar://problem/29537079>

Reviewers: mclow.lists, EricWF

Subscribers: christof, llvm-commits

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

llvm-svn: 348847
2018-12-11 14:22:28 +00:00
Louis Dionne d5a20703c4 Revert "[pair] Mark constructors as conditionally noexcept"
This broke the tests on Linux. Reverting until I find out why the tests
are broken (tomorrow).

llvm-svn: 348825
2018-12-11 02:32:46 +00:00
Louis Dionne 76cce3b2bd [pair] Mark constructors as conditionally noexcept
Summary:
std::tuple marks its constructors as noexcept when the corresponding
memberwise constructors are noexcept too -- this commit improves std::pair
so that it behaves the same.

Note:
I did not add support in the explicit and non-explicit `pair(_Tuple&& __p)`
constructors because those are non-standard extensions, and supporting them
properly is tedious (we have to copy the rvalue-referenceness of the deduced
_Tuple&& onto the result of tuple_element).

<rdar://problem/29537079>

Reviewers: mclow.lists, EricWF

Subscribers: christof, llvm-commits

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

llvm-svn: 348824
2018-12-11 02:17:23 +00:00
Louis Dionne bb9ca6d0bf [libcxx] Implement P0318: unwrap_ref_decay and unwrap_reference
Summary:
This was voted into C++20 in San Diego. Note that there was a revision
D0318R2 which did include unwrap_reference_t, but we mistakingly voted
P0318R1 into the C++20 Working Draft (which does not include
unwrap_reference_t). This patch implements D0318R2, which is what
we'll end up with in the Working Draft once this mistake has been
fixed.

Reviewers: EricWF, mclow.lists

Subscribers: christof, dexonsmith, libcxx-commits

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

llvm-svn: 348138
2018-12-03 14:03:27 +00:00
Fangrui Song 892bbd3f88 Fix -Wimplicit-fallthrough warning
Reviewers: EricWF, ldionne, mclow.lists

Reviewed By: ldionne

Subscribers: christof, libcxx-commits

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

llvm-svn: 346369
2018-11-07 23:51:13 +00:00
Louis Dionne 9b3222f613 [libc++] Make sure we can build libc++ with -fvisibility=hidden
Summary:
When building with -fvisibility=hidden, some symbols do not get exported from
libc++.dylib. This means that some entities are not explicitly given default
visibility in the source code, and that we rely on the fact -fvisibility=default
is the default. This commit explicitly gives default visibility to those
symbols to avoid being dependent on the command line flags used.

The commit also remove symbols from the dylib -- those symbols do not
actually need to be exported from the dylib and this should not be an
ABI break.

Finally, in the future, we may want to mark the whole std:: namespace as
having hidden visibility (to switch from opt-out to opt-in), in which
case the changes done in this commit will be required.

Reviewers: EricWF

Subscribers: mgorny, christof, dexonsmith, libcxx-commits

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

llvm-svn: 345260
2018-10-25 12:13:43 +00:00
Eric Fiselier 0b485f3e91 Fix even more Clang warnings.
This patch disables shift-sign-overflow warnings for now. It also
fixes most -Wfloat-equal warnings and -Wextra-semi warnings.

llvm-svn: 343438
2018-10-01 01:59:37 +00:00
Marshall Clow f56972e224 Implement the infrastructure for feature-test macros. Very few actual feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955
llvm-svn: 342073
2018-09-12 19:41:40 +00:00
Louis Dionne c8e84ff251 [libc++] Remove _LIBCPP_BUILDING_XXX macros, which are redundant since _LIBCPP_BUILDING_LIBRARY
Summary: As suggested by Marshall in https://reviews.llvm.org/D49914

Reviewers: mclow.lists, EricWF

Subscribers: christof, dexonsmith, cfe-commits

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

llvm-svn: 338475
2018-08-01 02:08:59 +00:00
Louis Dionne 14c922a240 [NFC] Add <initializer_list> to the synopsis of <utility>
Summary:
It is part of the synopsis in the Standard and <utility> does include it,
but it was left out of the synopsis comment.

Reviewers: EricWF, mclow.lists

Subscribers: christof, llvm-commits

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

llvm-svn: 336368
2018-07-05 16:16:03 +00:00
Marshall Clow 026b75f209 Fix a typo in the synopsis comment. NFC. Thanks to K-ballo for the catch
llvm-svn: 324851
2018-02-11 21:51:49 +00:00
Marshall Clow 8da1a487ae Last batch of P0202 constexpr additions: includes/set_intersection/exchange
llvm-svn: 323159
2018-01-22 23:10:40 +00:00
Marshall Clow c8531ebef9 Temporarily revert the inlining of 'piecewise_construct' because it is exported from the dylib.
llvm-svn: 321663
2018-01-02 18:57:47 +00:00
Marshall Clow 40a01d5314 Implement most of P0607: Inline Variables for the Standard Library. This involved marking a lot of variables as inline (but only for C++17 and later).
llvm-svn: 321658
2018-01-02 17:17:01 +00:00
Eric Fiselier af65856eec Add C++17 explicit deduction guides to std::pair.
This patch adds the newly standardized deduction guides
for std::pair, allowing it to work class template deduction.

llvm-svn: 314864
2017-10-04 00:04:26 +00:00
Michael Park 9cac9ad9d4 Add an `__is_inplace_index` metafunction.
Summary: This is used to constrain `variant`'s converting constructor correctly.

Reviewers: EricWF, mclow.lists

Reviewed By: EricWF, mclow.lists

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

llvm-svn: 305370
2017-06-14 05:51:18 +00:00
Marshall Clow 0c69d6e9bb Make tuple_element static_assert in pair if the index is out of range. Also, add a message to variant_alternative<> in the similar case (it already asserted). Add tests for this
llvm-svn: 305196
2017-06-12 16:13:17 +00:00
Eric Fiselier 77ad0d7089 Fix dllimport on a class template
llvm-svn: 300808
2017-04-20 01:45:15 +00:00
Eric Fiselier 2987087182 Cleanup remaining usages of _LIBCPP_HAS_NO_<c++11-feature> in tuple and utility
llvm-svn: 300644
2017-04-19 01:23:39 +00:00