3175 Commits

Author SHA1 Message Date
Eric Fiselier
301501fb78 Avoid eager template instantiation caused by the variant narrowing checks.
The standard disallows narrowing conversions when constructing a variant.
This is checked by attempting to perform braced initialization of the
destination type from the argument type. However, braced initialization
can force the compiler (mostly clang) to eagerly instantiate the
constructors of the destintation type -- which can lead to errors in
a non-immediate context.

However, as variant is currently specified, the narrowing checks only
observably apply when the destination type is arithmetic. Meaning we can
skip the check for class types. Hense avoiding the hard errors.

In order to cause fewer build breakages, this patch avoids the narrowing
check except when the destination type is arithmetic.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@366022 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-14 18:21:15 +00:00
Eric Fiselier
478bb094b5 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).

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365973 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-12 23:01:48 +00:00
Eric Fiselier
6f5ab14489 Add option to disable variant narrowing conversion changes.
The paper P0608R3 - "A sane variant converting constructor" disallows
narrowing conversions in variant. It was meant to address this
surprising problem:

  std::variant<std::string, bool> v = "abc";
  assert(v.index() == 1); // constructs a bool.

However, it also disables every potentially narrowing conversion. For
example:

  variant<unsigned> v = 0; // ill-formed
  variant<string, double> v2 = 42; // ill-formed (int -> double narrows)

These latter changes break code. A lot of code. Within Google it broke
on the order of a hundred thousand target with thousands of root causes
responsible for the breakages.

Of the breakages related to the narrowing restrictions, none of them
exposed outstanding bugs. However, the breakages caused by boolean
conversions (~13 root causes), all but one of them were bugs.

For this reasons, I am adding a flag to disable the narrowing conversion
changes but not the boolean conversions one.

One purpose of this flag is to allow users to opt-out of breaking changes
in variant until the offending code can be cleaned up. For non-trivial
variant usages the amount of cleanup may be significant.

This flag is also required to support automated tooling, such as
clang-tidy, that can automatically fix code broken by this change.
In order for clang-tidy to know the correct alternative to construct,
it must know what alternative was being constructed previously, which
means running it over the old version of std::variant.

Because this change breaks so much code, I will be implementing the
aforementioned clang-tidy check in the very near future.

Additionally I'm plan present this new information to the committee so they can
re-consider if this is a breaking change we want to make.

I think libc++ should very seriously consider pulling this change
before the 9.0 release branch is cut. But that's a separate discussion
that I will start on the lists.

For now this is the minimal first step.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365960 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-12 21:32:11 +00:00
Louis Dionne
86f93e801c [libc++] Add XFAILs for CTAD tests on older compilers
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365923 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-12 17:30:57 +00:00
Eric Fiselier
6507e2af11 Mark destroying delete test as UNSUPPORTED with clang 7
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365856 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-12 01:16:08 +00:00
Marshall Clow
3c73561841 Reorganize the 'bit' header to make most of the facilities available for internal use pre-C++20. NFC for external users
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365854 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-12 01:01:55 +00:00
Eric Fiselier
f579c7c19d Fix memory leak in set and map.
When assigning an initializer list into set/map, libc++ would
leak memory if the initializer list contained equivalent keys
because we failed to check if the insertion was successful.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365840 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-11 23:13:38 +00:00
Louis Dionne
2980850307 [libc++] Implement deduction guides for <unordered_set>
Thanks to Arthur O'Dwyer for the patch.
Differential Revision: https://reviews.llvm.org/D58617

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365788 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-11 15:16:39 +00:00
Marshall Clow
7a377e25a4 Make forward_list::remove/remove_if/unique all return void before C++20; undoes that bit of D58332. Thanks to Mikhail Maltsev for pointing this out
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365290 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-08 03:45:28 +00:00
Eric Fiselier
47e6bb8620 Fix PR27658 - Make ~mutex trivial when possible.
Currently std::mutex has a constexpr constructor, but a non-trivial
destruction.

The constexpr constructor is required to ensure the construction of a
mutex with static storage duration happens at compile time, during
constant initialization, and not during dynamic initialization.
This means that static mutex's are always initialized and can be used
safely during dynamic initialization without the "static initialization
order fiasco".

A trivial destructor is important for similar reasons. If a mutex is
used during dynamic initialization it might also be used during program
termination. If a static mutex has a non-trivial destructor it will be
invoked during termination. This can introduce the "static
deinitialization order fiasco".

Additionally, function-local statics emit a guard variable around
non-trivially destructible types. This results in horrible codegen and
adds a runtime cost to every call to that function. non-local static's
also result in slightly worse codegen but it's not as big of a problem.

Example codegen can be found here: https://goo.gl/3CSzbM

Note: This optimization is not safe with every pthread implementation.
Some implementations allocate on the first call to pthread_mutex_lock
and free the allocation in pthread_mutex_destroy.

Also, changing the triviality of the destructor is not an ABI break.
At least to the best of my knowledge :-)

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365273 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-07 01:20:54 +00:00
Marshall Clow
da9535d479 Make list::remove/remove_if/unique all return void before C++20; undoes that bit of D58332. Thanks to Mikhail Maltsev for pointing this out
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365261 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-06 06:10:03 +00:00
Zoe Carver
5625778f5c This patch makes swap functions constexpr. Both swap overloads, swap_ranges and iter_swap are updated (with tests).
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365238 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-05 20:13:34 +00:00
Marshall Clow
7d00fc23cd Add tests for regex_match ambiguity (aka LWG2273). NFC. Reviewed as https://reviews.llvm.org/D63051
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365080 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-03 20:32:35 +00:00
Eric Fiselier
78af2bfb2f 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.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@365074 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-03 19:21:40 +00:00
Marshall Clow
e380104a43 Add a private call '__libcpp_is_constant_evaluated' which 'works' for old language versions and w/o any compiler support. 'Working', in this case, means that it returns false in those cases.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364873 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-01 23:16:46 +00:00
Marshall Clow
6062354517 Bit Operations: P0556, P0553 and P1355. Reviewed as: https://reviews.llvm.org/D51262
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364862 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-01 23:00:32 +00:00
Eric Fiselier
b87e5f52af Ensure bitset's string constructor doesn't poison the overload set.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364842 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-01 19:59:34 +00:00
Marshall Clow
b23844e251 Implement P0646R1: Erase-Like Algorithms Should Return size_type. Reviewed as https://reviews.llvm.org/D58332, and then updated because I rewrote a couple of those routines to eliminate some UB. Thanks to Zoe for tghe patch.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364840 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-01 19:22:00 +00:00
Marshall Clow
b10aebc767 Implement LWG2221: 'Formatted output for nullptr_t' Reviewed as: https://reviews.llvm.org/D63053
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364802 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-01 16:20:25 +00:00
Billy Robert O'Neal III
af4b988cfa [libcxx] [test] Add void cast to result of compare_exchange_weak to suppress [[nodiscard]].
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364732 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-01 08:09:02 +00:00
Marshall Clow
7779ab4a2d Add a missing '__uncvref_t' to the SFINAE constraints for optional's assignment operator. Fixes PR38638. Thanks to Jonathan Wakely for the report
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364574 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-27 18:40:55 +00:00
Marshall Clow
2c2308c5e3 Followup to revision 364545: Turns out that clang issues different errors for C++11 vs c++2a, so I tweaked the 'expected-error' bits that I added to match either of them.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364554 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-27 15:37:31 +00:00
Marshall Clow
e3f2980a56 Provide hashers for string_view only if they are using the default char_traits. Seen on SO: test/std/strings/string.view/string.view.hash/char_type.hash.fail.cpp
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364545 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-27 14:18:32 +00:00
Richard Smith
8b2d46d8a2 Fix test failures due to modified wording in Clang diagnostics.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364241 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-24 22:01:03 +00:00
Richard Smith
caf3bc5596 Fix test failures when using a custom ABI namespace.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364239 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-24 21:46:05 +00:00
Eric Fiselier
20f2ecc862 Use C++11 implementation of unique_ptr in C++03.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364161 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-23 20:47:21 +00:00
Eric Fiselier
90cd963b3b 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.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364160 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-23 20:28:29 +00:00
Eric Fiselier
cfab3381d3 Disable test by default
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364149 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-23 03:59:32 +00:00
Eric Fiselier
64cad861d6 Add super fast _IsSame trait for internal use.
Clang provides __is_same that doesn't produce any instantiations
and just returns a bool. It's a lot faster than using std::is_same

I'll follow up with a patch to actually start using it.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364148 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-23 03:58:41 +00:00
Eric Fiselier
80f67f31b4 Add new style meta-programming primatives.
Using class templates instead of alias templates causes a lot of
instantiations. As part of the move away from C++03, we want to
improve the efficiency of our meta-programming.

This patch lays the groundwork by introducing new _If, _EnableIf,
_And, _Or, and _IsValidExpansion (detect member). Future patches
will replace the existing implementations after verifying there
compile time differences.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364114 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-21 23:37:52 +00:00
Marshall Clow
52f76364dc Implement P0340R3: Make 'underlying_type' SFINAE-friendly. Reviewed as https://reviews.llvm.org/D63574
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364094 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-21 18:57:06 +00:00
Eric Fiselier
59c47a9425 Use rvalue references throughout the is_constructible traits.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364065 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-21 15:35:33 +00:00
Eric Fiselier
3f10018902 Make move and forward work in C++03.
These functions are key to allowing the use of rvalues and variadics
in C++03 mode. Everything works the same as in C++11, except for one
tangentially related case:

struct T {
  T(T &&) = default;
};

In C++11, T has a deleted copy constructor. But in C++03 Clang gives
it both a move and a copy constructor. This seems reasonable enough
given the extensions it's using.

The other changes in this patch were the minimal set required
to keep the tests passing after the move/forward change. Most notably
the removal of the `__rv<unique_ptr>` hack that was present
in an attempt to make unique_ptr move only without language support.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364063 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-21 15:20:55 +00:00
Eric Fiselier
3d80477aa2 Enable aligned_union in C++03
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364058 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-21 14:45:08 +00:00
Eric Fiselier
3cb5e8693b Get is_convertible tests passing in C++03 (except the fallback).
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364057 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-21 14:43:15 +00:00
Eric Fiselier
b62bdff2b5 Make rvalue metaprogramming traits work in C++03.
The next step is to get move and forward working in C++03.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@364053 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-21 14:31:34 +00:00
Zhihao Yuan
b0473a5282 [libc++] Recommit r363692 to implement P0608R3
Re-apply the change which was reverted in r363764 as-is after
breakages being resolved.  Thanks Eric Fiselier for working
hard on this.

See also: https://bugs.llvm.org/show_bug.cgi?id=42330

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


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363993 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-20 22:09:40 +00:00
Louis Dionne
e46f68502a [libc++] Take 2: Implement CTAD for map and multimap
This is a re-application of r362986 (which was reverted in r363688) with fixes
for the issue that caused it to be reverted.

Thanks to Arthur O'Dwyer for the patch.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363968 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-20 19:32:00 +00:00
Xing Xue
681171bd1e AIX system headers need stdint.h and inttypes.h to be re-enterable
Summary:
AIX system headers need stdint.h and inttypes.h to be re-enterable when macro _STD_TYPES_T is defined so that limit macro definitions such as UINT32_MAX can be found. This patch attempts to allow that on AIX.

Reviewers: hubert.reinterpretcast, jasonliu, mclow.lists, EricWF

Reviewed by: hubert.reinterpretcast, mclow.lists

Subscribers: jfb, jsji, christof, cfe-commits, libcxx-commits, llvm-commits

Tags: #LLVM, #clang, #libc++

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363939 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-20 15:36:32 +00:00
Zhihao Yuan
1d7f21ea6f [libc++] Revert r363692 which implements P0608R3
The change caused a large number of compiler failures in
Google's codebase.  People need time to evaluate the impact.



git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363764 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-19 07:11:08 +00:00
Marshall Clow
0662d025d5 Disable the 'nextafter' portions of these tests on PPC when using 128-bit doubles because the 'nextafter' call doesn't work right. Reviewed as https://reviews.llvm.org/D62384. Thanks to Xing Xue for the patch, and Hubert for the explanation.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363740 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-18 21:20:02 +00:00
Marshall Clow
389b4e6d63 Fix the floating point version of midpoint. It wasn't constexpr, among other things. Add more tests. As a drive-by, the LCD implementation had a class named '__abs' which did a 'absolute value to a common-type' conversion. Rename that to be '__ct_abs'.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363714 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-18 18:13:54 +00:00
Zhihao Yuan
f8f62ac93c [libc++] Implement P0608R3 - A sane variant converting constructor
Summary:
Prefer user-defined conversions over narrowing conversions and conversions to bool.

References:
 http://wg21.link/p0608

Reviewers: EricWF, mpark, mclow.lists

Reviewed By: mclow.lists

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

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363692 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-18 15:26:50 +00:00
Louis Dionne
8ea6252cec [libc++] Re-apply XFAIL to is_base_of test that was inadvertently reverted
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363689 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-18 15:01:59 +00:00
Louis Dionne
11aae354b9 [libc++] Revert the addition of map/multimap CTAD
This was found to be broken on Clang trunk. This is a revert of the
following commits (the subsequent commits added XFAILs to the tests
that were missing from the original submission):

    r362986: Implement deduction guides for map/multimap.
    r363014: Add some XFAILs
    r363097: Add more XFAILs
    r363197: Add even more XFAILs

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363688 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-18 14:40:15 +00:00
Marshall Clow
a5a011702c Add tests for LWG 3206. NFC
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363589 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-17 18:06:30 +00:00
Eric Fiselier
cd4a856d45 add header to help with template testing
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363503 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-15 21:16:57 +00:00
Louis Dionne
f6244f8e57 [libcxx] Add XFAIL for facet test when back-deploying to older macOS
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363405 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-14 14:40:38 +00:00
Louis Dionne
ead1950731 [libc++] Add missing #include in <cwchar> tests
Thanks to Mikhail Maltsev for the patch.
Differential Revision: https://reviews.llvm.org/D63289

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363290 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-13 18:24:28 +00:00
Louis Dionne
d7020fb087 [libcxx] XFAIL set/multiset CTAD tests on Apple Clang 10
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363209 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-12 22:01:05 +00:00