Commit Graph

121 Commits

Author SHA1 Message Date
Louis Dionne 17f2d1cb9b [libc++] Fix QoI bug with construction of std::tuple involving std::any
In std::tuple, we should try to avoid calling std::is_copy_constructible
whenever we can to avoid surprising interactions with (I believe) compiler
builtins. This bug was reported in https://reviews.llvm.org/D96523#2730953.

The issue was that when tuple<_Up...> was the same as tuple<_Tp...>, we
would short-circuit the _Or (because sizeof...(_Tp) != 1) and go evaluate
the following `is_constructible<_Tp, const _Up&>...`. That shouldn't
actually be a problem, but see the analysis in https://reviews.llvm.org/D101770#2736470
for why it is with Clang and GCC.

Instead, after this patch, we check whether the constructed-from tuple
is the same as the current tuple regardless of the number of elements,
since we should always prefer the normal copy constructor in that case
anyway.

Differential Revision: https://reviews.llvm.org/D101770
2021-05-04 16:42:36 -04:00
Louis Dionne ef89e8ca1c [libc++] Fix constexpr-ness of std::tuple's constructor
Mentioned in https://reviews.llvm.org/D96523.
2021-04-30 15:55:10 -04:00
Louis Dionne a3ab5120fd [libc++] Rewrite the tuple constructors to be strictly Standards conforming
This nasty patch rewrites the tuple constructors to match those defined
by the Standard. We were previously providing several extensions in those
constructors - those extensions are removed by this patch.

The issue with those extensions is that we've had numerous bugs filed
against us over the years for problems essentially caused by them. As a
result, people are unable to use tuple in ways that are blessed by the
Standard, all that for the perceived benefit of providing them extensions
that they never asked for.

Since this is an API break, I communicated it in the release notes.
I do not foresee major issues with this break because I don't think the
extensions are too widely relied upon, but we can ship it and see if we
get complaints before the next LLVM release - that will give us some
amount of information regarding how much use these extensions have.

Differential Revision: https://reviews.llvm.org/D96523
2021-04-23 12:46:37 -04:00
Louis Dionne 4cd6ca102a [libc++] NFC: Normalize `#endif //` comment indentation 2021-04-20 12:03:32 -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
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
Louis Dionne 618862e89a [libc++] Fix incorrect forwarding in tuple's assignment operator
Also, add a bunch of tests for tuple and pair's assignment operators
involving reference types.

Differential Revision: https://reviews.llvm.org/D97419
2021-02-25 14:56:16 -05:00
Louis Dionne a0839b14df [libc++] Fix tuple assignment from types derived from a tuple-like
The implementation of tuple's constructors and assignment operators
currently diverges from the way the Standard specifies them, which leads
to subtle cases where the behavior is not as specified. In particular, a
class derived from a tuple-like type (e.g. pair) can't be assigned to a
tuple with corresponding members, when it should. This commit re-implements
the assignment operators (BUT NOT THE CONSTRUCTORS) in a way much closer
to the specification to get rid of this bug. Most of the tests have been
stolen from Eric's patch https://reviews.llvm.org/D27606.

As a fly-by improvement, tests for noexcept correctness have been added
to all overloads of operator=. We should tackle the same issue for the
tuple constructors in a future patch - I'm just trying to make progress
on fixing this long-standing bug.

PR17550
rdar://15837420

Differential Revision: https://reviews.llvm.org/D50106
2021-02-22 14:52:18 -05: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
David Blaikie e658b3eb97 PR43764: Qualify a couple of calls to forward_as_tuple to be ADL-resilient. 2019-10-28 18:04:41 -07: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 59e26308e6 [libc++] Take 2: Implement LWG 3158
Summary:
LWG 3158 marks the allocator_arg_t constructor of std::tuple as
conditionnally explicit based on whether the default constructors
of the tuple's members are explicitly default constructible.

This was previously committed as r372778 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/D65232

llvm-svn: 373092
2019-09-27 15:06:52 +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 e9e1c88ed9 [libc++] Implement LWG 3158
Summary:
LWG 3158 marks the allocator_arg_t constructor of std::tuple as
conditionnally explicit based on whether the default constructors
of the tuple's members are explicitly default constructible.

Reviewers: EricWF, mclow.lists

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

Tags: #libc

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

llvm-svn: 372778
2019-09-24 20:22:34 +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
Louis Dionne 1308011e1b [libc++] Implement CTAD for std::tuple
Summary:
We were using implicit deduction guides instead of explicit ones,
however the implicit ones don't do work anymore when changing the
constructors.

This commit adds the actual guides specified in the Standard to make
libc++ (1) closer to the Standard and (2) more resistent to changes
in std::tuple's constructors.

Reviewers: Quuxplusone

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

Tags: #libc

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

llvm-svn: 368599
2019-08-12 18:30:31 +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
Eric Fiselier 882fdf68b7 Fix non-conformance it `std::tuple`.
Previously we implemented all one trillion tuple-like constructors using
a single generic overload. This worked fairly well, except that it
differed in behavior from the standard version because it didn't
consider both T&& and T const&. This was observable for certain
types.

This patch addresses that issue by splitting the generic constructor
in two. We now provide both T&& and T const& versions of the
tuple-like constructors (sort of).

llvm-svn: 365973
2019-07-12 23:01:48 +00:00
Eric Fiselier f1807a7df6 Fix tuple's conditionally explicit constructors for very weird user
types.

It seems some people like to write types that can explicitly convert
to anything, but cannot be used to explicitly construct anything.

This patch makes tuple tolerate such types, as is required
by the standard.

llvm-svn: 365074
2019-07-03 19:21:40 +00:00
Eric Fiselier 3359a17b3a Apply new meta-programming traits throughout the library.
The new meta-programming primitives are lower cost than the old versions. This patch removes those old versions and switches libc++ to use the new ones.

llvm-svn: 364160
2019-06-23 20:28:29 +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 405570dc7a [libcxx] Make std::tuple<> trivially constructible
Summary:
This is not mandated by the Standard, but it's nonetheless a nice
property to have, especially since it's so easy to implement. It
also shrinks our bug list!

PR41714

Reviewers: mclow.lists, EricWF

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

Tags: #libc

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

llvm-svn: 363075
2019-06-11 15:02:10 +00:00
Eric Fiselier 7e528bc4ce Fix return type of std::tuple_cat.
When the arguments to tuple cat were const, the const was incorrectly
propagated into the type of the resulting tuple. For example:

const std::tuple<int> t(42);
auto r = std::tuple_cat(t, t);
// Incorrect! should be std::tuple<int, int>.
static_assert(is_same_v<decltype(r), std::tuple<const int, const int>>);

llvm-svn: 359255
2019-04-26 01:02:18 +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
Marshall Clow aa09911aef Add static_asserts to tuple's comparison operators to enforce the requirement that the tuples be the same size. See PR39183 for an example where we give unexpected results for this bad input case. With this change, we will reject it at compile-time
llvm-svn: 353450
2019-02-07 19:03:48 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

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: 351636
2019-01-19 08:50:56 +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 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
Louis Dionne d9247890da [NFC] Fix typo in <tuple>
llvm-svn: 346629
2018-11-12 01:28:07 +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
Marshall Clow 655c4695cf Implement P0777: Treating unnecessay decay
llvm-svn: 324398
2018-02-06 20:56:55 +00:00
Eric Fiselier b1539e0a0d Fix missing return in __tuple_leaf::__can_bind_reference when __reference_binds_to_temporary added in r323380.
llvm-svn: 323389
2018-01-24 23:10:02 +00:00
Eric Fiselier 292617e700 [libc++] Fix PR20855 -- libc++ incorrectly diagnoses illegal reference binding in std::tuple.
Summary:
See https://bugs.llvm.org/show_bug.cgi?id=20855

Libc++ goes out of it's way to diagnose `std::tuple` constructions which are UB due to lifetime bugs caused by reference creation. For example:

```
// The 'const std::string&' is created *inside* the tuple constructor, and its lifetime is over before the end of the constructor call.
std::tuple<int, const std::string&> t(std::make_tuple(42, "abc"));
```

However, we are over-aggressive and we incorrectly diagnose cases such as:

```
void foo(std::tuple<int const&, int const&> const&);
foo(std::make_tuple(42, 42));
```

This patch fixes the incorrectly diagnosed cases, as well as converting the diagnostic to use the newly added Clang trait `__reference_binds_to_temporary`. The new trait allows us to diagnose cases we previously couldn't such as:

```
std::tuple<int, const std::string&> t(42, "abc");
```

Reviewers: rsmith, mclow.lists

Reviewed By: rsmith

Subscribers: cfe-commits

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

llvm-svn: 323380
2018-01-24 22:14:01 +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
Casey Carter 00c872f353 workaround PR 28385 in __find_exactly_one_checked
Fixes #35578.

Differential Revision: D41048

llvm-svn: 320500
2017-12-12 17:22:24 +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
Eric Fiselier baaee20690 Add tests for class template deduction on std::tuple.
llvm-svn: 304967
2017-06-08 07:18:17 +00:00
Eric Fiselier def3c375e0 Rename unreserved names in tuple
llvm-svn: 304382
2017-06-01 02:14:21 +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
Eric Fiselier 9af60c4a8b Implement LWG 2773 - std::ignore should be constexpr.
In addition to the PR for LWG 2773 this patch also ensures
that each of std::ignores constructors or assignment operators
are constexpr.

llvm-svn: 294165
2017-02-06 01:25:31 +00:00
Eric Fiselier 5ddaeb888d Fix inconsistency in tuple's SFINAE. Patch from Andrey Khalyavin"
llvm-svn: 294106
2017-02-04 22:57:01 +00:00
Eric Fiselier b43f17c835 Fix std::tuples EBO when targeting the MSVC ABI.
MSVC/clang-cl doesn't do a full EBO unless __declspec(empty_bases)
is applied to the derived type. This causes certain tuple tests
to fail.

This patch adds the empty_bases attribute to __tuple_impl in order
for tuple to fully provide the EBO.

llvm-svn: 292159
2017-01-16 21:15:08 +00:00
Eric Fiselier e2f2d1edef [NFC] Rename _LIBCPP_TYPE_VIS_ONLY to _LIBCPP_TEMPLATE_VIS
The name _LIBCPP_TYPE_VIS_ONLY is no longer accurate because both
_LIBCPP_TYPE_VIS and _LIBCPP_TYPE_VIS_ONLY expand to
__attribute__((__type_visibility__)) with Clang. The only remaining difference
is that _LIBCPP_TYPE_VIS_ONLY can be applied to templates whereas
_LIBCPP_TYPE_VIS cannot (due to dllimport/dllexport not being allowed on
templates).

This patch renames _LIBCPP_TYPE_VIS_ONLY to _LIBCPP_TEMPLATE_VIS.

llvm-svn: 291035
2017-01-04 23:56:00 +00:00
Eric Fiselier 1013fe3c0c Re-implement LWG 2770 - Fix tuple_size with structured bindings.
This patch implements the correct PR for LWG 2770. It also makes the primary
tuple_size template incomplete again which fixes part of llvm.org/PR31513.

llvm-svn: 290846
2017-01-02 23:54:13 +00:00
Eric Fiselier 347a1cc221 Revert r289727 due to PR31384
This patch reverts the changes to tuple which fixed construction from
types derived from tuple. It breaks the code mentioned in llvm.org/PR31384.
I'll follow this commit up with a test case.

llvm-svn: 289773
2016-12-15 06:34:54 +00:00
Eric Fiselier f8136d08c6 [libcxx] Fix tuple construction/assignment from types derived from tuple/pair/array.
Summary:
The standard requires tuple have the following constructors:
```
tuple(tuple<OtherTypes...> const&);
tuple(tuple<OtherTypes...> &&);
tuple(pair<T1, T2> const&);
tuple(pair<T1, T2> &&);
tuple(array<T, N> const&);
tuple(array<T, N> &&);
```
However libc++ implements these as a single constructor with the signature:
```
template <class TupleLike, enable_if_t<__is_tuple_like<TupleLike>::value>>
tuple(TupleLike&&);
```

This causes the constructor to reject types derived from tuple-like types; Unlike if we had all of the concrete overloads, because they cause the derived->base conversion in the signature.

This patch fixes this issue by detecting derived types and the tuple-like base they are derived from. It does this by creating an overloaded function with signatures for each of tuple/pair/array and checking if the possibly derived type can convert to any of them.

This patch fixes [PR17550]( https://llvm.org/bugs/show_bug.cgi?id=17550)

This patch 

Reviewers: mclow.lists, K-ballo, mpark, EricWF

Subscribers: cfe-commits

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

llvm-svn: 289727
2016-12-14 22:22:38 +00:00
Eric Fiselier bd688258ba Fix PR27374 - Remove the implicit reduced-arity-extension in tuple.
This patch removes libc++'s tuple extension which allowed it to be
constructed from fewer initializers than elements; with the remaining
elements being default constructed. However the implicit version of
this extension breaks conforming code. For example:

    int fun(std::string);
    int fun(std::tuple<std::string, int>);
    int x = fun("hello"); // ambigious

Because existing code may already depend on this extension it can be re-enabled
by defining _LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION.

Note that the explicit version of this extension is still supported,
although it's somewhat less useful than the implicit one.

llvm-svn: 289158
2016-12-08 23:57:08 +00:00
Eric Fiselier 2371589266 Implement LWG 2770 - Make tuple_size<T> defined for all T
llvm-svn: 286779
2016-11-13 20:43:50 +00:00
Eric Fiselier 40905833b5 Fix PR30979 - tuple<move_only> is constructible from move_only const&
llvm-svn: 286774
2016-11-13 19:54:31 +00:00