summaryrefslogtreecommitdiffstats
path: root/libcxx/include/variant
Commit message (Collapse)AuthorAgeFilesLines
* Improve compile time of variant.Eric Fiselier2019-07-141-31/+36
| | | | | | | | | | In particular, improve the compile time of the overload set builder that variant uses to determine which alternative to construct. Instead of having the __overload type construct itself recursively, this patch uses a flat construction for the overload set. llvm-svn: 366033
* Cleanup whitespace in <variant>. NFC.Eric Fiselier2019-07-141-11/+7
| | | | llvm-svn: 366026
* Avoid eager template instantiation caused by the variant narrowing checks.Eric Fiselier2019-07-141-8/+28
| | | | | | | | | | | | | | | | | | 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. llvm-svn: 366022
* Add option to disable variant narrowing conversion changes.Eric Fiselier2019-07-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. llvm-svn: 365960
* [libc++] Recommit r363692 to implement P0608R3Zhihao Yuan2019-06-201-2/+30
| | | | | | | | | | | | 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 llvm-svn: 363993
* [libc++] Revert r363692 which implements P0608R3Zhihao Yuan2019-06-191-30/+2
| | | | | | | The change caused a large number of compiler failures in Google's codebase. People need time to evaluate the impact. llvm-svn: 363764
* [libc++] Implement P0608R3 - A sane variant converting constructorZhihao Yuan2019-06-181-2/+30
| | | | | | | | | | | | | | | | | | 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 llvm-svn: 363692
* Update more file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | | 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
* [libcxx] Reorganize tests since the application of P0602R4Louis Dionne2019-01-101-4/+4
| | | | | | | | | | | | | | | | | Summary: P0602R4 makes the special member functions of optional and variant conditionally trivial based on the types in the optional/variant. We already implemented that, but the tests were organized as if this were a non-standard extension. This patch reorganizes the tests in a way that makes more sense since this is not an extension anymore. Reviewers: EricWF, mpark, mclow.lists Subscribers: christof, jkorous, dexonsmith, libcxx-commits Differential Revision: https://reviews.llvm.org/D54772 llvm-svn: 350884
* [NFC] Fix typo in commentLouis Dionne2018-12-211-1/+1
| | | | llvm-svn: 349932
* [libcxx] Add availability markup for bad_optional_access, bad_variant_access ↵Louis Dionne2018-11-191-1/+12
| | | | | | | | | | | | and bad_any_cast Reviewers: dexonsmith, EricWF Subscribers: christof, arphaman, libcxx-commits Differential Revision: https://reviews.llvm.org/D53256 llvm-svn: 347219
* Don't require relops on variant alternatives to all return the sameEric Fiselier2018-09-191-6/+16
| | | | | | | | | | | | type. Libc++ correctly asserts that a set of visitors for a variant all return the same type. However, we use the visitation machinary to perform relational operations. This causes a static assertion when some of the alternatives relops return a UDT which is implicitly convertible to bool instead of 'bool' exactly. llvm-svn: 342560
* Implement the infrastructure for feature-test macros. Very few actual ↵Marshall Clow2018-09-121-0/+1
| | | | | | feature test macros, though. Reviewed as: https://reviews.llvm.org/D51955 llvm-svn: 342073
* Fix ODR violation: namespace-scope helpers should not be declared 'static'.Richard Smith2018-08-271-1/+1
| | | | llvm-svn: 340778
* Partially Revert "Workaround GCC bug PR78489 - SFINAE order is not respected."Eric Fiselier2018-03-231-12/+17
| | | | | | | | | | This partially reverts commit r328261. The GCC bug has been fixed in trunk and has never existed in a released version. Therefore the changes to variant are unneeded. However, the additional tests have been left in place. llvm-svn: 328388
* Workaround GCC bug PR78489 - SFINAE order is not respected.Eric Fiselier2018-03-221-17/+12
| | | | | | | | | | | This patch works around variant test failures which are new to GCC 8. GCC 8 either doesn't perform SFINAE in lexical order, or it doesn't halt after encountering the first failure. This causes hard error to occur instead of substitution failure. See gcc.gnu.org/PR78489 llvm-svn: 328261
* While implementing P0777 - preventing unnecessary decay, I found some ↵Marshall Clow2018-02-121-7/+7
| | | | | | non-public uses of decay that could be replaced by __uncvref. NFC intented llvm-svn: 324895
* Implement P0777: Treating unnecessay decayMarshall Clow2018-02-061-4/+4
| | | | llvm-svn: 324398
* Implement most of P0607: Inline Variables for the Standard Library. This ↵Marshall Clow2018-01-021-4/+4
| | | | | | involved marking a lot of variables as inline (but only for C++17 and later). llvm-svn: 321658
* [libcxx] P0604, invoke_result and is_invocableZhihao Yuan2017-12-121-1/+1
| | | | | | | | | | | | | | | | | | | | Summary: Introduce a new form of `result_of` without function type encoding. Rename and split `is_callable/is_nothrow_callable` into `is_invocable/is_nothrow_invocable/is_invocable_r/is_nothrow_invocable_r` (and associated types accordingly) Change function type encoding of previous `is_callable/is_nothrow_callable` traits to conventional template type parameter lists. Reviewers: EricWF, mclow.lists, bebuch Reviewed By: EricWF, bebuch Subscribers: lichray, bebuch, cfe-commits Differential Revision: https://reviews.llvm.org/D38831 llvm-svn: 320509
* Fix min/max usage in variantEric Fiselier2017-11-191-0/+5
| | | | llvm-svn: 318622
* [libc++] Shrink variant's index type when possibleEric Fiselier2017-11-191-7/+32
| | | | | | | | | | | | | | | | | | | Summary: Currently `std::variant` always uses an unsigned int to store the variant index. However this isn't nessesary and causes `std::variant` to be larger than it needs to be in most cases. This patch changes the index type to be `unsigned char` when possible, and `unsigned short` or `unsigned int` otherwise, depending on the size (Although it's questionable if it's even possible to create a variant with 65535 elements. Unfortunately this change is an ABI break, and as such is only enabled in ABI v2. Reviewers: mpark Reviewed By: mpark Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40210 llvm-svn: 318621
* Add a missing SFINAE condition to the `variant`'s converting constructor.Michael Park2017-06-191-0/+2
| | | | | | | | | | | | | | | | | | | | | Remarks: This function shall not participate in overload resolution unless `is_same_v<decay_t<T>, variant>` is false, unless `decay_t<T>` is neither a specialization of `in_place_type_t` nor a specialization of `in_place_index_t`, unless `is_constructible_v<Tj, T>` is true, and unless the expression `FUN(std::forward<T>(t))` (with `FUN` being the above-mentioned set of imaginary functions) is well formed. Depends on D34111. Reviewers: EricWF, K-ballo Reviewed By: EricWF Subscribers: fhahn Differential Revision: https://reviews.llvm.org/D34112 llvm-svn: 305668
* Make tuple_element static_assert in pair if the index is out of range. Also, ↵Marshall Clow2017-06-121-1/+1
| | | | | | add a message to variant_alternative<> in the similar case (it already asserted). Add tests for this llvm-svn: 305196
* Implement LWG 2904.Michael Park2017-06-071-13/+8
| | | | | | | | | | | | | | | | | | | Summary: - Removed the move-constructibe requirement from copy-assignable. - Updated `__assign_alt` such that we direct initialize if `_Tp` can be `nothrow`-constructible from `_Arg`, or `_Tp`'s move construction can throw. Otherwise, construct a temporary and move it. - Updated the tests to remove the pre-LWG2904 path. Depends on D32671. Reviewers: EricWF, CaseyCarter Reviewed By: EricWF Differential Revision: https://reviews.llvm.org/D33965 llvm-svn: 304891
* Fix `std::visit` for the zero variants case.Michael Park2017-05-111-16/+7
| | | | | | | | | | | | | | | | | Summary: The following code is broken: ``` std::visit([]{}); ``` Reviewers: EricWF Reviewed By: EricWF Differential Revision: https://reviews.llvm.org/D33090 llvm-svn: 302773
* Fix GCC 7 test failures.Eric Fiselier2017-05-091-1/+1
| | | | | | | | | | | This patch fixes the test failures and unexpected passes that occur when testing against GCC 7. Specifically: * don't mark __gcd as always inline because it's a recursive function. GCC diagnoses this. * don't XFAIL the aligned allocation tests. GCC 7 supports them but not the -faligned-allocation option. * Work around gcc.gnu.org/PR78489 in variants constructors. llvm-svn: 302488
* Implement LWG 2857 for variant. Tests from Casey Carter @ Microsoft.Eric Fiselier2017-04-151-16/+18
| | | | | | | Also mark LWG 2857 as complete, since the changes to optional and any were completed by Marshall earlier. llvm-svn: 300403
* Implement P0599: 'noexcept for hash functions'. Fix a couple of hash ↵Marshall Clow2017-03-231-1/+1
| | | | | | functions (optional<T> and unique_ptr<T>) which were mistakenly marked as 'noexcept'. Reviewed as https://reviews.llvm.org/D31234 llvm-svn: 298573
* Fix PR31916 - std::visit rejects visitors accepting lvalue argumentsEric Fiselier2017-02-091-1/+1
| | | | | | | | | | A static assertion was misfiring since it checked is_callable<Visitor, decltype(__variant_alt<T>.value)>. However the decltype expression doesn't capture the value category as required. This patch applies extra braces to decltype to fix that. llvm-svn: 294612
* Fix variant build errors with GCC 7Eric Fiselier2017-02-051-2/+1
| | | | llvm-svn: 294141
* Implement P0513R0 - "Poisoning the Hash"Eric Fiselier2017-01-211-2/+4
| | | | | | | | | | | | | | | | | | | | | Summary: Exactly what the title says. This patch also adds a `std::hash<nullptr_t>` specialization in C++17, but it was not added by this paper and I can't find the actual paper that adds it. See http://wg21.link/P0513R0 for more info. If there are no comments in the next couple of days I'll commit this Reviewers: mclow.lists, K-ballo, EricWF Reviewed By: EricWF Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28938 llvm-svn: 292684
* Added a workaround for a `-fdelayed-template-parsing` bug.Michael Park2017-01-161-8/+13
| | | | | | | | | | | | | | | Summary: There seems to be an additional bug in `-fdelayed-template-parsing` similar to http://llvm.org/viewvc/llvm-project?view=revision&revision=236063. This is a workaround for it for <variant> to compile with `clang-cl` on Windows. Reviewers: EricWF Differential Revision: https://reviews.llvm.org/D28734 llvm-svn: 292097
* [NFC] Rename _LIBCPP_TYPE_VIS_ONLY to _LIBCPP_TEMPLATE_VISEric Fiselier2017-01-041-33/+33
| | | | | | | | | | | | | 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
* remove some inherited attributes on exceptionsSaleem Abdulrasool2016-12-311-1/+1
| | | | | | | | | | | | | | These exception types are marked with `_LIBCPP_EXCEPTION_ABI` which expands to `__attribute__((__visibility__("default")))` or `__declspec(dllexport)`. When building for Windows, we would hit an error: cannot apply 'dllexport' to a 'dllexport' class Remove the duplicate annotations as they will be inherited from the class. llvm-svn: 290785
* Choose better hash values for std::monostate and valueless variants.Eric Fiselier2016-12-041-2/+4
| | | | | | | | | | | Previously these hashes were 0 and -1 respectively. These seem like common sentinel values and should be avoided to prevent needless collisions. This patch changes those values to different arbitrary numbers, which should hopefully cause less collisions. Because I couldn't help myself I choose the fundamental constants for gravity and the speed of light. llvm-svn: 288623
* Fix <variant> w/o exception supportEric Fiselier2016-12-031-2/+12
| | | | llvm-svn: 288571
* Fix C++03 buildEric Fiselier2016-12-021-1/+1
| | | | llvm-svn: 288555
* Make variant's index part of the hash valueEric Fiselier2016-12-021-1/+3
| | | | llvm-svn: 288554
* Fix generated warnings in <variant>Eric Fiselier2016-12-021-4/+5
| | | | llvm-svn: 288552
* Implement C++17 <variant>. Patch from Michael Park!Eric Fiselier2016-12-021-0/+1553
This patch was reviewed as https://reviews.llvm.org/D23263. llvm-svn: 288547
OpenPOWER on IntegriCloud