Commit Graph

659 Commits

Author SHA1 Message Date
Eric Fiselier
3996cfb482 Add test for variant construction with duplicate types.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@366032 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-14 20:59:51 +00:00
Eric Fiselier
d13b2c9c44 Harden variant test added in r366022
The test was brittle since it only went boom for one specific type, when
really it should go boom for all of them.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@366025 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-14 18:30:34 +00:00
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
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
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
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
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
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
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
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
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
704a388bb7 Move libc++ specific tests for std::function out of the std directory
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363111 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-11 22:59:53 +00:00
Marshall Clow
88b46e4a16 XFAIL a couple of tests on apple-clang-9.1, which is a compiler that I didn't know existed
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363097 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-11 20:14:07 +00:00
Marshall Clow
dbcfe75325 Add a test for is_base_of and incomplete types. Because this trait uses a compiler intrinsic which was broken in many clangs, have lots of XFAILs.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@363029 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-11 03:38:29 +00:00
Zhihao Yuan
5a466fcca7 [libc++] Fix leading zeros in std::to_chars
Summary:
It is a bugfix proposal for https://bugs.llvm.org/show_bug.cgi?id=42166.

`std::to_chars` appends leading zeros if input 64-bit value has 9, 10 or 11 digits.
According to documentation `std::to_chars` must not append leading zeros:
https://en.cppreference.com/w/cpp/utility/to_chars

Changeset should not affect `std::to_chars` performance:
http://quick-bench.com/CEpRs14xxA9WLvkXFtaJ3TWOVAg

Unit test that `std::from_chars` supports compatibility for both `std::to_chars` outputs (previous and fixed one) already exists:
1f60111b59/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp (L63)

Reviewers: lichray, mclow.lists, ldionne, EricWF

Reviewed By: lichray, mclow.lists

Subscribers: zoecarver, christof, dexonsmith, libcxx-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@362967 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-10 17:11:46 +00:00
Eric Fiselier
5db0997bf6 Fix some incorrect std::function tests
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@362861 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-08 00:45:45 +00:00
Louis Dionne
0a3564fc0b [libcxx][test] Include test_workarounds.h where needed
Some tests require `TEST_WORKAROUND_CONSTEXPR_IMPLIES_NOEXCEPT`, but they
did not include the header that defines that macro.

Thanks to Michael Park for the patch.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@362660 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-05 21:54:34 +00:00
Marshall Clow
b6e011b18b Add include for 'test_macros.h' to all the tests that were missing them. Thanks to Zoe for the (big, but simple) patch. NFC intended.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@362252 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-31 18:35:30 +00:00
Marshall Clow
7cfbabcb84 Improve the test coverage for std::is_base_of
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@360911 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-16 15:56:26 +00:00
Marshall Clow
61ca0bbf14 Add a test for LWG#3204 and mark it as complete. Reviewed as https://reviews.llvm.org/D61829 Thanks to Zoe for the patch.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@360586 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-13 14:56:02 +00:00
Nico Weber
6807ed9b23 Mark is_trivially_destructible as unsupported with apple-clang-9
See discussion on https://reviews.llvm.org/D48292

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359907 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-03 17:26:17 +00:00
Eric Fiselier
35323b7f05 Support overaligned types in aligned_storage.
Summary:
The current implementation of aligned storage was written before we had `alignas`, so it used a list of builtin types to force the alignment. But this doesn't work overaligned requests.

This patch adds a fallback case supporting over-alignment. It only affects case that were previously ill-formed.

Reviewers: rsmith, ldionne, dlj, mclow.lists

Reviewed By: mclow.lists

Subscribers: mclow.lists, dexonsmith, libcxx-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359596 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-30 18:44:45 +00:00
Eric Fiselier
0ef0a7622b add tuple_cat test for const T
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359256 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-26 01:06:32 +00:00
Eric Fiselier
cc57a78190 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>>);

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359255 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-26 01:02:18 +00:00
Casey Carter
d8b79a0d07 [libc++][test] Fix noexcept assertions in variant's get tests
All constant expressions are non-potentially-throwing in C++14, but that is *not* the case in C++17. Change these tests of the `variant`-flavored overloads of `std::get` to expect the correct behavior when the compiler is not GCC or is GCC 9+.

Credit to Jonathan Wakely for providing an improved version of my initial change that validates the incorrect behavior on GCC < 9 as well as validating the correct behavior on other compilers.

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359220 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-25 18:36:29 +00:00
Marshall Clow
26ff1b3321 Update test to better check for the non-constexpr-ness of a move constructor. Fixes PR#41577.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359162 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-25 02:12:51 +00:00
Richard Smith
6892a8e351 Use modern type trait implementations when available.
Teach libcxx to stop using various deprecated __has_* type traits, in favor of
the ("modern", C++11 era) __is_* type traits.

This is mostly just a simplification, but fixes at least one bug: _Atomic T
should be considered trivially-destructible, but is not considered to be POD by
Clang, and __has_trivial_destructor is specified in the GCC documentation as
returning false for non-POD non-class types.

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


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359159 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-25 00:35:01 +00:00
Eric Fiselier
250205c9d2 Add std::is_constant_evaluated.
Clang recently added __builtin_is_constant_evaluated() and GCC 9.0
has it as well.

This patch adds support for it in libc++.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359119 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-24 17:54:25 +00:00
Marshall Clow
ef08906314 Make the test object callable. libstdc++'s bind checks that (libc++ currently does not). Thanks to Jonathan Wakely for the fix.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359108 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-24 15:33:55 +00:00
Marshall Clow
a123e7ac83 Add an any_cast test for array types. Thanks to Jonathan Wakely for the suggestion.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@359085 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-24 12:11:12 +00:00
Louis Dionne
0f60e0a4a0 [libc++] Fix error flags and exceptions propagated from input stream operations
Summary:
This is a re-application of r357533 and r357531. They had been reverted
because we thought the commits broke the LLDB data formatters, but it
turns out this was because only r357531 had been included in the CI
run.

Before this patch, we would only ever throw an exception if the badbit
was set on the stream. The Standard is currently very unclear on how
exceptions should be propagated and what error flags should be set by
the input stream operations. This commit changes libc++ to behave under
a different (but valid) interpretation of the Standard. This interpretation
of the Standard matches what other implementations are doing.

This effectively implements the wording in p1264r0. It hasn't been voted
into the Standard yet, however there is wide agreement that the fix is
correct and it's just a matter of time before the fix is standardized.

PR21586
PR15949
rdar://problem/15347558

Reviewers: mclow.lists, EricWF

Subscribers: christof, dexonsmith, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@357775 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-05 16:33:37 +00:00
Louis Dionne
d8ae8539a7 [libc++] Use std::is_nothrow_callable for std::invoke according to LWG 2807
Thanks to Zoe Carver for the patch.
Differential Revision: https://reviews.llvm.org/D58097

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@357616 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 17:54:37 +00:00
Louis Dionne
77c439298e [libc++][NFC] Rename test file according to the libc++ convention
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@357588 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 14:38:28 +00:00
Louis Dionne
ee85f7c135 Revert "[libc++] Fix error flags and exceptions propagated from input stream operations"
This reverts commits r357533 and r357531, which broke the LLDB
data formatters. I'll hold off until we know how to fix the data
formatters accordingly.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@357536 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-02 22:21:27 +00:00
Louis Dionne
59d894965e [libc++] Fix error flags and exceptions propagated from input stream operations
Summary:
Before this patch, we would only ever throw an exception if the badbit
was set on the stream. The Standard is currently very unclear on how
exceptions should be propagated and what error flags should be set by
the input stream operations. This commit changes libc++ to behave under
a different (but valid) interpretation of the Standard. This interpretation
of the Standard matches what other implementations are doing.

I will submit a paper in San Diego to clarify the Standard such that the
interpretation used in this commit (and other implementations) is the only
possible one.

PR21586
PR15949
rdar://problem/15347558

Reviewers: mclow.lists, EricWF

Subscribers: christof, dexonsmith, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@357531 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-02 21:43:07 +00:00
Louis Dionne
7b9927381c [libcxx] Make sure reference_wrapper works with incomplete types
Summary: Completes P0357R3, which was merged into the C++20 Working Draft in San Diego.

Reviewers: EricWF, mclow.lists

Subscribers: christof, jkorous, dexonsmith, libcxx-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@357423 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-01 19:53:44 +00:00
Louis Dionne
b857e811b3 [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

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@357411 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-01 16:39:34 +00:00