diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:51:16 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:51:16 +0000 |
commit | 1147845301c03308e3419b89c28c77bb6917fe04 (patch) | |
tree | 225f45e462607f9595a5e5f418a9533ab50e83bb | |
parent | b7332b04df5d50c92640c74cfeb138ecb7e3f7ae (diff) | |
download | src-test2-1147845301c03308e3419b89c28c77bb6917fe04.tar.gz src-test2-1147845301c03308e3419b89c28c77bb6917fe04.zip |
Notes
219 files changed, 6814 insertions, 5326 deletions
diff --git a/LICENSE.TXT b/LICENSE.TXT index 190d9394d517..e159d283443f 100644 --- a/LICENSE.TXT +++ b/LICENSE.TXT @@ -1,5 +1,240 @@ ============================================================================== -libc++ License +The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: +============================================================================== + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + +============================================================================== +Software from third parties included in the LLVM Project: +============================================================================== +The LLVM Project contains third party software which is under different license +terms. All such code will be identified clearly using at least one of two +mechanisms: +1) It will be in a separate directory tree with its own `LICENSE.txt` or + `LICENSE` file at the top containing the specific license and restrictions + which apply to that software, or +2) It will contain specific license and restriction terms at the top of every + file. + +============================================================================== +Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy): ============================================================================== The libc++ library is dual licensed under both the University of Illinois diff --git a/include/__bit_reference b/include/__bit_reference index c208af2b4d76..cce74fb50236 100644 --- a/include/__bit_reference +++ b/include/__bit_reference @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -69,7 +68,7 @@ public: _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;} _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const _NOEXCEPT - {return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(__ctz(__mask_)));} + {return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(__libcpp_ctz(__mask_)));} private: _LIBCPP_INLINE_VISIBILITY __bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT @@ -141,7 +140,7 @@ public: {return static_cast<bool>(*__seg_ & __mask_);} _LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT - {return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__ctz(__mask_)));} + {return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__libcpp_ctz(__mask_)));} private: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR @@ -168,7 +167,7 @@ __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); __storage_type __b = *__first.__seg_ & __m; if (__b) - return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b))); if (__n == __dn) return __first + __n; __n -= __dn; @@ -177,14 +176,14 @@ __find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type // do middle whole words for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) if (*__first.__seg_) - return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(*__first.__seg_))); + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(*__first.__seg_))); // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b = *__first.__seg_ & __m; if (__b) - return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b))); } return _It(__first.__seg_, static_cast<unsigned>(__n)); } @@ -204,7 +203,7 @@ __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); __storage_type __b = ~*__first.__seg_ & __m; if (__b) - return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b))); if (__n == __dn) return __first + __n; __n -= __dn; @@ -215,7 +214,7 @@ __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type { __storage_type __b = ~*__first.__seg_; if (__b) - return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b))); } // do last partial word if (__n > 0) @@ -223,7 +222,7 @@ __find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); __storage_type __b = ~*__first.__seg_ & __m; if (__b) - return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b))); + return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b))); } return _It(__first.__seg_, static_cast<unsigned>(__n)); } @@ -255,18 +254,18 @@ __count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); __storage_type __dn = _VSTD::min(__clz_f, __n); __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); - __r = _VSTD::__popcount(*__first.__seg_ & __m); + __r = _VSTD::__libcpp_popcount(*__first.__seg_ & __m); __n -= __dn; ++__first.__seg_; } // do middle whole words for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) - __r += _VSTD::__popcount(*__first.__seg_); + __r += _VSTD::__libcpp_popcount(*__first.__seg_); // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); - __r += _VSTD::__popcount(*__first.__seg_ & __m); + __r += _VSTD::__libcpp_popcount(*__first.__seg_ & __m); } return __r; } @@ -286,18 +285,18 @@ __count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_typ __storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_); __storage_type __dn = _VSTD::min(__clz_f, __n); __storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn)); - __r = _VSTD::__popcount(~*__first.__seg_ & __m); + __r = _VSTD::__libcpp_popcount(~*__first.__seg_ & __m); __n -= __dn; ++__first.__seg_; } // do middle whole words for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word) - __r += _VSTD::__popcount(~*__first.__seg_); + __r += _VSTD::__libcpp_popcount(~*__first.__seg_); // do last partial word if (__n > 0) { __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); - __r += _VSTD::__popcount(~*__first.__seg_ & __m); + __r += _VSTD::__libcpp_popcount(~*__first.__seg_ & __m); } return __r; } diff --git a/include/__bsd_locale_defaults.h b/include/__bsd_locale_defaults.h index cbc407d10305..2ace2a21cb01 100644 --- a/include/__bsd_locale_defaults.h +++ b/include/__bsd_locale_defaults.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------- __bsd_locale_defaults.h -----------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // The BSDs have lots of *_l functions. We don't want to define those symbols diff --git a/include/__bsd_locale_fallbacks.h b/include/__bsd_locale_fallbacks.h index 3097b01410d3..a807fe039554 100644 --- a/include/__bsd_locale_fallbacks.h +++ b/include/__bsd_locale_fallbacks.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------- __bsd_locale_fallbacks.h ----------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // The BSDs have lots of *_l functions. This file provides reimplementations diff --git a/include/__config b/include/__config index f0bc3483facd..1ecced9f4792 100644 --- a/include/__config +++ b/include/__config @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- __config ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -33,12 +32,16 @@ # define _GNUC_VER_NEW 0 #endif -#define _LIBCPP_VERSION 8000 +#define _LIBCPP_VERSION 9000 #ifndef _LIBCPP_ABI_VERSION # define _LIBCPP_ABI_VERSION 1 #endif +#ifndef __STDC_HOSTED__ +# define _LIBCPP_FREESTANDING +#endif + #ifndef _LIBCPP_STD_VER # if __cplusplus <= 201103L # define _LIBCPP_STD_VER 11 @@ -93,10 +96,12 @@ // Enable optimized version of __do_get_(un)signed which avoids redundant copies. # define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET // Use the smallest possible integer type to represent the index of the variant. -// Previously libc++ used "unsigned int" exclusivly. +// Previously libc++ used "unsigned int" exclusively. # define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION // Unstable attempt to provide a more optimized std::function # define _LIBCPP_ABI_OPTIMIZED_FUNCTION +// All the regex constants must be distinct and nonzero. +# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO #elif _LIBCPP_ABI_VERSION == 1 # if !defined(_LIBCPP_OBJECT_FORMAT_COFF) // Enable compiling copies of now inline methods into the dylib to support @@ -182,6 +187,10 @@ #define _LIBCPP_CLANG_VER 0 #endif +#if defined(_LIBCPP_COMPILER_GCC) && __cplusplus < 201103L +#error "libc++ does not support using GCC with C++03. Please enable C++11" +#endif + // FIXME: ABI detection should be done via compiler builtin macros. This // is just a placeholder until Clang implements such macros. For now assume // that Windows compilers pretending to be MSVC++ target the Microsoft ABI, @@ -201,6 +210,10 @@ # endif #endif +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +# define _LIBCPP_ABI_VCRUNTIME +#endif + // Need to detect which libc we're using if we're on Linux. #if defined(__linux__) # include <features.h> @@ -257,7 +270,7 @@ # define _LIBCPP_WIN32API # define _LIBCPP_LITTLE_ENDIAN # define _LIBCPP_SHORT_WCHAR 1 -// Both MinGW and native MSVC provide a "MSVC"-like enviroment +// Both MinGW and native MSVC provide a "MSVC"-like environment # define _LIBCPP_MSVCRT_LIKE // If mingw not explicitly detected, assume using MS C runtime only if // a MS compatibility version is specified. @@ -298,7 +311,7 @@ // random data even when using sandboxing mechanisms such as chroots, // Capsicum, etc. # define _LIBCPP_USING_ARC4_RANDOM -#elif defined(__Fuchsia__) +#elif defined(__Fuchsia__) || defined(__wasi__) # define _LIBCPP_USING_GETENTROPY #elif defined(__native_client__) // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access, @@ -332,7 +345,7 @@ # if defined(__FreeBSD__) # define _LIBCPP_HAS_QUICK_EXIT # define _LIBCPP_HAS_C11_FEATURES -# elif defined(__Fuchsia__) +# elif defined(__Fuchsia__) || defined(__wasi__) # define _LIBCPP_HAS_QUICK_EXIT # define _LIBCPP_HAS_TIMESPEC_GET # define _LIBCPP_HAS_C11_FEATURES @@ -400,10 +413,6 @@ typedef __char32_t char32_t; #define _LIBCPP_HAS_NO_STRONG_ENUMS #endif -#if !(__has_feature(cxx_decltype)) -#define _LIBCPP_HAS_NO_DECLTYPE -#endif - #if __has_feature(cxx_attributes) # define _LIBCPP_NORETURN [[noreturn]] #else @@ -434,18 +443,6 @@ typedef __char32_t char32_t; #define _LIBCPP_HAS_NO_VARIADICS #endif -#if !(__has_feature(cxx_generalized_initializers)) -#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -#endif - -#if __has_feature(is_base_of) -#define _LIBCPP_HAS_IS_BASE_OF -#endif - -#if __has_feature(is_final) -#define _LIBCPP_HAS_IS_FINAL -#endif - // Objective-C++ features (opt-in) #if __has_feature(objc_arc) #define _LIBCPP_HAS_OBJC_ARC @@ -455,10 +452,6 @@ typedef __char32_t char32_t; #define _LIBCPP_HAS_OBJC_ARC_WEAK #endif -#if !(__has_feature(cxx_constexpr)) -#define _LIBCPP_HAS_NO_CONSTEXPR -#endif - #if !(__has_feature(cxx_relaxed_constexpr)) #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR #endif @@ -471,14 +464,6 @@ typedef __char32_t char32_t; #define _LIBCPP_HAS_NO_NOEXCEPT #endif -#if __has_feature(underlying_type) -#define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T) -#endif - -#if __has_feature(is_literal) -#define _LIBCPP_IS_LITERAL(T) __is_literal(T) -#endif - #if !defined(_LIBCPP_HAS_NO_ASAN) && !__has_feature(address_sanitizer) #define _LIBCPP_HAS_NO_ASAN #endif @@ -510,69 +495,20 @@ typedef __char32_t char32_t; #define _LIBCPP_NORETURN __attribute__((noreturn)) -#if _GNUC_VER >= 407 -#define _LIBCPP_UNDERLYING_TYPE(T) __underlying_type(T) -#define _LIBCPP_IS_LITERAL(T) __is_literal_type(T) -#define _LIBCPP_HAS_IS_FINAL -#endif - -#if defined(__GNUC__) && _GNUC_VER >= 403 -#define _LIBCPP_HAS_IS_BASE_OF -#endif - #if !__EXCEPTIONS && !defined(_LIBCPP_NO_EXCEPTIONS) #define _LIBCPP_NO_EXCEPTIONS #endif -// constexpr was added to GCC in 4.6. -#if _GNUC_VER < 406 -# define _LIBCPP_HAS_NO_CONSTEXPR -// Can only use constexpr in c++11 mode. -#elif !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L -# define _LIBCPP_HAS_NO_CONSTEXPR -#endif - // Determine if GCC supports relaxed constexpr #if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR #endif -// GCC 5 will support variable templates +// GCC 5 supports variable templates #if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES #endif -#ifndef __GXX_EXPERIMENTAL_CXX0X__ - -#define _LIBCPP_HAS_NO_DECLTYPE -#define _LIBCPP_HAS_NO_NULLPTR -#define _LIBCPP_HAS_NO_UNICODE_CHARS -#define _LIBCPP_HAS_NO_VARIADICS -#define _LIBCPP_HAS_NO_RVALUE_REFERENCES -#define _LIBCPP_HAS_NO_STRONG_ENUMS -#define _LIBCPP_HAS_NO_NOEXCEPT - -#else // __GXX_EXPERIMENTAL_CXX0X__ - -#if _GNUC_VER < 403 -#define _LIBCPP_HAS_NO_RVALUE_REFERENCES -#endif - - -#if _GNUC_VER < 404 -#define _LIBCPP_HAS_NO_DECLTYPE -#define _LIBCPP_HAS_NO_UNICODE_CHARS -#define _LIBCPP_HAS_NO_VARIADICS -#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -#endif // _GNUC_VER < 404 - -#if _GNUC_VER < 406 -#define _LIBCPP_HAS_NO_NOEXCEPT -#define _LIBCPP_HAS_NO_NULLPTR -#endif - -#endif // __GXX_EXPERIMENTAL_CXX0X__ - #if !defined(_LIBCPP_HAS_NO_ASAN) && !defined(__SANITIZE_ADDRESS__) #define _LIBCPP_HAS_NO_ASAN #endif @@ -597,16 +533,12 @@ typedef __char32_t char32_t; #error "MSVC versions prior to Visual Studio 2015 are not supported" #endif -#define _LIBCPP_HAS_IS_BASE_OF -#define _LIBCPP_HAS_NO_CONSTEXPR #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES -#define _LIBCPP_HAS_NO_NOEXCEPT #define __alignof__ __alignof #define _LIBCPP_NORETURN __declspec(noreturn) #define _ALIGNAS(x) __declspec(align(x)) #define _ALIGNAS_TYPE(x) alignas(x) -#define _LIBCPP_HAS_NO_VARIADICS #define _LIBCPP_WEAK @@ -623,12 +555,7 @@ typedef __char32_t char32_t; #define _ATTRIBUTE(x) __attribute__((x)) #define _LIBCPP_NORETURN __attribute__((noreturn)) -#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS -#define _LIBCPP_HAS_NO_NOEXCEPT -#define _LIBCPP_HAS_NO_NULLPTR #define _LIBCPP_HAS_NO_UNICODE_CHARS -#define _LIBCPP_HAS_IS_BASE_OF -#define _LIBCPP_HAS_IS_FINAL #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES #if defined(_AIX) @@ -659,8 +586,13 @@ typedef __char32_t char32_t; # define _LIBCPP_EXPORTED_FROM_ABI #elif defined(_LIBCPP_BUILDING_LIBRARY) # define _LIBCPP_DLL_VIS __declspec(dllexport) -# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS -# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS +# if defined(__MINGW32__) +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS +# else +# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS +# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS +# endif # define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS # define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport) #else @@ -777,7 +709,7 @@ typedef __char32_t char32_t; #else // Try to approximate the effect of exclude_from_explicit_instantiation // (which is that entities are not assumed to be provided by explicit - // template instantitations in the dylib) by always inlining those entities. + // template instantiations in the dylib) by always inlining those entities. # define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE #endif @@ -789,6 +721,16 @@ typedef __char32_t char32_t; # endif #endif +#ifndef _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT +# ifdef _LIBCPP_OBJECT_FORMAT_COFF // Windows binaries can't merge typeinfos. +# define _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 0 +#else +// TODO: This isn't strictly correct on ELF platforms due to llvm.org/PR37398 +// And we should consider defaulting to OFF. +# define _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 1 +#endif +#endif + #ifndef _LIBCPP_HIDE_FROM_ABI # if _LIBCPP_HIDE_FROM_ABI_PER_TU # define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE @@ -843,22 +785,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD # define _NOEXCEPT_(x) #endif -#if defined(_LIBCPP_DEBUG_USE_EXCEPTIONS) -# if !defined(_LIBCPP_DEBUG) -# error cannot use _LIBCPP_DEBUG_USE_EXCEPTIONS unless _LIBCPP_DEBUG is defined -# endif -# ifdef _LIBCPP_HAS_NO_NOEXCEPT -# define _NOEXCEPT_DEBUG -# define _NOEXCEPT_DEBUG_(x) -# else -# define _NOEXCEPT_DEBUG noexcept(false) -# define _NOEXCEPT_DEBUG_(x) noexcept(false) -# endif -#else -# define _NOEXCEPT_DEBUG _NOEXCEPT -# define _NOEXCEPT_DEBUG_(x) _NOEXCEPT_(x) -#endif - #ifdef _LIBCPP_HAS_NO_UNICODE_CHARS typedef unsigned short char16_t; typedef unsigned int char32_t; @@ -869,30 +795,11 @@ typedef unsigned int char32_t; #endif #ifdef _LIBCPP_CXX03_LANG -# if __has_extension(c_static_assert) -# define static_assert(__b, __m) _Static_assert(__b, __m) -# else -extern "C++" { -template <bool> struct __static_assert_test; -template <> struct __static_assert_test<true> {}; -template <unsigned> struct __static_assert_check {}; -} -# define static_assert(__b, __m) \ - typedef __static_assert_check<sizeof(__static_assert_test<(__b)>)> \ - _LIBCPP_CONCAT(__t, __LINE__) -# endif // __has_extension(c_static_assert) +# define static_assert(...) _Static_assert(__VA_ARGS__) +# define decltype(...) __decltype(__VA_ARGS__) #endif // _LIBCPP_CXX03_LANG -#ifdef _LIBCPP_HAS_NO_DECLTYPE -// GCC 4.6 provides __decltype in all standard modes. -# if __has_keyword(__decltype) || _LIBCPP_CLANG_VER >= 304 || _GNUC_VER >= 406 -# define decltype(__x) __decltype(__x) -# else -# define decltype(__x) __typeof__(__x) -# endif -#endif - -#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#ifdef _LIBCPP_CXX03_LANG # define _LIBCPP_CONSTEXPR #else # define _LIBCPP_CONSTEXPR constexpr @@ -911,9 +818,9 @@ template <unsigned> struct __static_assert_check {}; #endif #ifdef __GNUC__ -# define _NOALIAS __attribute__((__malloc__)) +# define _LIBCPP_NOALIAS __attribute__((__malloc__)) #else -# define _NOALIAS +# define _LIBCPP_NOALIAS #endif #if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__) || \ @@ -966,10 +873,6 @@ template <unsigned> struct __static_assert_check {}; #define _LIBCPP_EXTERN_TEMPLATE2(...) extern template __VA_ARGS__; #endif -#if defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__) -#define _LIBCPP_NONUNIQUE_RTTI_BIT (1ULL << 63) -#endif - #if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \ defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__) #define _LIBCPP_LOCALE__L_EXTENSIONS 1 @@ -990,13 +893,10 @@ template <unsigned> struct __static_assert_check {}; // for align_val_t were added in 19.12, aka VS 2017 version 15.3. #if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912 # define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION -#elif defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) -# define _LIBCPP_DEFER_NEW_TO_VCRUNTIME -# if !defined(__cpp_aligned_new) - // We're defering to Microsoft's STL to provide aligned new et al. We don't - // have it unless the language feature test macro is defined. -# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION -# endif +#elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new) + // We're deferring to Microsoft's STL to provide aligned new et al. We don't + // have it unless the language feature test macro is defined. +# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION #endif #if defined(__APPLE__) @@ -1025,8 +925,10 @@ template <unsigned> struct __static_assert_check {}; #endif // Deprecation macros. -// Deprecations warnings are only enabled when _LIBCPP_ENABLE_DEPRECATION_WARNINGS is defined. -#if defined(_LIBCPP_ENABLE_DEPRECATION_WARNINGS) +// +// Deprecations warnings are always enabled, except when users explicitly opt-out +// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS. +#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) # if __has_attribute(deprecated) # define _LIBCPP_DEPRECATED __attribute__ ((deprecated)) # elif _LIBCPP_STD_VER > 11 @@ -1128,6 +1030,12 @@ template <unsigned> struct __static_assert_check {}; #endif #endif +#if __has_attribute(no_destroy) +# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__)) +#else +# define _LIBCPP_NO_DESTROY +#endif + #ifndef _LIBCPP_HAS_NO_ASAN _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( const void *, const void *, const void *, const void *); @@ -1158,6 +1066,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL) # if defined(__FreeBSD__) || \ defined(__Fuchsia__) || \ + defined(__wasi__) || \ defined(__NetBSD__) || \ defined(__linux__) || \ defined(__GNU__) || \ @@ -1188,6 +1097,23 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( _LIBCPP_HAS_NO_THREADS is defined. #endif +// The Apple, glibc, and Bionic implementation of pthreads implements +// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 +// mutexes have no destroy mechanism. +// TODO(EricWF): Enable this optimization on Apple and Bionic platforms after +// speaking to their respective stakeholders. +#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \ + || defined(_LIBCPP_HAS_THREAD_API_WIN32) +# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION +#endif + +// Destroying a condvar is a nop on Windows. +// TODO(EricWF): This is potentially true for some pthread implementations +// as well. +#if defined(_LIBCPP_HAS_THREAD_API_WIN32) +# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION +#endif + // Systems that use capability-based security (FreeBSD with Capsicum, // Nuxi CloudABI) may only provide local filesystem access (using *at()). // Functions like open(), rename(), unlink() and stat() should not be @@ -1204,7 +1130,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #endif #if defined(__BIONIC__) || defined(__CloudABI__) || \ - defined(__Fuchsia__) || defined(_LIBCPP_HAS_MUSL_LIBC) + defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) #define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE #endif @@ -1216,13 +1142,22 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic) # define _LIBCPP_HAS_C_ATOMIC_IMP -#elif _GNUC_VER > 407 +#elif defined(_LIBCPP_COMPILER_GCC) # define _LIBCPP_HAS_GCC_ATOMIC_IMP #endif -#if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)) \ +#if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \ + !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \ + !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)) \ || defined(_LIBCPP_HAS_NO_THREADS) -#define _LIBCPP_HAS_NO_ATOMIC_HEADER +# define _LIBCPP_HAS_NO_ATOMIC_HEADER +#else +# ifndef _LIBCPP_ATOMIC_FLAG_TYPE +# define _LIBCPP_ATOMIC_FLAG_TYPE bool +# endif +# ifdef _LIBCPP_FREESTANDING +# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS +# endif #endif #ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK @@ -1250,6 +1185,10 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF #endif +#if !__has_builtin(__builtin_is_constant_evaluated) && _GNUC_VER < 900 +#define _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED +#endif + #if !defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) # if defined(_LIBCPP_MSVCRT) || defined(_NEWLIB_VERSION) # define _LIBCPP_HAS_NO_OFF_T_FUNCTIONS @@ -1277,6 +1216,21 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( # define _LIBCPP_FALLTHROUGH() ((void)0) #endif +#if __has_attribute(__nodebug__) +#define _LIBCPP_NODEBUG __attribute__((__nodebug__)) +#else +#define _LIBCPP_NODEBUG +#endif + +#ifndef _LIBCPP_NODEBUG_TYPE +#if __has_attribute(__nodebug__) && \ + (defined(_LIBCPP_COMPILER_CLANG) && _LIBCPP_CLANG_VER >= 900) +#define _LIBCPP_NODEBUG_TYPE __attribute__((nodebug)) +#else +#define _LIBCPP_NODEBUG_TYPE +#endif +#endif // !defined(_LIBCPP_NODEBUG_TYPE) + #if defined(_LIBCPP_ABI_MICROSOFT) && \ (defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases)) # define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases) @@ -1312,7 +1266,8 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #if !defined(_LIBCPP_BUILDING_LIBRARY) && \ !defined(_LIBCPP_DISABLE_AVAILABILITY) && \ __has_feature(attribute_availability_with_strict) && \ - __has_feature(attribute_availability_in_templates) + __has_feature(attribute_availability_in_templates) && \ + __has_extension(pragma_clang_attribute_external_declaration) # ifdef __APPLE__ # define _LIBCPP_USE_AVAILABILITY_APPLE # endif @@ -1355,6 +1310,21 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( # define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR \ __attribute__((availability(macosx,strict,introduced=10.9))) \ __attribute__((availability(ios,strict,introduced=7.0))) +# define _LIBCPP_AVAILABILITY_FILESYSTEM \ + __attribute__((availability(macosx,strict,introduced=10.15))) \ + __attribute__((availability(ios,strict,introduced=13.0))) \ + __attribute__((availability(tvos,strict,introduced=13.0))) \ + __attribute__((availability(watchos,strict,introduced=6.0))) +# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH \ + _Pragma("clang attribute push(__attribute__((availability(macosx,strict,introduced=10.15))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \ + _Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))") +# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") \ + _Pragma("clang attribute pop") #else # define _LIBCPP_AVAILABILITY_SHARED_MUTEX # define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS @@ -1366,6 +1336,9 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( # define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE # define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY # define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR +# define _LIBCPP_AVAILABILITY_FILESYSTEM +# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH +# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP #endif // Define availability that depends on _LIBCPP_NO_EXCEPTIONS. diff --git a/include/__debug b/include/__debug index a8788f68f8f4..524c5ff02847 100644 --- a/include/__debug +++ b/include/__debug @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- __debug ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -12,6 +11,7 @@ #define _LIBCPP_DEBUG_H #include <__config> +#include <iosfwd> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -25,7 +25,6 @@ # include <cstdlib> # include <cstdio> # include <cstddef> -# include <exception> #endif #if _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_ASSERT) @@ -50,10 +49,6 @@ #define _LIBCPP_DEBUG_MODE(...) ((void)0) #endif -#if _LIBCPP_DEBUG_LEVEL < 1 -class _LIBCPP_EXCEPTION_ABI __libcpp_debug_exception; -#endif - _LIBCPP_BEGIN_NAMESPACE_STD struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info { @@ -63,6 +58,9 @@ struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info { _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m) : __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {} + + _LIBCPP_FUNC_VIS std::string what() const; + const char* __file_; int __line_; const char* __pred_; @@ -80,38 +78,11 @@ extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_fun _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __libcpp_abort_debug_function(__libcpp_debug_info const&); -/// __libcpp_throw_debug_function - A debug handler that throws -/// an instance of __libcpp_debug_exception when called. - _LIBCPP_NORETURN _LIBCPP_FUNC_VIS -void __libcpp_throw_debug_function(__libcpp_debug_info const&); - /// __libcpp_set_debug_function - Set the debug handler to the specified /// function. _LIBCPP_FUNC_VIS bool __libcpp_set_debug_function(__libcpp_debug_function_type __func); -// Setup the throwing debug handler during dynamic initialization. -#if _LIBCPP_DEBUG_LEVEL >= 1 && defined(_LIBCPP_DEBUG_USE_EXCEPTIONS) -# if defined(_LIBCPP_NO_EXCEPTIONS) -# error _LIBCPP_DEBUG_USE_EXCEPTIONS cannot be used when exceptions are disabled. -# endif -static bool __init_dummy = __libcpp_set_debug_function(__libcpp_throw_debug_function); -#endif - -#if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY) -class _LIBCPP_EXCEPTION_ABI __libcpp_debug_exception : public exception { -public: - __libcpp_debug_exception() _NOEXCEPT; - explicit __libcpp_debug_exception(__libcpp_debug_info const& __i); - __libcpp_debug_exception(__libcpp_debug_exception const&); - ~__libcpp_debug_exception() _NOEXCEPT; - const char* what() const _NOEXCEPT; -private: - struct __libcpp_debug_exception_imp; - __libcpp_debug_exception_imp *__imp_; -}; -#endif - #if _LIBCPP_DEBUG_LEVEL >= 2 || defined(_LIBCPP_BUILDING_LIBRARY) struct _LIBCPP_TYPE_VIS __c_node; @@ -251,16 +222,22 @@ public: __db_c_const_iterator __c_end() const; __db_i_const_iterator __i_end() const; + typedef __c_node*(_InsertConstruct)(void*, void*, __c_node*); + + template <class _Cont> + _LIBCPP_INLINE_VISIBILITY static __c_node* __create_C_node(void *__mem, void *__c, __c_node *__next) { + return ::new(__mem) _C_node<_Cont>(__c, __next); + } + template <class _Cont> _LIBCPP_INLINE_VISIBILITY void __insert_c(_Cont* __c) { - __c_node* __n = __insert_c(static_cast<void*>(__c)); - ::new(__n) _C_node<_Cont>(__n->__c_, __n->__next_); + __insert_c(static_cast<void*>(__c), &__create_C_node<_Cont>); } void __insert_i(void* __i); - __c_node* __insert_c(void* __c); + void __insert_c(void* __c, _InsertConstruct* __fn); void __erase_c(void* __c); void __insert_ic(void* __i, const void* __c); diff --git a/include/__errc b/include/__errc index d0f00b7f0be0..a8ad29f364ac 100644 --- a/include/__errc +++ b/include/__errc @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- __errc ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/__functional_03 b/include/__functional_03 index 0a3bfbaa3d2c..a90cbb75b2ad 100644 --- a/include/__functional_03 +++ b/include/__functional_03 @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/__functional_base b/include/__functional_base index 032be99bf6a5..9587d7ab15a1 100644 --- a/include/__functional_base +++ b/include/__functional_base @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -126,7 +125,7 @@ struct __weak_result_type_imp // bool is true : public __maybe_derive_from_unary_function<_Tp>, public __maybe_derive_from_binary_function<_Tp> { - typedef typename _Tp::result_type result_type; + typedef _LIBCPP_NODEBUG_TYPE typename _Tp::result_type result_type; }; template <class _Tp> @@ -147,19 +146,19 @@ struct __weak_result_type template <class _Rp> struct __weak_result_type<_Rp ()> { - typedef _Rp result_type; + typedef _LIBCPP_NODEBUG_TYPE _Rp result_type; }; template <class _Rp> struct __weak_result_type<_Rp (&)()> { - typedef _Rp result_type; + typedef _LIBCPP_NODEBUG_TYPE _Rp result_type; }; template <class _Rp> struct __weak_result_type<_Rp (*)()> { - typedef _Rp result_type; + typedef _LIBCPP_NODEBUG_TYPE _Rp result_type; }; // 1 argument case @@ -611,7 +610,7 @@ _LIBCPP_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Allo template <class _Tp, class _Alloc, class ..._Args> struct __uses_alloc_ctor_imp { - typedef typename __uncvref<_Alloc>::type _RawAlloc; + typedef _LIBCPP_NODEBUG_TYPE typename __uncvref<_Alloc>::type _RawAlloc; static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value; static const bool __ic = is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value; diff --git a/include/__functional_base_03 b/include/__functional_base_03 index 8407dcfa39ca..e6dac90c84f7 100644 --- a/include/__functional_base_03 +++ b/include/__functional_base_03 @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/__hash_table b/include/__hash_table index 6f5b183105e6..0b953f58e99e 100644 --- a/include/__hash_table +++ b/include/__hash_table @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -123,7 +122,7 @@ inline _LIBCPP_INLINE_VISIBILITY size_t __next_hash_pow2(size_t __n) { - return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __clz(__n-1))); + return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __libcpp_clz(__n-1))); } @@ -876,9 +875,9 @@ struct __enforce_unordered_container_requirements { template <class _Key, class _Hash, class _Equal> #ifndef _LIBCPP_CXX03_LANG _LIBCPP_DIAGNOSE_WARNING(!__invokable<_Equal const&, _Key const&, _Key const&>::value, - "the specified comparator type does not provide a const call operator") + "the specified comparator type does not provide a viable const call operator") _LIBCPP_DIAGNOSE_WARNING(!__invokable<_Hash const&, _Key const&>::value, - "the specified hash functor does not provide a const call operator") + "the specified hash functor does not provide a viable const call operator") #endif typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type __diagnose_unordered_container_requirements(int); @@ -1261,7 +1260,7 @@ public: void swap(__hash_table& __u) #if _LIBCPP_STD_VER <= 11 - _NOEXCEPT_DEBUG_( + _NOEXCEPT_( __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || __is_nothrow_swappable<__pointer_allocator>::value) @@ -1269,7 +1268,7 @@ public: || __is_nothrow_swappable<__node_allocator>::value) ); #else - _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value); + _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value); #endif _LIBCPP_INLINE_VISIBILITY @@ -2249,7 +2248,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( return _InsertReturnType{end(), false, _NodeHandle()}; pair<iterator, bool> __result = __node_insert_unique(__nh.__ptr_); if (__result.second) - __nh.__release(); + __nh.__release_ptr(); return _InsertReturnType{__result.first, __result.second, _VSTD::move(__nh)}; } @@ -2264,7 +2263,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique( return end(); pair<iterator, bool> __result = __node_insert_unique(__nh.__ptr_); if (__result.second) - __nh.__release(); + __nh.__release_ptr(); return __result.first; } @@ -2328,7 +2327,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( if (__nh.empty()) return end(); iterator __result = __node_insert_multi(__nh.__ptr_); - __nh.__release(); + __nh.__release_ptr(); return __result; } @@ -2342,7 +2341,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi( if (__nh.empty()) return end(); iterator __result = __node_insert_multi(__hint, __nh.__ptr_); - __nh.__release(); + __nh.__release_ptr(); return __result; } @@ -2372,6 +2371,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_multi( template <class _Tp, class _Hash, class _Equal, class _Alloc> void __hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n) +_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { if (__n == 1) __n = 2; @@ -2807,7 +2807,7 @@ template <class _Tp, class _Hash, class _Equal, class _Alloc> void __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) #if _LIBCPP_STD_VER <= 11 - _NOEXCEPT_DEBUG_( + _NOEXCEPT_( __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || __is_nothrow_swappable<__pointer_allocator>::value) @@ -2815,7 +2815,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) || __is_nothrow_swappable<__node_allocator>::value) ) #else - _NOEXCEPT_DEBUG_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value) + _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value) #endif { _LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value || diff --git a/include/__libcpp_version b/include/__libcpp_version index e002b3628b34..d58c55a31dc7 100644 --- a/include/__libcpp_version +++ b/include/__libcpp_version @@ -1 +1 @@ -8000 +9000 diff --git a/include/__locale b/include/__locale index cde9cc85f6b5..d382e4d8a94b 100644 --- a/include/__locale +++ b/include/__locale @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -20,6 +19,7 @@ #include <cctype> #include <locale.h> #if defined(_LIBCPP_MSVCRT_LIKE) +# include <cstring> # include <support/win32/locale_win32.h> #elif defined(_AIX) # include <support/ibm/xlocale.h> @@ -35,6 +35,9 @@ # include <xlocale.h> #elif defined(__Fuchsia__) # include <support/fuchsia/xlocale.h> +#elif defined(__wasi__) +// WASI libc uses musl's locales support. +# include <support/musl/xlocale.h> #elif defined(_LIBCPP_HAS_MUSL_LIBC) # include <support/musl/xlocale.h> #endif @@ -64,28 +67,41 @@ private: #elif defined(_LIBCPP_MSVCRT_LIKE) struct __libcpp_locale_guard { __libcpp_locale_guard(locale_t __l) : - __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)), - __locale_collate(setlocale(LC_COLLATE, __l.__get_locale())), - __locale_ctype(setlocale(LC_CTYPE, __l.__get_locale())), - __locale_monetary(setlocale(LC_MONETARY, __l.__get_locale())), - __locale_numeric(setlocale(LC_NUMERIC, __l.__get_locale())), - __locale_time(setlocale(LC_TIME, __l.__get_locale())) - // LC_MESSAGES is not supported on Windows. - {} + __status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) { + // Setting the locale can be expensive even when the locale given is + // already the current locale, so do an explicit check to see if the + // current locale is already the one we want. + const char* __lc = __setlocale(nullptr); + // If every category is the same, the locale string will simply be the + // locale name, otherwise it will be a semicolon-separated string listing + // each category. In the second case, we know at least one category won't + // be what we want, so we only have to check the first case. + if (strcmp(__l.__get_locale(), __lc) != 0) { + __locale_all = _strdup(__lc); + if (__locale_all == nullptr) + __throw_bad_alloc(); + __setlocale(__l.__get_locale()); + } + } ~__libcpp_locale_guard() { - setlocale(LC_COLLATE, __locale_collate); - setlocale(LC_CTYPE, __locale_ctype); - setlocale(LC_MONETARY, __locale_monetary); - setlocale(LC_NUMERIC, __locale_numeric); - setlocale(LC_TIME, __locale_time); - _configthreadlocale(__status); + // The CRT documentation doesn't explicitly say, but setlocale() does the + // right thing when given a semicolon-separated list of locale settings + // for the different categories in the same format as returned by + // setlocale(LC_ALL, nullptr). + if (__locale_all != nullptr) { + __setlocale(__locale_all); + free(__locale_all); + } + _configthreadlocale(__status); + } + static const char* __setlocale(const char* __locale) { + const char* __new_locale = setlocale(LC_ALL, __locale); + if (__new_locale == nullptr) + __throw_bad_alloc(); + return __new_locale; } int __status; - char* __locale_collate; - char* __locale_ctype; - char* __locale_monetary; - char* __locale_numeric; - char* __locale_time; + char* __locale_all = nullptr; }; #endif @@ -255,7 +271,10 @@ public: return do_compare(__lo1, __hi1, __lo2, __hi2); } + // FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work + // around a dllimport bug that expects an external instantiation. _LIBCPP_INLINE_VISIBILITY + _LIBCPP_ALWAYS_INLINE string_type transform(const char_type* __lo, const char_type* __hi) const { return do_transform(__lo, __hi); @@ -389,6 +408,11 @@ public: static const mask punct = _ISpunct; static const mask xdigit = _ISxdigit; static const mask blank = _ISblank; +#if defined(__mips__) + static const mask __regex_word = static_cast<char_class_type>(_ISbit(15)); +#else + static const mask __regex_word = 0x80; +#endif #elif defined(_LIBCPP_MSVCRT_LIKE) typedef unsigned short mask; static const mask space = _SPACE; @@ -401,6 +425,7 @@ public: static const mask punct = _PUNCT; static const mask xdigit = _HEX; static const mask blank = _BLANK; + static const mask __regex_word = 0x80; # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) # ifdef __APPLE__ @@ -422,8 +447,12 @@ public: # if defined(__NetBSD__) static const mask blank = _CTYPE_BL; + // NetBSD defines classes up to 0x2000 + // see sys/ctype_bits.h, _CTYPE_Q + static const mask __regex_word = 0x8000; # else static const mask blank = _CTYPE_B; + static const mask __regex_word = 0x80; # endif #elif defined(__sun__) || defined(_AIX) typedef unsigned int mask; @@ -437,6 +466,7 @@ public: static const mask punct = _ISPUNCT; static const mask xdigit = _ISXDIGIT; static const mask blank = _ISBLANK; + static const mask __regex_word = 0x80; #elif defined(_NEWLIB_VERSION) // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. typedef char mask; @@ -450,6 +480,7 @@ public: static const mask punct = _P; static const mask xdigit = _X | _N; static const mask blank = _B; + static const mask __regex_word = 0x80; # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT @@ -465,6 +496,7 @@ public: static const mask punct = 1<<7; static const mask xdigit = 1<<8; static const mask blank = 1<<9; + static const mask __regex_word = 1<<10; #endif static const mask alnum = alpha | digit; static const mask graph = alnum | punct; @@ -1230,8 +1262,6 @@ _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<w _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>) _LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>) -_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*); - template <size_t _Np> struct __narrow_to_utf8 { diff --git a/include/__mutex_base b/include/__mutex_base index da21a5f8eb6a..f828beaf780d 100644 --- a/include/__mutex_base +++ b/include/__mutex_base @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -37,28 +36,24 @@ _LIBCPP_BEGIN_NAMESPACE_STD # endif #endif // _LIBCPP_THREAD_SAFETY_ANNOTATION + class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex { -#ifndef _LIBCPP_CXX03_LANG __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER; -#else - __libcpp_mutex_t __m_; -#endif public: _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_CXX03_LANG - constexpr mutex() = default; + _LIBCPP_CONSTEXPR mutex() = default; + + mutex(const mutex&) = delete; + mutex& operator=(const mutex&) = delete; + +#if defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION) + ~mutex() = default; #else - mutex() _NOEXCEPT {__m_ = (__libcpp_mutex_t)_LIBCPP_MUTEX_INITIALIZER;} + ~mutex() _NOEXCEPT; #endif - ~mutex(); -private: - mutex(const mutex&);// = delete; - mutex& operator=(const mutex&);// = delete; - -public: void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability()); bool try_lock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true)); void unlock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()); @@ -287,26 +282,20 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status) class _LIBCPP_TYPE_VIS condition_variable { -#ifndef _LIBCPP_CXX03_LANG __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER; -#else - __libcpp_condvar_t __cv_; -#endif - public: _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_CXX03_LANG - constexpr condition_variable() _NOEXCEPT = default; + _LIBCPP_CONSTEXPR condition_variable() _NOEXCEPT = default; + +#ifdef _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION + ~condition_variable() = default; #else - condition_variable() _NOEXCEPT {__cv_ = (__libcpp_condvar_t)_LIBCPP_CONDVAR_INITIALIZER;} -#endif ~condition_variable(); +#endif -private: - condition_variable(const condition_variable&); // = delete; - condition_variable& operator=(const condition_variable&); // = delete; + condition_variable(const condition_variable&) = delete; + condition_variable& operator=(const condition_variable&) = delete; -public: void notify_one() _NOEXCEPT; void notify_all() _NOEXCEPT; diff --git a/include/__node_handle b/include/__node_handle index a9cf3b7217a3..be1fe17a8728 100644 --- a/include/__node_handle +++ b/include/__node_handle @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -57,7 +56,7 @@ private: optional<allocator_type> __alloc_; _LIBCPP_INLINE_VISIBILITY - void __release() + void __release_ptr() { __ptr_ = nullptr; __alloc_ = _VSTD::nullopt; @@ -194,8 +193,7 @@ using __map_node_handle = __basic_node_handle< _NodeType, _Alloc, __map_node_handle_specifics>; template <class _Iterator, class _NodeType> -_LIBCPP_TEMPLATE_VIS -struct __insert_return_type +struct _LIBCPP_TEMPLATE_VIS __insert_return_type { _Iterator position; bool inserted; diff --git a/include/__nullptr b/include/__nullptr index aa3b4d2145a5..45529a710b63 100644 --- a/include/__nullptr +++ b/include/__nullptr @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- __nullptr --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/__sso_allocator b/include/__sso_allocator index 8aca0495d756..393012873848 100644 --- a/include/__sso_allocator +++ b/include/__sso_allocator @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/__std_stream b/include/__std_stream index db90795f66fc..5a9a470a9787 100644 --- a/include/__std_stream +++ b/include/__std_stream @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/__string b/include/__string index 1ddeec7149fb..a88b976be3c9 100644 --- a/include/__string +++ b/include/__string @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- __string ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/__threading_support b/include/__threading_support index 202490062729..589fe2096fd4 100644 --- a/include/__threading_support +++ b/include/__threading_support @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -23,6 +22,8 @@ # include <__external_threading> #elif !defined(_LIBCPP_HAS_NO_THREADS) +typedef ::timespec __libcpp_timespec_t; + #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD) # include <pthread.h> # include <sched.h> @@ -149,7 +150,7 @@ int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m); _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, - timespec *__ts); + __libcpp_timespec_t *__ts); _LIBCPP_THREAD_ABI_VISIBILITY int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv); @@ -157,7 +158,7 @@ int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv); // Execute once _LIBCPP_THREAD_ABI_VISIBILITY int __libcpp_execute_once(__libcpp_exec_once_flag *flag, - void (*init_routine)(void)); + void (*init_routine)()); // Thread id _LIBCPP_THREAD_ABI_VISIBILITY @@ -288,7 +289,7 @@ int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m) } int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m, - timespec *__ts) + __libcpp_timespec_t *__ts) { return pthread_cond_timedwait(__cv, __m, __ts); } @@ -300,7 +301,7 @@ int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv) // Execute once int __libcpp_execute_once(__libcpp_exec_once_flag *flag, - void (*init_routine)(void)) { + void (*init_routine)()) { return pthread_once(flag, init_routine); } @@ -357,7 +358,7 @@ void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns) { using namespace chrono; seconds __s = duration_cast<seconds>(__ns); - timespec __ts; + __libcpp_timespec_t __ts; typedef decltype(__ts.tv_sec) ts_sec; _LIBCPP_CONSTEXPR ts_sec __ts_sec_max = numeric_limits<ts_sec>::max(); diff --git a/include/__tree b/include/__tree index 814851085b98..15b03ec857f6 100644 --- a/include/__tree +++ b/include/__tree @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -27,6 +26,13 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_STD +#if defined(__GNUC__) && !defined(__clang__) // gcc.gnu.org/PR37804 +template <class, class, class, class> class _LIBCPP_TEMPLATE_VIS map; +template <class, class, class, class> class _LIBCPP_TEMPLATE_VIS multimap; +template <class, class, class> class _LIBCPP_TEMPLATE_VIS set; +template <class, class, class> class _LIBCPP_TEMPLATE_VIS multiset; +#endif + template <class _Tp, class _Compare, class _Allocator> class __tree; template <class _Tp, class _NodePtr, class _DiffType> class _LIBCPP_TEMPLATE_VIS __tree_iterator; @@ -965,7 +971,7 @@ private: template<class _Tp, class _Compare> #ifndef _LIBCPP_CXX03_LANG _LIBCPP_DIAGNOSE_WARNING(!std::__invokable<_Compare const&, _Tp const&, _Tp const&>::value, - "the specified comparator type does not provide a const call operator") + "the specified comparator type does not provide a viable const call operator") #endif int __diagnose_non_const_comparator(); @@ -1090,8 +1096,8 @@ public: __tree(const value_compare& __comp, const allocator_type& __a); __tree(const __tree& __t); __tree& operator=(const __tree& __t); - template <class _InputIterator> - void __assign_unique(_InputIterator __first, _InputIterator __last); + template <class _ForwardIterator> + void __assign_unique(_ForwardIterator __first, _ForwardIterator __last); template <class _InputIterator> void __assign_multi(_InputIterator __first, _InputIterator __last); #ifndef _LIBCPP_CXX03_LANG @@ -1326,10 +1332,7 @@ public: #endif // !_LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - pair<iterator, bool> __node_insert_unique(__node_pointer __nd); - _LIBCPP_INLINE_VISIBILITY - iterator __node_insert_unique(const_iterator __p, - __node_pointer __nd); + pair<iterator, bool> __node_assign_unique(const __container_value_type& __v, __node_pointer __dest); _LIBCPP_INLINE_VISIBILITY iterator __node_insert_multi(__node_pointer __nd); @@ -1509,8 +1512,50 @@ private: _LIBCPP_INLINE_VISIBILITY void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {} - __node_pointer __detach(); - static __node_pointer __detach(__node_pointer); + struct _DetachedTreeCache { + _LIBCPP_INLINE_VISIBILITY + explicit _DetachedTreeCache(__tree *__t) _NOEXCEPT : __t_(__t), + __cache_root_(__detach_from_tree(__t)) { + __advance(); + } + + _LIBCPP_INLINE_VISIBILITY + __node_pointer __get() const _NOEXCEPT { + return __cache_elem_; + } + + _LIBCPP_INLINE_VISIBILITY + void __advance() _NOEXCEPT { + __cache_elem_ = __cache_root_; + if (__cache_root_) { + __cache_root_ = __detach_next(__cache_root_); + } + } + + _LIBCPP_INLINE_VISIBILITY + ~_DetachedTreeCache() { + __t_->destroy(__cache_elem_); + if (__cache_root_) { + while (__cache_root_->__parent_ != nullptr) + __cache_root_ = static_cast<__node_pointer>(__cache_root_->__parent_); + __t_->destroy(__cache_root_); + } + } + + _DetachedTreeCache(_DetachedTreeCache const&) = delete; + _DetachedTreeCache& operator=(_DetachedTreeCache const&) = delete; + + private: + _LIBCPP_INLINE_VISIBILITY + static __node_pointer __detach_from_tree(__tree *__t) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static __node_pointer __detach_next(__node_pointer) _NOEXCEPT; + + __tree *__t_; + __node_pointer __cache_root_; + __node_pointer __cache_elem_; + }; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; @@ -1548,13 +1593,13 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, // Precondition: size() != 0 template <class _Tp, class _Compare, class _Allocator> typename __tree<_Tp, _Compare, _Allocator>::__node_pointer -__tree<_Tp, _Compare, _Allocator>::__detach() +__tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_from_tree(__tree *__t) _NOEXCEPT { - __node_pointer __cache = static_cast<__node_pointer>(__begin_node()); - __begin_node() = __end_node(); - __end_node()->__left_->__parent_ = nullptr; - __end_node()->__left_ = nullptr; - size() = 0; + __node_pointer __cache = static_cast<__node_pointer>(__t->__begin_node()); + __t->__begin_node() = __t->__end_node(); + __t->__end_node()->__left_->__parent_ = nullptr; + __t->__end_node()->__left_ = nullptr; + __t->size() = 0; // __cache->__left_ == nullptr if (__cache->__right_ != nullptr) __cache = static_cast<__node_pointer>(__cache->__right_); @@ -1569,7 +1614,7 @@ __tree<_Tp, _Compare, _Allocator>::__detach() // This is no longer a red-black tree template <class _Tp, class _Compare, class _Allocator> typename __tree<_Tp, _Compare, _Allocator>::__node_pointer -__tree<_Tp, _Compare, _Allocator>::__detach(__node_pointer __cache) +__tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_next(__node_pointer __cache) _NOEXCEPT { if (__cache->__parent_ == nullptr) return nullptr; @@ -1603,45 +1648,23 @@ __tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) } template <class _Tp, class _Compare, class _Allocator> -template <class _InputIterator> +template <class _ForwardIterator> void -__tree<_Tp, _Compare, _Allocator>::__assign_unique(_InputIterator __first, _InputIterator __last) +__tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first, _ForwardIterator __last) { - typedef iterator_traits<_InputIterator> _ITraits; + typedef iterator_traits<_ForwardIterator> _ITraits; typedef typename _ITraits::value_type _ItValueType; static_assert((is_same<_ItValueType, __container_value_type>::value), "__assign_unique may only be called with the containers value type"); - + static_assert(__is_forward_iterator<_ForwardIterator>::value, + "__assign_unique requires a forward iterator"); if (size() != 0) { - __node_pointer __cache = __detach(); -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - for (; __cache != nullptr && __first != __last; ++__first) - { - __cache->__value_ = *__first; - __node_pointer __next = __detach(__cache); - __node_insert_unique(__cache); - __cache = __next; + _DetachedTreeCache __cache(this); + for (; __cache.__get() != nullptr && __first != __last; ++__first) { + if (__node_assign_unique(*__first, __cache.__get()).second) + __cache.__advance(); } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - while (__cache->__parent_ != nullptr) - __cache = static_cast<__node_pointer>(__cache->__parent_); - destroy(__cache); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS - if (__cache != nullptr) - { - while (__cache->__parent_ != nullptr) - __cache = static_cast<__node_pointer>(__cache->__parent_); - destroy(__cache); - } } for (; __first != __last; ++__first) __insert_unique(*__first); @@ -1660,33 +1683,11 @@ __tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _Input " or the nodes value type"); if (size() != 0) { - __node_pointer __cache = __detach(); -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - for (; __cache != nullptr && __first != __last; ++__first) - { - __cache->__value_ = *__first; - __node_pointer __next = __detach(__cache); - __node_insert_multi(__cache); - __cache = __next; - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - while (__cache->__parent_ != nullptr) - __cache = static_cast<__node_pointer>(__cache->__parent_); - destroy(__cache); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS - if (__cache != nullptr) - { - while (__cache->__parent_ != nullptr) - __cache = static_cast<__node_pointer>(__cache->__parent_); - destroy(__cache); + _DetachedTreeCache __cache(this); + for (; __cache.__get() && __first != __last; ++__first) { + __cache.__get()->__value_ = *__first; + __node_insert_multi(__cache.__get()); + __cache.__advance(); } } for (; __first != __last; ++__first) @@ -1784,33 +1785,11 @@ __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) const_iterator __e = end(); if (size() != 0) { - __node_pointer __cache = __detach(); -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - while (__cache != nullptr && __t.size() != 0) - { - __cache->__value_ = _VSTD::move(__t.remove(__t.begin())->__value_); - __node_pointer __next = __detach(__cache); - __node_insert_multi(__cache); - __cache = __next; - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - while (__cache->__parent_ != nullptr) - __cache = static_cast<__node_pointer>(__cache->__parent_); - destroy(__cache); - throw; - } -#endif // _LIBCPP_NO_EXCEPTIONS - if (__cache != nullptr) - { - while (__cache->__parent_ != nullptr) - __cache = static_cast<__node_pointer>(__cache->__parent_); - destroy(__cache); + _DetachedTreeCache __cache(this); + while (__cache.__get() != nullptr && __t.size() != 0) { + __cache.__get()->__value_ = _VSTD::move(__t.remove(__t.begin())->__value_); + __node_insert_multi(__cache.__get()); + __cache.__advance(); } } while (__t.size() != 0) @@ -2319,14 +2298,15 @@ __tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const __co template <class _Tp, class _Compare, class _Allocator> pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool> -__tree<_Tp, _Compare, _Allocator>::__node_insert_unique(__node_pointer __nd) +__tree<_Tp, _Compare, _Allocator>::__node_assign_unique(const __container_value_type& __v, __node_pointer __nd) { __parent_pointer __parent; - __node_base_pointer& __child = __find_equal(__parent, __nd->__value_); + __node_base_pointer& __child = __find_equal(__parent, _NodeTypes::__get_key(__v)); __node_pointer __r = static_cast<__node_pointer>(__child); bool __inserted = false; if (__child == nullptr) { + __nd->__value_ = __v; __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); __r = __nd; __inserted = true; @@ -2334,22 +2314,6 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_unique(__node_pointer __nd) return pair<iterator, bool>(iterator(__r), __inserted); } -template <class _Tp, class _Compare, class _Allocator> -typename __tree<_Tp, _Compare, _Allocator>::iterator -__tree<_Tp, _Compare, _Allocator>::__node_insert_unique(const_iterator __p, - __node_pointer __nd) -{ - __parent_pointer __parent; - __node_base_pointer __dummy; - __node_base_pointer& __child = __find_equal(__p, __parent, __nd->__value_); - __node_pointer __r = static_cast<__node_pointer>(__child); - if (__child == nullptr) - { - __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); - __r = __nd; - } - return iterator(__r); -} template <class _Tp, class _Compare, class _Allocator> typename __tree<_Tp, _Compare, _Allocator>::iterator @@ -2408,7 +2372,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique( __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); - __nh.__release(); + __nh.__release_ptr(); return _InsertReturnType{iterator(__ptr), true, _NodeHandle()}; } @@ -2433,7 +2397,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique( __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); __r = __ptr; - __nh.__release(); + __nh.__release_ptr(); } return iterator(__r); } @@ -2498,7 +2462,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi(_NodeHandle&& __nh __node_base_pointer& __child = __find_leaf_high( __parent, _NodeTypes::__get_key(__ptr->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); - __nh.__release(); + __nh.__release_ptr(); return iterator(__ptr); } @@ -2517,7 +2481,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi( __node_base_pointer& __child = __find_leaf(__hint, __parent, _NodeTypes::__get_key(__ptr->__value_)); __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); - __nh.__release(); + __nh.__release_ptr(); return iterator(__ptr); } diff --git a/include/__tuple b/include/__tuple index 3b23d78afa1b..196f3c2b5aa5 100644 --- a/include/__tuple +++ b/include/__tuple @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -54,27 +53,24 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<volatile _Tp> : publ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<const volatile _Tp> : public tuple_size<_Tp> {}; #endif -template <size_t _Ip, class _Tp> class _LIBCPP_TEMPLATE_VIS tuple_element; +template <size_t _Ip, class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_element; template <size_t _Ip, class _Tp> -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> { -public: - typedef typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type; }; template <size_t _Ip, class _Tp> -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> { -public: - typedef typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type; }; template <size_t _Ip, class _Tp> -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> { -public: - typedef typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type; }; template <class _Tp> struct __tuple_like : false_type {}; @@ -103,7 +99,7 @@ namespace __detail { template<typename _Tp, size_t ..._Extra> struct __repeat; template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> { - typedef __integer_sequence<_Tp, + typedef _LIBCPP_NODEBUG_TYPE __integer_sequence<_Tp, _Np..., sizeof...(_Np) + _Np..., 2 * sizeof...(_Np) + _Np..., @@ -257,7 +253,7 @@ template <class ..._Tp> struct __tuple_types {}; namespace __indexer_detail { template <size_t _Idx, class _Tp> -struct __indexed { using type = _Tp; }; +struct __indexed { using type _LIBCPP_NODEBUG_TYPE = _Tp; }; template <class _Types, class _Indexes> struct __indexer; @@ -272,7 +268,7 @@ __indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&); } // namespace __indexer_detail template <size_t _Idx, class ..._Types> -using __type_pack_element = typename decltype( +using __type_pack_element _LIBCPP_NODEBUG_TYPE = typename decltype( __indexer_detail::__at_index<_Idx>( __indexer_detail::__indexer< __tuple_types<_Types...>, @@ -282,11 +278,10 @@ using __type_pack_element = typename decltype( #endif template <size_t _Ip, class ..._Types> -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>> { -public: static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range"); - typedef __type_pack_element<_Ip, _Types...> type; + typedef _LIBCPP_NODEBUG_TYPE __type_pack_element<_Ip, _Types...> type; }; @@ -306,34 +301,34 @@ struct __apply_cv_mf<false, false, false> { }; template <> struct __apply_cv_mf<false, true, false> { - template <class _Tp> using __apply = const _Tp; + template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const _Tp; }; template <> struct __apply_cv_mf<false, false, true> { - template <class _Tp> using __apply = volatile _Tp; + template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = volatile _Tp; }; template <> struct __apply_cv_mf<false, true, true> { - template <class _Tp> using __apply = const volatile _Tp; + template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const volatile _Tp; }; template <> struct __apply_cv_mf<true, false, false> { - template <class _Tp> using __apply = _Tp&; + template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = _Tp&; }; template <> struct __apply_cv_mf<true, true, false> { - template <class _Tp> using __apply = const _Tp&; + template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const _Tp&; }; template <> struct __apply_cv_mf<true, false, true> { - template <class _Tp> using __apply = volatile _Tp&; + template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = volatile _Tp&; }; template <> struct __apply_cv_mf<true, true, true> { - template <class _Tp> using __apply = const volatile _Tp&; + template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const volatile _Tp&; }; template <class _Tp, class _RawTp = typename remove_reference<_Tp>::type> -using __apply_cv_t = __apply_cv_mf< +using __apply_cv_t _LIBCPP_NODEBUG_TYPE = __apply_cv_mf< is_lvalue_reference<_Tp>::value, is_const<_RawTp>::value, is_volatile<_RawTp>::value>; @@ -352,7 +347,7 @@ template <template <class...> class _Tuple, class ..._Types, size_t ..._Idx> struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> { // Specialization for pair, tuple, and __tuple_types template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>> - using __apply_quals = __tuple_types< + using __apply_quals _LIBCPP_NODEBUG_TYPE = __tuple_types< typename _ApplyFn::template __apply<__type_pack_element<_Idx, _Types...>>... >; }; @@ -380,19 +375,19 @@ struct __make_tuple_types template <class ..._Types, size_t _Ep> struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> { - typedef __tuple_types<_Types...> type; + typedef _LIBCPP_NODEBUG_TYPE __tuple_types<_Types...> type; }; template <class ..._Types, size_t _Ep> struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> { - typedef __tuple_types<_Types...> type; + typedef _LIBCPP_NODEBUG_TYPE __tuple_types<_Types...> type; }; template <bool ..._Preds> struct __all_dummy; template <bool ..._Pred> -using __all = is_same<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>; +using __all = _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>; struct __tuple_sfinae_base { template <template <class, class...> class _Trait, @@ -457,15 +452,14 @@ struct __tuple_assignable<_Tp, _Up, true, true> template <size_t _Ip, class ..._Tp> -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > { -public: - typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type; + typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type; }; #if _LIBCPP_STD_VER > 11 template <size_t _Ip, class ..._Tp> -using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; +using tuple_element_t _LIBCPP_NODEBUG_TYPE = typename tuple_element <_Ip, _Tp...>::type; #endif template <bool _IsTuple, class _SizeTrait, size_t _Expected> @@ -477,7 +471,7 @@ struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected> template <class _Tuple, size_t _ExpectedSize, class _RawTuple = typename __uncvref<_Tuple>::type> -using __tuple_like_with_size = __tuple_like_with_size_imp< +using __tuple_like_with_size _LIBCPP_NODEBUG_TYPE = __tuple_like_with_size_imp< __tuple_like<_RawTuple>::value, tuple_size<_RawTuple>, _ExpectedSize >; diff --git a/include/__undef_macros b/include/__undef_macros index 60ab1dbfb5f7..4923ee6b4a1a 100644 --- a/include/__undef_macros +++ b/include/__undef_macros @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------ __undef_macros ------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/algorithm b/include/algorithm index d102899f2dfc..0d7862675588 100644 --- a/include/algorithm +++ b/include/algorithm @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- algorithm ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -781,11 +780,23 @@ __half_positive(_Tp __value) template <class _Compare> struct __debug_less { - _Compare __comp_; + _Compare &__comp_; + _LIBCPP_CONSTEXPR_AFTER_CXX17 __debug_less(_Compare& __c) : __comp_(__c) {} template <class _Tp, class _Up> - bool operator()(const _Tp& __x, const _Up& __y) + _LIBCPP_CONSTEXPR_AFTER_CXX17 + bool operator()(const _Tp& __x, const _Up& __y) + { + bool __r = __comp_(__x, __y); + if (__r) + __do_compare_assert(0, __y, __x); + return __r; + } + + template <class _Tp, class _Up> + _LIBCPP_CONSTEXPR_AFTER_CXX17 + bool operator()(_Tp& __x, _Up& __y) { bool __r = __comp_(__x, __y); if (__r) @@ -794,25 +805,39 @@ struct __debug_less } template <class _LHS, class _RHS> + _LIBCPP_CONSTEXPR_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY decltype((void)_VSTD::declval<_Compare&>()( - _VSTD::declval<_LHS const&>(), _VSTD::declval<_RHS const&>())) - __do_compare_assert(int, _LHS const& __l, _RHS const& __r) { + _VSTD::declval<_LHS &>(), _VSTD::declval<_RHS &>())) + __do_compare_assert(int, _LHS & __l, _RHS & __r) { _LIBCPP_ASSERT(!__comp_(__l, __r), "Comparator does not induce a strict weak ordering"); } template <class _LHS, class _RHS> + _LIBCPP_CONSTEXPR_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY - void __do_compare_assert(long, _LHS const&, _RHS const&) {} + void __do_compare_assert(long, _LHS &, _RHS &) {} }; -#endif // _LIBCPP_DEBUG +#endif // _LIBCPP_DEBUG + +template <class _Comp> +struct __comp_ref_type { + // Pass the comparator by lvalue reference. Or in debug mode, using a + // debugging wrapper that stores a reference. +#ifndef _LIBCPP_DEBUG + typedef typename add_lvalue_reference<_Comp>::type type; +#else + typedef __debug_less<_Comp> type; +#endif +}; // all_of template <class _InputIterator, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { @@ -825,7 +850,8 @@ all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) // any_of template <class _InputIterator, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { @@ -838,7 +864,8 @@ any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) // none_of template <class _InputIterator, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) { @@ -883,7 +910,8 @@ for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) // find template <class _InputIterator, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) { @@ -896,7 +924,8 @@ find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) // find_if template <class _InputIterator, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { @@ -909,7 +938,8 @@ find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) // find_if_not template<class _InputIterator, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _InputIterator find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) { @@ -1044,7 +1074,8 @@ __find_end(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, } template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) @@ -1056,7 +1087,8 @@ find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, } template <class _ForwardIterator1, class _ForwardIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) @@ -1082,7 +1114,8 @@ __find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1, template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) @@ -1091,7 +1124,8 @@ find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, } template <class _ForwardIterator1, class _ForwardIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) @@ -1104,7 +1138,8 @@ find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1, // adjacent_find template <class _ForwardIterator, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { @@ -1122,7 +1157,8 @@ adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicat } template <class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator adjacent_find(_ForwardIterator __first, _ForwardIterator __last) { @@ -1133,7 +1169,8 @@ adjacent_find(_ForwardIterator __first, _ForwardIterator __last) // count template <class _InputIterator, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename iterator_traits<_InputIterator>::difference_type count(_InputIterator __first, _InputIterator __last, const _Tp& __value_) { @@ -1147,7 +1184,8 @@ count(_InputIterator __first, _InputIterator __last, const _Tp& __value_) // count_if template <class _InputIterator, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename iterator_traits<_InputIterator>::difference_type count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) { @@ -1161,7 +1199,8 @@ count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) // mismatch template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) @@ -1173,7 +1212,8 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1, } template <class _InputIterator1, class _InputIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { @@ -1184,7 +1224,8 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi #if _LIBCPP_STD_VER > 11 template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, @@ -1197,7 +1238,8 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1, } template <class _InputIterator1, class _InputIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_InputIterator1, _InputIterator2> mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) @@ -1211,7 +1253,8 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1, // equal template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) { @@ -1222,7 +1265,8 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first } template <class _InputIterator1, class _InputIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2) { @@ -1260,7 +1304,8 @@ __equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, } template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred ) @@ -1272,7 +1317,8 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, } template <class _InputIterator1, class _InputIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) @@ -1288,7 +1334,7 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, // is_permutation template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> -_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __pred) { @@ -1335,7 +1381,8 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, } template<class _ForwardIterator1, class _ForwardIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) @@ -1414,7 +1461,8 @@ __is_permutation(_RandomAccessIterator1 __first1, _RandomAccessIterator2 __last1 } template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, @@ -1427,7 +1475,8 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, } template<class _ForwardIterator1, class _ForwardIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) @@ -1445,7 +1494,8 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, // __search is in <functional> template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) @@ -1458,7 +1508,8 @@ search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, } template <class _ForwardIterator1, class _ForwardIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1 search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2) @@ -1471,7 +1522,7 @@ search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, #if _LIBCPP_STD_VER > 14 template <class _ForwardIterator, class _Searcher> -_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s) { return __s(__f, __l).first; } #endif @@ -1556,7 +1607,8 @@ __search_n(_RandomAccessIterator __first, _RandomAccessIterator __last, } template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_, _BinaryPredicate __pred) @@ -1567,7 +1619,8 @@ search_n(_ForwardIterator __first, _ForwardIterator __last, } template <class _ForwardIterator, class _Size, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_) { @@ -1611,6 +1664,18 @@ __unwrap_iter(__wrap_iter<_Tp*> __i) return __i.base(); } +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + const _Tp* +>::type +__unwrap_iter(__wrap_iter<const _Tp*> __i) +{ + return __i.base(); +} + #else template <class _Tp> @@ -1984,7 +2049,7 @@ generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) // generate_n template <class _OutputIterator, class _Size, class _Generator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) { @@ -1998,7 +2063,7 @@ generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) // remove template <class _ForwardIterator, class _Tp> -_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { __first = _VSTD::find(__first, __last, __value_); @@ -2020,7 +2085,7 @@ remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) // remove_if template <class _ForwardIterator, class _Predicate> -_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { __first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type> @@ -2079,7 +2144,7 @@ remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __ // unique template <class _ForwardIterator, class _BinaryPredicate> -_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { __first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type> @@ -2098,7 +2163,8 @@ unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pre } template <class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last) { @@ -2421,7 +2487,8 @@ rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterato // min_element template <class _ForwardIterator, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { @@ -2438,7 +2505,8 @@ min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) } template <class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator min_element(_ForwardIterator __first, _ForwardIterator __last) { @@ -2449,7 +2517,8 @@ min_element(_ForwardIterator __first, _ForwardIterator __last) // min template <class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& min(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -2457,7 +2526,8 @@ min(const _Tp& __a, const _Tp& __b, _Compare __comp) } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& min(const _Tp& __a, const _Tp& __b) { @@ -2467,7 +2537,8 @@ min(const _Tp& __a, const _Tp& __b) #ifndef _LIBCPP_CXX03_LANG template<class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp min(initializer_list<_Tp> __t, _Compare __comp) { @@ -2475,7 +2546,8 @@ min(initializer_list<_Tp> __t, _Compare __comp) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp min(initializer_list<_Tp> __t) { @@ -2487,7 +2559,8 @@ min(initializer_list<_Tp> __t) // max_element template <class _ForwardIterator, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { @@ -2505,7 +2578,8 @@ max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) template <class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator max_element(_ForwardIterator __first, _ForwardIterator __last) { @@ -2516,7 +2590,8 @@ max_element(_ForwardIterator __first, _ForwardIterator __last) // max template <class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& max(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -2524,7 +2599,8 @@ max(const _Tp& __a, const _Tp& __b, _Compare __comp) } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Tp& max(const _Tp& __a, const _Tp& __b) { @@ -2534,7 +2610,8 @@ max(const _Tp& __a, const _Tp& __b) #ifndef _LIBCPP_CXX03_LANG template<class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp max(initializer_list<_Tp> __t, _Compare __comp) { @@ -2542,7 +2619,8 @@ max(initializer_list<_Tp> __t, _Compare __comp) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp max(initializer_list<_Tp> __t) { @@ -2554,7 +2632,8 @@ max(initializer_list<_Tp> __t) #if _LIBCPP_STD_VER > 14 // clamp template<class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const _Tp& clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp) { @@ -2564,7 +2643,8 @@ clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const _Tp& clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi) { @@ -2575,7 +2655,7 @@ clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi) // minmax_element template <class _ForwardIterator, class _Compare> -_LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX11 std::pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { @@ -2625,7 +2705,8 @@ minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __com } template <class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 std::pair<_ForwardIterator, _ForwardIterator> minmax_element(_ForwardIterator __first, _ForwardIterator __last) { @@ -2636,7 +2717,8 @@ minmax_element(_ForwardIterator __first, _ForwardIterator __last) // minmax template<class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<const _Tp&, const _Tp&> minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) { @@ -2645,7 +2727,8 @@ minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<const _Tp&, const _Tp&> minmax(const _Tp& __a, const _Tp& __b) { @@ -2655,7 +2738,8 @@ minmax(const _Tp& __a, const _Tp& __b) #ifndef _LIBCPP_CXX03_LANG template<class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t, _Compare __comp) { @@ -2692,7 +2776,8 @@ minmax(initializer_list<_Tp> __t, _Compare __comp) } template<class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 pair<_Tp, _Tp> minmax(initializer_list<_Tp> __t) { @@ -2936,7 +3021,7 @@ _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK typedef __independent_bits_engine<_URNG, _UIntType> _Eng; if (_Rp == 0) return static_cast<result_type>(_Eng(__g, _Dt)()); - size_t __w = _Dt - __clz(_Rp) - 1; + size_t __w = _Dt - __libcpp_clz(_Rp) - 1; if ((_Rp & (std::numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0) ++__w; _Eng __e(__g, __w); @@ -2990,7 +3075,7 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) { _Dp __uid; __rs_default __g = __rs_get(); - for (--__last, --__d; __first < __last; ++__first, --__d) + for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d) { difference_type __i = __uid(__g, _Pp(0, __d)); if (__i != difference_type(0)) @@ -3012,7 +3097,7 @@ random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, difference_type __d = __last - __first; if (__d > 1) { - for (--__last; __first < __last; ++__first, --__d) + for (--__last; __first < __last; ++__first, (void) --__d) { difference_type __i = __rand(__d); if (__i != difference_type(0)) @@ -3096,11 +3181,7 @@ _SampleIterator sample(_PopulationIterator __first, template<class _RandomAccessIterator, class _UniformRandomNumberGenerator> void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, -#ifndef _LIBCPP_CXX03_LANG _UniformRandomNumberGenerator&& __g) -#else - _UniformRandomNumberGenerator& __g) -#endif { typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; typedef uniform_int_distribution<ptrdiff_t> _Dp; @@ -3119,7 +3200,7 @@ template<class _RandomAccessIterator, class _UniformRandomNumberGenerator> } template <class _InputIterator, class _Predicate> -_LIBCPP_CONSTEXPR_AFTER_CXX17 bool +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) { for (; __first != __last; ++__first) @@ -3527,7 +3608,7 @@ stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate _ // is_sorted_until template <class _ForwardIterator, class _Compare> -_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { if (__first != __last) @@ -3544,7 +3625,8 @@ is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __co } template<class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) { @@ -3554,7 +3636,8 @@ is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) // is_sorted template <class _ForwardIterator, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { @@ -3562,7 +3645,8 @@ is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) } template<class _ForwardIterator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool is_sorted(_ForwardIterator __first, _ForwardIterator __last) { @@ -4009,14 +4093,8 @@ inline _LIBCPP_INLINE_VISIBILITY void sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - __sort<_Comp_ref>(__first, __last, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; - __sort<_Comp_ref>(__first, __last, __comp); -#endif // _LIBCPP_DEBUG + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; + _VSTD::__sort<_Comp_ref>(__first, __last, _Comp_ref(__comp)); } template <class _RandomAccessIterator> @@ -4111,7 +4189,8 @@ __lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __va } template <class _ForwardIterator, class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { @@ -4120,7 +4199,8 @@ lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu } template <class _ForwardIterator, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { @@ -4153,7 +4233,8 @@ __upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __va } template <class _ForwardIterator, class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { @@ -4162,7 +4243,8 @@ upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __valu } template <class _ForwardIterator, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { @@ -4207,22 +4289,18 @@ __equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __va } template <class _ForwardIterator, class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __equal_range<_Comp_ref>(__first, __last, __value_, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __equal_range<_Comp_ref>(__first, __last, __value_, __comp); -#endif // _LIBCPP_DEBUG } template <class _ForwardIterator, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { @@ -4242,22 +4320,18 @@ __binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __ } template <class _ForwardIterator, class _Tp, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __binary_search<_Comp_ref>(__first, __last, __value_, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __binary_search<_Comp_ref>(__first, __last, __value_, __comp); -#endif // _LIBCPP_DEBUG } template <class _ForwardIterator, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { @@ -4296,14 +4370,8 @@ _OutputIterator merge(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); -#endif // _LIBCPP_DEBUG } template <class _InputIterator1, class _InputIterator2, class _OutputIterator> @@ -4478,17 +4546,9 @@ inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _ difference_type __buf_size = _VSTD::min(__len1, __len2); pair<value_type*, ptrdiff_t> __buf = _VSTD::get_temporary_buffer<value_type>(__buf_size); unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first); - -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __c, __len1, __len2, - __buf.first, __buf.second); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2, __buf.first, __buf.second); -#endif // _LIBCPP_DEBUG } template <class _BidirectionalIterator> @@ -4690,14 +4750,8 @@ stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compar __buf = _VSTD::get_temporary_buffer<value_type>(__len); __h.reset(__buf.first); } -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - __stable_sort<_Comp_ref>(__first, __last, __c, __len, __buf.first, __buf.second); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; __stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second); -#endif // _LIBCPP_DEBUG } template <class _RandomAccessIterator> @@ -4711,7 +4765,7 @@ stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) // is_heap_until template <class _RandomAccessIterator, class _Compare> -_LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator +_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::difference_type difference_type; @@ -4738,7 +4792,8 @@ is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Comp } template<class _RandomAccessIterator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) { @@ -4748,7 +4803,8 @@ is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) // is_heap template <class _RandomAccessIterator, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { @@ -4756,7 +4812,8 @@ is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __ } template<class _RandomAccessIterator> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { @@ -4797,14 +4854,8 @@ inline _LIBCPP_INLINE_VISIBILITY void push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - __sift_up<_Comp_ref>(__first, __last, __c, __last - __first); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; __sift_up<_Comp_ref>(__first, __last, __comp, __last - __first); -#endif // _LIBCPP_DEBUG } template <class _RandomAccessIterator> @@ -4890,14 +4941,8 @@ inline _LIBCPP_INLINE_VISIBILITY void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - __pop_heap<_Comp_ref>(__first, __last, __c, __last - __first); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; __pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first); -#endif // _LIBCPP_DEBUG } template <class _RandomAccessIterator> @@ -4931,14 +4976,8 @@ inline _LIBCPP_INLINE_VISIBILITY void make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - __make_heap<_Comp_ref>(__first, __last, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; __make_heap<_Comp_ref>(__first, __last, __comp); -#endif // _LIBCPP_DEBUG } template <class _RandomAccessIterator> @@ -4965,14 +5004,8 @@ inline _LIBCPP_INLINE_VISIBILITY void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - __sort_heap<_Comp_ref>(__first, __last, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; __sort_heap<_Comp_ref>(__first, __last, __comp); -#endif // _LIBCPP_DEBUG } template <class _RandomAccessIterator> @@ -5009,14 +5042,8 @@ void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - __partial_sort<_Comp_ref>(__first, __middle, __last, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; __partial_sort<_Comp_ref>(__first, __middle, __last, __comp); -#endif // _LIBCPP_DEBUG } template <class _RandomAccessIterator> @@ -5059,14 +5086,8 @@ _RandomAccessIterator partial_sort_copy(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __comp); -#endif // _LIBCPP_DEBUG } template <class _InputIterator, class _RandomAccessIterator> @@ -5273,14 +5294,8 @@ inline _LIBCPP_INLINE_VISIBILITY void nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - __nth_element<_Comp_ref>(__first, __nth, __last, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; __nth_element<_Comp_ref>(__first, __nth, __last, __comp); -#endif // _LIBCPP_DEBUG } template <class _RandomAccessIterator> @@ -5309,23 +5324,19 @@ __includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __ } template <class _InputIterator1, class _InputIterator2, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); -#endif // _LIBCPP_DEBUG } template <class _InputIterator1, class _InputIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { @@ -5367,14 +5378,8 @@ _OutputIterator set_union(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); -#endif // _LIBCPP_DEBUG } template <class _InputIterator1, class _InputIterator2, class _OutputIterator> @@ -5419,14 +5424,8 @@ _OutputIterator set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); -#endif // _LIBCPP_DEBUG } template <class _InputIterator1, class _InputIterator2, class _OutputIterator> @@ -5473,14 +5472,8 @@ _OutputIterator set_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); -#endif // _LIBCPP_DEBUG } template <class _InputIterator1, class _InputIterator2, class _OutputIterator> @@ -5532,14 +5525,8 @@ _OutputIterator set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); -#endif // _LIBCPP_DEBUG } template <class _InputIterator1, class _InputIterator2, class _OutputIterator> @@ -5571,23 +5558,19 @@ __lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, } template <class _InputIterator1, class _InputIterator2, class _Compare> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); -#endif // _LIBCPP_DEBUG } template <class _InputIterator1, class _InputIterator2> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_LIBCPP_NODISCARD_EXT inline +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) @@ -5631,14 +5614,8 @@ inline _LIBCPP_INLINE_VISIBILITY bool next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __next_permutation<_Comp_ref>(__first, __last, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __next_permutation<_Comp_ref>(__first, __last, __comp); -#endif // _LIBCPP_DEBUG } template <class _BidirectionalIterator> @@ -5684,14 +5661,8 @@ inline _LIBCPP_INLINE_VISIBILITY bool prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) { -#ifdef _LIBCPP_DEBUG - typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; - __debug_less<_Compare> __c(__comp); - return __prev_permutation<_Comp_ref>(__first, __last, __c); -#else // _LIBCPP_DEBUG - typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + typedef typename __comp_ref_type<_Compare>::type _Comp_ref; return __prev_permutation<_Comp_ref>(__first, __last, __comp); -#endif // _LIBCPP_DEBUG } template <class _BidirectionalIterator> diff --git a/include/any b/include/any index 781eee7869c0..36b07c9d7e75 100644 --- a/include/any +++ b/include/any @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------------ any -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -508,7 +507,7 @@ any::any(_ValueType && __v) : __h(nullptr) template <class _ValueType, class ..._Args, class _Tp, class> any::any(in_place_type_t<_ValueType>, _Args&&... __args) { __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...); -}; +} template <class _ValueType, class _Up, class ..._Args, class _Tp, class> any::any(in_place_type_t<_ValueType>, initializer_list<_Up> __il, _Args&&... __args) { diff --git a/include/array b/include/array index 56f6887655aa..88e9d57ff783 100644 --- a/include/array +++ b/include/array @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- array -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -92,7 +91,7 @@ template <class T, size_t N > void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17 template <class T> struct tuple_size; -template <size_t I, class T> class tuple_element; +template <size_t I, class T> struct tuple_element; template <class T, size_t N> struct tuple_size<array<T, N>>; template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 @@ -191,17 +190,17 @@ struct _LIBCPP_TEMPLATE_VIS array // element access: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - reference operator[](size_type __n) {return __elems_[__n];} + reference operator[](size_type __n) _NOEXCEPT {return __elems_[__n];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - const_reference operator[](size_type __n) const {return __elems_[__n];} + const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];} _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n); _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const; - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() {return __elems_[0];} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const {return __elems_[0];} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() {return __elems_[_Size - 1];} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size - 1];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return __elems_[0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return __elems_[_Size - 1];} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return __elems_[_Size - 1];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 value_type* data() _NOEXCEPT {return __elems_;} @@ -304,13 +303,13 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> // element access: _LIBCPP_INLINE_VISIBILITY - reference operator[](size_type) { + reference operator[](size_type) _NOEXCEPT { _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); _LIBCPP_UNREACHABLE(); } _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - const_reference operator[](size_type) const { + const_reference operator[](size_type) const _NOEXCEPT { _LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array"); _LIBCPP_UNREACHABLE(); } @@ -328,25 +327,25 @@ struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0> } _LIBCPP_INLINE_VISIBILITY - reference front() { + reference front() _NOEXCEPT { _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); _LIBCPP_UNREACHABLE(); } _LIBCPP_INLINE_VISIBILITY - const_reference front() const { + const_reference front() const _NOEXCEPT { _LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array"); _LIBCPP_UNREACHABLE(); } _LIBCPP_INLINE_VISIBILITY - reference back() { + reference back() _NOEXCEPT { _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); _LIBCPP_UNREACHABLE(); } _LIBCPP_INLINE_VISIBILITY - const_reference back() const { + const_reference back() const _NOEXCEPT { _LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array"); _LIBCPP_UNREACHABLE(); } @@ -434,10 +433,9 @@ struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> > : public integral_constant<size_t, _Size> {}; template <size_t _Ip, class _Tp, size_t _Size> -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> > { static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)"); -public: typedef _Tp type; }; diff --git a/include/atomic b/include/atomic index d37e7b4b035c..afb431eda11d 100644 --- a/include/atomic +++ b/include/atomic @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- atomic -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -21,17 +20,24 @@ namespace std #define __cpp_lib_atomic_is_always_lock_free // as specified by SG10 -// order and consistency - -typedef enum memory_order -{ - memory_order_relaxed, - memory_order_consume, // load-consume - memory_order_acquire, // load-acquire - memory_order_release, // store-release - memory_order_acq_rel, // store-release load-acquire - memory_order_seq_cst // store-release load-acquire -} memory_order; + // order and consistency + + enum memory_order: unspecified // enum class in C++20 + { + relaxed, + consume, // load-consume + acquire, // load-acquire + release, // store-release + acq_rel, // store-release load-acquire + seq_cst // store-release load-acquire + }; + + inline constexpr auto memory_order_relaxed = memory_order::relaxed; + inline constexpr auto memory_order_consume = memory_order::consume; + inline constexpr auto memory_order_acquire = memory_order::acquire; + inline constexpr auto memory_order_release = memory_order::release; + inline constexpr auto memory_order_acq_rel = memory_order::acq_rel; + inline constexpr auto memory_order_seq_cst = memory_order::seq_cst; template <class T> T kill_dependency(T y) noexcept; @@ -551,13 +557,13 @@ void atomic_signal_fence(memory_order m) noexcept; #endif #ifdef _LIBCPP_HAS_NO_THREADS -#error <atomic> is not supported on this single threaded system +# error <atomic> is not supported on this single threaded system #endif -#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) -#error <atomic> is not implemented +#ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER +# error <atomic> is not implemented #endif #ifdef kill_dependency -#error C++ standard library is incompatible with <stdatomic.h> +# error C++ standard library is incompatible with <stdatomic.h> #endif #define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \ @@ -578,49 +584,94 @@ void atomic_signal_fence(memory_order m) noexcept; _LIBCPP_BEGIN_NAMESPACE_STD -typedef enum memory_order -{ - memory_order_relaxed, memory_order_consume, memory_order_acquire, - memory_order_release, memory_order_acq_rel, memory_order_seq_cst +// Figure out what the underlying type for `memory_order` would be if it were +// declared as an unscoped enum (accounting for -fshort-enums). Use this result +// to pin the underlying type in C++20. +enum __legacy_memory_order { + __mo_relaxed, + __mo_consume, + __mo_acquire, + __mo_release, + __mo_acq_rel, + __mo_seq_cst +}; + +typedef underlying_type<__legacy_memory_order>::type __memory_order_underlying_t; + +#if _LIBCPP_STD_VER > 17 + +enum class memory_order : __memory_order_underlying_t { + relaxed = __mo_relaxed, + consume = __mo_consume, + acquire = __mo_acquire, + release = __mo_release, + acq_rel = __mo_acq_rel, + seq_cst = __mo_seq_cst +}; + +inline constexpr auto memory_order_relaxed = memory_order::relaxed; +inline constexpr auto memory_order_consume = memory_order::consume; +inline constexpr auto memory_order_acquire = memory_order::acquire; +inline constexpr auto memory_order_release = memory_order::release; +inline constexpr auto memory_order_acq_rel = memory_order::acq_rel; +inline constexpr auto memory_order_seq_cst = memory_order::seq_cst; + +#else + +typedef enum memory_order { + memory_order_relaxed = __mo_relaxed, + memory_order_consume = __mo_consume, + memory_order_acquire = __mo_acquire, + memory_order_release = __mo_release, + memory_order_acq_rel = __mo_acq_rel, + memory_order_seq_cst = __mo_seq_cst, } memory_order; -#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) -namespace __gcc_atomic { -template <typename _Tp> -struct __gcc_atomic_t { +#endif // _LIBCPP_STD_VER > 17 + +static_assert((is_same<underlying_type<memory_order>::type, __memory_order_underlying_t>::value), + "unexpected underlying type for std::memory_order"); + +#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) || \ + defined(_LIBCPP_ATOMIC_ONLY_USE_BUILTINS) + +// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because +// the default operator= in an object is not volatile, a byte-by-byte copy +// is required. +template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY +typename enable_if<is_assignable<_Tp&, _Tv>::value>::type +__cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) { + __a_value = __val; +} +template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY +typename enable_if<is_assignable<_Tp&, _Tv>::value>::type +__cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) { + volatile char* __to = reinterpret_cast<volatile char*>(&__a_value); + volatile char* __end = __to + sizeof(_Tp); + volatile const char* __from = reinterpret_cast<volatile const char*>(&__val); + while (__to != __end) + *__to++ = *__from++; +} -#if _GNUC_VER >= 501 - static_assert(is_trivially_copyable<_Tp>::value, - "std::atomic<Tp> requires that 'Tp' be a trivially copyable type"); #endif +#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) + +template <typename _Tp> +struct __cxx_atomic_base_impl { + _LIBCPP_INLINE_VISIBILITY #ifndef _LIBCPP_CXX03_LANG - __gcc_atomic_t() _NOEXCEPT = default; + __cxx_atomic_base_impl() _NOEXCEPT = default; #else - __gcc_atomic_t() _NOEXCEPT : __a_value() {} + __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} #endif // _LIBCPP_CXX03_LANG - _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT + _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT : __a_value(value) {} _Tp __a_value; }; -#define _Atomic(x) __gcc_atomic::__gcc_atomic_t<x> - -template <typename _Tp> _Tp __create(); - -template <typename _Tp, typename _Td> -typename enable_if<sizeof(_Tp()->__a_value = __create<_Td>()), char>::type - __test_atomic_assignable(int); -template <typename _Tp, typename _Up> -__two __test_atomic_assignable(...); - -template <typename _Tp, typename _Td> -struct __can_assign { - static const bool value = - sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char); -}; -static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) { +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) { // Avoid switch statement to make this a constexpr. return __order == memory_order_relaxed ? __ATOMIC_RELAXED: (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: @@ -630,7 +681,7 @@ static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) { __ATOMIC_CONSUME)))); } -static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) { +_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) { // Avoid switch statement to make this a constexpr. return __order == memory_order_relaxed ? __ATOMIC_RELAXED: (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: @@ -640,133 +691,125 @@ static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) __ATOMIC_CONSUME)))); } -} // namespace __gcc_atomic - -template <typename _Tp> -static inline -typename enable_if< - __gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value>::type -__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) { - __a->__a_value = __val; -} - template <typename _Tp> -static inline -typename enable_if< - !__gcc_atomic::__can_assign<volatile _Atomic(_Tp)*, _Tp>::value && - __gcc_atomic::__can_assign< _Atomic(_Tp)*, _Tp>::value>::type -__c11_atomic_init(volatile _Atomic(_Tp)* __a, _Tp __val) { - // [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because - // the default operator= in an object is not volatile, a byte-by-byte copy - // is required. - volatile char* to = reinterpret_cast<volatile char*>(&__a->__a_value); - volatile char* end = to + sizeof(_Tp); - char* from = reinterpret_cast<char*>(&__val); - while (to != end) { - *to++ = *from++; - } +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { + __cxx_atomic_assign_volatile(__a->__a_value, __val); } template <typename _Tp> -static inline void __c11_atomic_init(_Atomic(_Tp)* __a, _Tp __val) { +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) { __a->__a_value = __val; } -static inline void __c11_atomic_thread_fence(memory_order __order) { - __atomic_thread_fence(__gcc_atomic::__to_gcc_order(__order)); +_LIBCPP_INLINE_VISIBILITY inline +void __cxx_atomic_thread_fence(memory_order __order) { + __atomic_thread_fence(__to_gcc_order(__order)); } -static inline void __c11_atomic_signal_fence(memory_order __order) { - __atomic_signal_fence(__gcc_atomic::__to_gcc_order(__order)); +_LIBCPP_INLINE_VISIBILITY inline +void __cxx_atomic_signal_fence(memory_order __order) { + __atomic_signal_fence(__to_gcc_order(__order)); } template <typename _Tp> -static inline void __c11_atomic_store(volatile _Atomic(_Tp)* __a, _Tp __val, - memory_order __order) { - return __atomic_store(&__a->__a_value, &__val, - __gcc_atomic::__to_gcc_order(__order)); +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val, + memory_order __order) { + __atomic_store(&__a->__a_value, &__val, + __to_gcc_order(__order)); } template <typename _Tp> -static inline void __c11_atomic_store(_Atomic(_Tp)* __a, _Tp __val, - memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val, + memory_order __order) { __atomic_store(&__a->__a_value, &__val, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp> -static inline _Tp __c11_atomic_load(const volatile _Atomic(_Tp)* __a, - memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a, + memory_order __order) { _Tp __ret; __atomic_load(&__a->__a_value, &__ret, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); return __ret; } template <typename _Tp> -static inline _Tp __c11_atomic_load(const _Atomic(_Tp)* __a, memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) { _Tp __ret; __atomic_load(&__a->__a_value, &__ret, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); return __ret; } template <typename _Tp> -static inline _Tp __c11_atomic_exchange(volatile _Atomic(_Tp)* __a, - _Tp __value, memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp __value, memory_order __order) { _Tp __ret; __atomic_exchange(&__a->__a_value, &__value, &__ret, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); return __ret; } template <typename _Tp> -static inline _Tp __c11_atomic_exchange(_Atomic(_Tp)* __a, _Tp __value, - memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value, + memory_order __order) { _Tp __ret; __atomic_exchange(&__a->__a_value, &__value, &__ret, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); return __ret; } template <typename _Tp> -static inline bool __c11_atomic_compare_exchange_strong( - volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong( + volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, false, - __gcc_atomic::__to_gcc_order(__success), - __gcc_atomic::__to_gcc_failure_order(__failure)); + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); } template <typename _Tp> -static inline bool __c11_atomic_compare_exchange_strong( - _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success, +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong( + __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, false, - __gcc_atomic::__to_gcc_order(__success), - __gcc_atomic::__to_gcc_failure_order(__failure)); + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); } template <typename _Tp> -static inline bool __c11_atomic_compare_exchange_weak( - volatile _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak( + volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, true, - __gcc_atomic::__to_gcc_order(__success), - __gcc_atomic::__to_gcc_failure_order(__failure)); + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); } template <typename _Tp> -static inline bool __c11_atomic_compare_exchange_weak( - _Atomic(_Tp)* __a, _Tp* __expected, _Tp __value, memory_order __success, +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak( + __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) { return __atomic_compare_exchange(&__a->__a_value, __expected, &__value, true, - __gcc_atomic::__to_gcc_order(__success), - __gcc_atomic::__to_gcc_failure_order(__failure)); + __to_gcc_order(__success), + __to_gcc_failure_order(__failure)); } template <typename _Tp> @@ -783,80 +826,264 @@ template <typename _Tp, int n> struct __skip_amt<_Tp[n]> { }; template <typename _Tp, typename _Td> -static inline _Tp __c11_atomic_fetch_add(volatile _Atomic(_Tp)* __a, - _Td __delta, memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Td __delta, memory_order __order) { return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp, typename _Td> -static inline _Tp __c11_atomic_fetch_add(_Atomic(_Tp)* __a, _Td __delta, - memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, + memory_order __order) { return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp, typename _Td> -static inline _Tp __c11_atomic_fetch_sub(volatile _Atomic(_Tp)* __a, - _Td __delta, memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Td __delta, memory_order __order) { return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp, typename _Td> -static inline _Tp __c11_atomic_fetch_sub(_Atomic(_Tp)* __a, _Td __delta, - memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta, + memory_order __order) { return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp> -static inline _Tp __c11_atomic_fetch_and(volatile _Atomic(_Tp)* __a, - _Tp __pattern, memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp __pattern, memory_order __order) { return __atomic_fetch_and(&__a->__a_value, __pattern, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp> -static inline _Tp __c11_atomic_fetch_and(_Atomic(_Tp)* __a, - _Tp __pattern, memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a, + _Tp __pattern, memory_order __order) { return __atomic_fetch_and(&__a->__a_value, __pattern, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp> -static inline _Tp __c11_atomic_fetch_or(volatile _Atomic(_Tp)* __a, - _Tp __pattern, memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp __pattern, memory_order __order) { return __atomic_fetch_or(&__a->__a_value, __pattern, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp> -static inline _Tp __c11_atomic_fetch_or(_Atomic(_Tp)* __a, _Tp __pattern, - memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, + memory_order __order) { return __atomic_fetch_or(&__a->__a_value, __pattern, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp> -static inline _Tp __c11_atomic_fetch_xor(volatile _Atomic(_Tp)* __a, - _Tp __pattern, memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a, + _Tp __pattern, memory_order __order) { return __atomic_fetch_xor(&__a->__a_value, __pattern, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); } template <typename _Tp> -static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern, - memory_order __order) { +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern, + memory_order __order) { return __atomic_fetch_xor(&__a->__a_value, __pattern, - __gcc_atomic::__to_gcc_order(__order)); + __to_gcc_order(__order)); +} + +#define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0) + +#elif defined(_LIBCPP_HAS_C_ATOMIC_IMP) + +template <typename _Tp> +struct __cxx_atomic_base_impl { + + _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_CXX03_LANG + __cxx_atomic_base_impl() _NOEXCEPT = default; +#else + __cxx_atomic_base_impl() _NOEXCEPT : __a_value() {} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT + : __a_value(value) {} + _Atomic(_Tp) __a_value; +}; + +#define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s) + +_LIBCPP_INLINE_VISIBILITY inline +void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT { + __c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order)); +} + +_LIBCPP_INLINE_VISIBILITY inline +void __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT { + __c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT { + __c11_atomic_init(&__a->__a_value, __val); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val) _NOEXCEPT { + __c11_atomic_init(&__a->__a_value, __val); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT { + __c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val, memory_order __order) _NOEXCEPT { + __c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT { + using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*; + return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT { + using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*; + return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT { + return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> * __a, _Tp __value, memory_order __order) _NOEXCEPT { + return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT { + return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT { + return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT { + return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT { + return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); } -#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT { + return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order)); +} + +#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_Tp -kill_dependency(_Tp __y) _NOEXCEPT +_LIBCPP_INLINE_VISIBILITY +_Tp kill_dependency(_Tp __y) _NOEXCEPT { return __y; } @@ -872,7 +1099,7 @@ kill_dependency(_Tp __y) _NOEXCEPT # define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE # define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE # define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE -#else +#elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE) # define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE # define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE # define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE @@ -885,12 +1112,352 @@ kill_dependency(_Tp __y) _NOEXCEPT # define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE #endif +#ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS + +template<typename _Tp> +struct __cxx_atomic_lock_impl { + + _LIBCPP_INLINE_VISIBILITY + __cxx_atomic_lock_impl() _NOEXCEPT + : __a_value(), __a_lock(0) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit + __cxx_atomic_lock_impl(_Tp value) _NOEXCEPT + : __a_value(value), __a_lock(0) {} + + _Tp __a_value; + mutable __cxx_atomic_base_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_lock; + + _LIBCPP_INLINE_VISIBILITY void __lock() const volatile { + while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire)) + /*spin*/; + } + _LIBCPP_INLINE_VISIBILITY void __lock() const { + while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire)) + /*spin*/; + } + _LIBCPP_INLINE_VISIBILITY void __unlock() const volatile { + __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release); + } + _LIBCPP_INLINE_VISIBILITY void __unlock() const { + __cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release); + } + _LIBCPP_INLINE_VISIBILITY _Tp __read() const volatile { + __lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a_value); + __unlock(); + return __old; + } + _LIBCPP_INLINE_VISIBILITY _Tp __read() const { + __lock(); + _Tp __old = __a_value; + __unlock(); + return __old; + } +}; + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) { + __cxx_atomic_assign_volatile(__a->__a_value, __val); +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_init(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) { + __a->__a_value = __val; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) { + __a->__lock(); + __cxx_atomic_assign_volatile(__a->__a_value, __val); + __a->__unlock(); +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +void __cxx_atomic_store(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) { + __a->__lock(); + __a->__a_value = __val; + __a->__unlock(); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(const volatile __cxx_atomic_lock_impl<_Tp>* __a, memory_order) { + return __a->__read(); +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_load(const __cxx_atomic_lock_impl<_Tp>* __a, memory_order) { + return __a->__read(); +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, __value); + __a->__unlock(); + return __old; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_exchange(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value = __value; + __a->__unlock(); + return __old; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp* __expected, _Tp __value, memory_order, memory_order) { + __a->__lock(); + _Tp temp; + __cxx_atomic_assign_volatile(temp, __a->__a_value); + bool __ret = temp == *__expected; + if(__ret) + __cxx_atomic_assign_volatile(__a->__a_value, __value); + else + __cxx_atomic_assign_volatile(*__expected, __a->__a_value); + __a->__unlock(); + return __ret; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp* __expected, _Tp __value, memory_order, memory_order) { + __a->__lock(); + bool __ret = __a->__a_value == *__expected; + if(__ret) + __a->__a_value = __value; + else + *__expected = __a->__a_value; + __a->__unlock(); + return __ret; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp* __expected, _Tp __value, memory_order, memory_order) { + __a->__lock(); + _Tp temp; + __cxx_atomic_assign_volatile(temp, __a->__a_value); + bool __ret = temp == *__expected; + if(__ret) + __cxx_atomic_assign_volatile(__a->__a_value, __value); + else + __cxx_atomic_assign_volatile(*__expected, __a->__a_value); + __a->__unlock(); + return __ret; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp* __expected, _Tp __value, memory_order, memory_order) { + __a->__lock(); + bool __ret = __a->__a_value == *__expected; + if(__ret) + __a->__a_value = __value; + else + *__expected = __a->__a_value; + __a->__unlock(); + return __ret; +} + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Td __delta, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old + __delta)); + __a->__unlock(); + return __old; +} +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp>* __a, + _Td __delta, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value += __delta; + __a->__unlock(); + return __old; +} + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp*>* __a, + ptrdiff_t __delta, memory_order) { + __a->__lock(); + _Tp* __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, __old + __delta); + __a->__unlock(); + return __old; +} +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp* __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp*>* __a, + ptrdiff_t __delta, memory_order) { + __a->__lock(); + _Tp* __old = __a->__a_value; + __a->__a_value += __delta; + __a->__unlock(); + return __old; +} + +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Td __delta, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old - __delta)); + __a->__unlock(); + return __old; +} +template <typename _Tp, typename _Td> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_sub(__cxx_atomic_lock_impl<_Tp>* __a, + _Td __delta, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value -= __delta; + __a->__unlock(); + return __old; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old & __pattern)); + __a->__unlock(); + return __old; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_and(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value &= __pattern; + __a->__unlock(); + return __old; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old | __pattern)); + __a->__unlock(); + return __old; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_or(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value |= __pattern; + __a->__unlock(); + return __old; +} + +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old; + __cxx_atomic_assign_volatile(__old, __a->__a_value); + __cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old ^ __pattern)); + __a->__unlock(); + return __old; +} +template <typename _Tp> +_LIBCPP_INLINE_VISIBILITY +_Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a, + _Tp __pattern, memory_order) { + __a->__lock(); + _Tp __old = __a->__a_value; + __a->__a_value ^= __pattern; + __a->__unlock(); + return __old; +} + +#ifdef __cpp_lib_atomic_is_always_lock_free + +template<typename _Tp> struct __cxx_is_always_lock_free { + enum { __value = __atomic_always_lock_free(sizeof(_Tp), 0) }; }; + +#else + +template<typename _Tp> struct __cxx_is_always_lock_free { enum { __value = false }; }; +// Implementations must match the C ATOMIC_*_LOCK_FREE macro values. +template<> struct __cxx_is_always_lock_free<bool> { enum { __value = 2 == ATOMIC_BOOL_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<signed char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<char16_t> { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<char32_t> { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<wchar_t> { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<unsigned long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; }; +template<typename _Tp> struct __cxx_is_always_lock_free<_Tp*> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; }; +template<> struct __cxx_is_always_lock_free<std::nullptr_t> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; }; + +#endif //__cpp_lib_atomic_is_always_lock_free + +template <typename _Tp, + typename _Base = typename conditional<__cxx_is_always_lock_free<_Tp>::__value, + __cxx_atomic_base_impl<_Tp>, + __cxx_atomic_lock_impl<_Tp> >::type> +#else +template <typename _Tp, + typename _Base = __cxx_atomic_base_impl<_Tp> > +#endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS +struct __cxx_atomic_impl : public _Base { + +#if _GNUC_VER >= 501 + static_assert(is_trivially_copyable<_Tp>::value, + "std::atomic<Tp> requires that 'Tp' be a trivially copyable type"); +#endif + + _LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT _LIBCPP_DEFAULT + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT + : _Base(value) {} +}; + // general atomic<T> template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value> struct __atomic_base // false { - mutable _Atomic(_Tp) __a_; + mutable __cxx_atomic_impl<_Tp> __a_; #if defined(__cpp_lib_atomic_is_always_lock_free) static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0); @@ -898,88 +1465,79 @@ struct __atomic_base // false _LIBCPP_INLINE_VISIBILITY bool is_lock_free() const volatile _NOEXCEPT - { -#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) - return __c11_atomic_is_lock_free(sizeof(_Tp)); -#else - return __atomic_is_lock_free(sizeof(_Tp), 0); -#endif - } + {return __cxx_atomic_is_lock_free(sizeof(_Tp));} _LIBCPP_INLINE_VISIBILITY bool is_lock_free() const _NOEXCEPT {return static_cast<__atomic_base const volatile*>(this)->is_lock_free();} _LIBCPP_INLINE_VISIBILITY void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) - {__c11_atomic_store(&__a_, __d, __m);} + {__cxx_atomic_store(&__a_, __d, __m);} _LIBCPP_INLINE_VISIBILITY void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) - {__c11_atomic_store(&__a_, __d, __m);} + {__cxx_atomic_store(&__a_, __d, __m);} _LIBCPP_INLINE_VISIBILITY _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) - {return __c11_atomic_load(&__a_, __m);} + {return __cxx_atomic_load(&__a_, __m);} _LIBCPP_INLINE_VISIBILITY _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) - {return __c11_atomic_load(&__a_, __m);} + {return __cxx_atomic_load(&__a_, __m);} _LIBCPP_INLINE_VISIBILITY operator _Tp() const volatile _NOEXCEPT {return load();} _LIBCPP_INLINE_VISIBILITY operator _Tp() const _NOEXCEPT {return load();} _LIBCPP_INLINE_VISIBILITY _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_exchange(&__a_, __d, __m);} + {return __cxx_atomic_exchange(&__a_, __d, __m);} _LIBCPP_INLINE_VISIBILITY _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_exchange(&__a_, __d, __m);} + {return __cxx_atomic_exchange(&__a_, __d, __m);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) - {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} + {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) - {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} + {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) volatile _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) - {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} + {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f) - {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} + {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} + {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_weak(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} + {return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} + {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} _LIBCPP_INLINE_VISIBILITY bool compare_exchange_strong(_Tp& __e, _Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} + {return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_CXX03_LANG - __atomic_base() _NOEXCEPT = default; -#else - __atomic_base() _NOEXCEPT : __a_() {} -#endif // _LIBCPP_CXX03_LANG + __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR + __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} #ifndef _LIBCPP_CXX03_LANG __atomic_base(const __atomic_base&) = delete; __atomic_base& operator=(const __atomic_base&) = delete; @@ -1011,34 +1569,34 @@ struct __atomic_base<_Tp, true> _LIBCPP_INLINE_VISIBILITY _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_fetch_and(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_fetch_and(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_and(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_fetch_or(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_fetch_or(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_or(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));} @@ -1120,17 +1678,17 @@ struct atomic<_Tp*> _LIBCPP_INLINE_VISIBILITY _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_add(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} + {return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);} _LIBCPP_INLINE_VISIBILITY _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);} @@ -1161,7 +1719,7 @@ struct atomic<_Tp*> // atomic_is_lock_free template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT { @@ -1169,7 +1727,7 @@ atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT { @@ -1179,25 +1737,25 @@ atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT // atomic_init template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY void atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT { - __c11_atomic_init(&__o->__a_, __d); + __cxx_atomic_init(&__o->__a_, __d); } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY void atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT { - __c11_atomic_init(&__o->__a_, __d); + __cxx_atomic_init(&__o->__a_, __d); } // atomic_store template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY void atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT { @@ -1205,7 +1763,7 @@ atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY void atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT { @@ -1215,7 +1773,7 @@ atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT // atomic_store_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY void atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) @@ -1224,7 +1782,7 @@ atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOE } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY void atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) @@ -1235,7 +1793,7 @@ atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT // atomic_load template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT { @@ -1243,7 +1801,7 @@ atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp atomic_load(const atomic<_Tp>* __o) _NOEXCEPT { @@ -1253,7 +1811,7 @@ atomic_load(const atomic<_Tp>* __o) _NOEXCEPT // atomic_load_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) @@ -1262,7 +1820,7 @@ atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEP } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) @@ -1273,7 +1831,7 @@ atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT // atomic_exchange template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT { @@ -1281,7 +1839,7 @@ atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT { @@ -1291,7 +1849,7 @@ atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT // atomic_exchange_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT { @@ -1299,7 +1857,7 @@ atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _ } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT { @@ -1309,7 +1867,7 @@ atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT // atomic_compare_exchange_weak template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT { @@ -1317,7 +1875,7 @@ atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEX } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT { @@ -1327,7 +1885,7 @@ atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT // atomic_compare_exchange_strong template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT { @@ -1335,7 +1893,7 @@ atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NO } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT { @@ -1345,7 +1903,7 @@ atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT // atomic_compare_exchange_weak_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d, @@ -1356,7 +1914,7 @@ atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, memory_order __s, memory_order __f) _NOEXCEPT @@ -1368,7 +1926,7 @@ atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, // atomic_compare_exchange_strong_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d, @@ -1379,7 +1937,7 @@ atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY bool atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, @@ -1392,7 +1950,7 @@ atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, // atomic_fetch_add template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1404,7 +1962,7 @@ atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1416,7 +1974,7 @@ atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp* atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT { @@ -1424,7 +1982,7 @@ atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp* atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT { @@ -1434,7 +1992,7 @@ atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT // atomic_fetch_add_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1446,7 +2004,7 @@ atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1458,7 +2016,7 @@ atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEP } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp* atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT @@ -1467,7 +2025,7 @@ atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp* atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT { @@ -1477,7 +2035,7 @@ atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _ // atomic_fetch_sub template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1489,7 +2047,7 @@ atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1501,7 +2059,7 @@ atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp* atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT { @@ -1509,7 +2067,7 @@ atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp* atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT { @@ -1519,7 +2077,7 @@ atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT // atomic_fetch_sub_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1531,7 +2089,7 @@ atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1543,7 +2101,7 @@ atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEP } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp* atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT @@ -1552,7 +2110,7 @@ atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY _Tp* atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT { @@ -1562,7 +2120,7 @@ atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _ // atomic_fetch_and template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1574,7 +2132,7 @@ atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1588,7 +2146,7 @@ atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT // atomic_fetch_and_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1600,7 +2158,7 @@ atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1614,7 +2172,7 @@ atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEP // atomic_fetch_or template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1626,7 +2184,7 @@ atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1640,7 +2198,7 @@ atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT // atomic_fetch_or_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1652,7 +2210,7 @@ atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1666,7 +2224,7 @@ atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT // atomic_fetch_xor template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1678,7 +2236,7 @@ atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1692,7 +2250,7 @@ atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT // atomic_fetch_xor_explicit template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1704,7 +2262,7 @@ atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) } template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename enable_if < is_integral<_Tp>::value && !is_same<_Tp, bool>::value, @@ -1719,27 +2277,23 @@ atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEP typedef struct atomic_flag { - _Atomic(bool) __a_; + __cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_; _LIBCPP_INLINE_VISIBILITY bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {return __c11_atomic_exchange(&__a_, true, __m);} + {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);} _LIBCPP_INLINE_VISIBILITY bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT - {return __c11_atomic_exchange(&__a_, true, __m);} + {return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);} _LIBCPP_INLINE_VISIBILITY void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT - {__c11_atomic_store(&__a_, false, __m);} + {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);} _LIBCPP_INLINE_VISIBILITY void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT - {__c11_atomic_store(&__a_, false, __m);} + {__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);} _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_CXX03_LANG - atomic_flag() _NOEXCEPT = default; -#else - atomic_flag() _NOEXCEPT : __a_() {} -#endif // _LIBCPP_CXX03_LANG + atomic_flag() _NOEXCEPT _LIBCPP_DEFAULT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION @@ -1818,14 +2372,14 @@ inline _LIBCPP_INLINE_VISIBILITY void atomic_thread_fence(memory_order __m) _NOEXCEPT { - __c11_atomic_thread_fence(__m); + __cxx_atomic_thread_fence(__m); } inline _LIBCPP_INLINE_VISIBILITY void atomic_signal_fence(memory_order __m) _NOEXCEPT { - __c11_atomic_signal_fence(__m); + __cxx_atomic_signal_fence(__m); } // Atomics for standard typedef types diff --git a/include/bit b/include/bit index db3812e5b5b2..1c0e8ad3ba8b 100644 --- a/include/bit +++ b/include/bit @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------------ bit ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===---------------------------------------------------------------------===// @@ -16,12 +15,42 @@ namespace std { + template <class T> + constexpr bool ispow2(T x) noexcept; // C++20 + template <class T> + constexpr T ceil2(T x); // C++20 + template <class T> + constexpr T floor2(T x) noexcept; // C++20 + template <class T> + constexpr T log2p1(T x) noexcept; // C++20 + + // 23.20.2, rotating + template<class T> + constexpr T rotl(T x, unsigned int s) noexcept; // C++20 + template<class T> + constexpr T rotr(T x, unsigned int s) noexcept; // C++20 + + // 23.20.3, counting + template<class T> + constexpr int countl_zero(T x) noexcept; // C++20 + template<class T> + constexpr int countl_one(T x) noexcept; // C++20 + template<class T> + constexpr int countr_zero(T x) noexcept; // C++20 + template<class T> + constexpr int countr_one(T x) noexcept; // C++20 + template<class T> + constexpr int popcount(T x) noexcept; // C++20 + } // namespace std */ #include <__config> +#include <limits> +#include <type_traits> #include <version> +#include <__debug> #if defined(__IBMCPP__) #include "support/ibm/support.h" @@ -34,44 +63,47 @@ namespace std { #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_COMPILER_MSVC -inline _LIBCPP_INLINE_VISIBILITY -int __ctz(unsigned __x) { return __builtin_ctz(__x); } +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_ctz(unsigned __x) _NOEXCEPT { return __builtin_ctz(__x); } -inline _LIBCPP_INLINE_VISIBILITY -int __ctz(unsigned long __x) { return __builtin_ctzl(__x); } +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_ctz(unsigned long __x) _NOEXCEPT { return __builtin_ctzl(__x); } -inline _LIBCPP_INLINE_VISIBILITY -int __ctz(unsigned long long __x) { return __builtin_ctzll(__x); } +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_ctz(unsigned long long __x) _NOEXCEPT { return __builtin_ctzll(__x); } -inline _LIBCPP_INLINE_VISIBILITY -int __clz(unsigned __x) { return __builtin_clz(__x); } +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_clz(unsigned __x) _NOEXCEPT { return __builtin_clz(__x); } -inline _LIBCPP_INLINE_VISIBILITY -int __clz(unsigned long __x) { return __builtin_clzl(__x); } +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_clz(unsigned long __x) _NOEXCEPT { return __builtin_clzl(__x); } -inline _LIBCPP_INLINE_VISIBILITY -int __clz(unsigned long long __x) { return __builtin_clzll(__x); } +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_clz(unsigned long long __x) _NOEXCEPT { return __builtin_clzll(__x); } -inline _LIBCPP_INLINE_VISIBILITY -int __popcount(unsigned __x) { return __builtin_popcount(__x); } +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_popcount(unsigned __x) _NOEXCEPT { return __builtin_popcount(__x); } -inline _LIBCPP_INLINE_VISIBILITY -int __popcount(unsigned long __x) { return __builtin_popcountl(__x); } +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_popcount(unsigned long __x) _NOEXCEPT { return __builtin_popcountl(__x); } -inline _LIBCPP_INLINE_VISIBILITY -int __popcount(unsigned long long __x) { return __builtin_popcountll(__x); } +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +int __libcpp_popcount(unsigned long long __x) _NOEXCEPT { return __builtin_popcountll(__x); } #else // _LIBCPP_COMPILER_MSVC // Precondition: __x != 0 inline _LIBCPP_INLINE_VISIBILITY -int __ctz(unsigned __x) { +int __libcpp_ctz(unsigned __x) { static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); static_assert(sizeof(unsigned long) == 4, ""); unsigned long __where; @@ -81,13 +113,13 @@ int __ctz(unsigned __x) { } inline _LIBCPP_INLINE_VISIBILITY -int __ctz(unsigned long __x) { +int __libcpp_ctz(unsigned long __x) { static_assert(sizeof(unsigned long) == sizeof(unsigned), ""); return __ctz(static_cast<unsigned>(__x)); } inline _LIBCPP_INLINE_VISIBILITY -int __ctz(unsigned long long __x) { +int __libcpp_ctz(unsigned long long __x) { unsigned long __where; #if defined(_LIBCPP_HAS_BITSCAN64) (defined(_M_AMD64) || defined(__x86_64__)) @@ -105,7 +137,7 @@ int __ctz(unsigned long long __x) { // Precondition: __x != 0 inline _LIBCPP_INLINE_VISIBILITY -int __clz(unsigned __x) { +int __libcpp_clz(unsigned __x) { static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); static_assert(sizeof(unsigned long) == 4, ""); unsigned long __where; @@ -115,13 +147,13 @@ int __clz(unsigned __x) { } inline _LIBCPP_INLINE_VISIBILITY -int __clz(unsigned long __x) { +int __libcpp_clz(unsigned long __x) { static_assert(sizeof(unsigned) == sizeof(unsigned long), ""); - return __clz(static_cast<unsigned>(__x)); + return __libcpp_clz(static_cast<unsigned>(__x)); } inline _LIBCPP_INLINE_VISIBILITY -int __clz(unsigned long long __x) { +int __libcpp_clz(unsigned long long __x) { unsigned long __where; #if defined(_LIBCPP_HAS_BITSCAN64) if (_BitScanReverse64(&__where, __x)) @@ -136,23 +168,298 @@ int __clz(unsigned long long __x) { return 64; // Undefined Behavior. } -inline _LIBCPP_INLINE_VISIBILITY int __popcount(unsigned __x) { +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned __x) { static_assert(sizeof(unsigned) == 4, ""); return __popcnt(__x); } -inline _LIBCPP_INLINE_VISIBILITY int __popcount(unsigned long __x) { +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long __x) { static_assert(sizeof(unsigned long) == 4, ""); return __popcnt(__x); } -inline _LIBCPP_INLINE_VISIBILITY int __popcount(unsigned long long __x) { +inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long long __x) { static_assert(sizeof(unsigned long long) == 8, ""); return __popcnt64(__x); } #endif // _LIBCPP_COMPILER_MSVC +template <class _Tp> +using __bitop_unsigned_integer _LIBCPP_NODEBUG_TYPE = integral_constant<bool, + is_integral<_Tp>::value && + is_unsigned<_Tp>::value && + _IsNotSame<typename remove_cv<_Tp>::type, bool>::value && + _IsNotSame<typename remove_cv<_Tp>::type, signed char>::value && + _IsNotSame<typename remove_cv<_Tp>::type, wchar_t>::value && + _IsNotSame<typename remove_cv<_Tp>::type, char16_t>::value && + _IsNotSame<typename remove_cv<_Tp>::type, char32_t>::value + >; + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp __rotl(_Tp __t, unsigned int __cnt) _NOEXCEPT +{ + static_assert(__bitop_unsigned_integer<_Tp>::value, "__rotl requires unsigned"); + const unsigned int __dig = numeric_limits<_Tp>::digits; + if ((__cnt % __dig) == 0) + return __t; + return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig))); +} + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_Tp __rotr(_Tp __t, unsigned int __cnt) _NOEXCEPT +{ + static_assert(__bitop_unsigned_integer<_Tp>::value, "__rotr requires unsigned"); + const unsigned int __dig = numeric_limits<_Tp>::digits; + if ((__cnt % __dig) == 0) + return __t; + return (__t >> (__cnt % __dig)) | (__t << (__dig - (__cnt % __dig))); +} + + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +int __countr_zero(_Tp __t) _NOEXCEPT +{ + static_assert(__bitop_unsigned_integer<_Tp>::value, "__countr_zero requires unsigned"); + if (__t == 0) + return numeric_limits<_Tp>::digits; + + if (sizeof(_Tp) <= sizeof(unsigned int)) + return __libcpp_ctz(static_cast<unsigned int>(__t)); + else if (sizeof(_Tp) <= sizeof(unsigned long)) + return __libcpp_ctz(static_cast<unsigned long>(__t)); + else if (sizeof(_Tp) <= sizeof(unsigned long long)) + return __libcpp_ctz(static_cast<unsigned long long>(__t)); + else + { + int __ret = 0; + int __iter = 0; + const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits; + while ((__iter = __libcpp_ctz(static_cast<unsigned long long>(__t))) == __ulldigits) + { + __ret += __iter; + __t >>= __ulldigits; + } + return __ret + __iter; + } +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +int __countl_zero(_Tp __t) _NOEXCEPT +{ + static_assert(__bitop_unsigned_integer<_Tp>::value, "__countl_zero requires unsigned"); + if (__t == 0) + return numeric_limits<_Tp>::digits; + + if (sizeof(_Tp) <= sizeof(unsigned int)) + return __libcpp_clz(static_cast<unsigned int>(__t)) + - (numeric_limits<unsigned int>::digits - numeric_limits<_Tp>::digits); + else if (sizeof(_Tp) <= sizeof(unsigned long)) + return __libcpp_clz(static_cast<unsigned long>(__t)) + - (numeric_limits<unsigned long>::digits - numeric_limits<_Tp>::digits); + else if (sizeof(_Tp) <= sizeof(unsigned long long)) + return __libcpp_clz(static_cast<unsigned long long>(__t)) + - (numeric_limits<unsigned long long>::digits - numeric_limits<_Tp>::digits); + else + { + int __ret = 0; + int __iter = 0; + const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits; + while (true) { + __t = __rotr(__t, __ulldigits); + if ((__iter = __countl_zero(static_cast<unsigned long long>(__t))) != __ulldigits) + break; + __ret += __iter; + } + return __ret + __iter; + } +} + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +int __countl_one(_Tp __t) _NOEXCEPT +{ + static_assert(__bitop_unsigned_integer<_Tp>::value, "__countl_one requires unsigned"); + return __t != numeric_limits<_Tp>::max() + ? __countl_zero(static_cast<_Tp>(~__t)) + : numeric_limits<_Tp>::digits; +} + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +int __countr_one(_Tp __t) _NOEXCEPT +{ + static_assert(__bitop_unsigned_integer<_Tp>::value, "__countr_one requires unsigned"); + return __t != numeric_limits<_Tp>::max() + ? __countr_zero(static_cast<_Tp>(~__t)) + : numeric_limits<_Tp>::digits; +} + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +int +__popcount(_Tp __t) _NOEXCEPT +{ + static_assert(__bitop_unsigned_integer<_Tp>::value, "__libcpp_popcount requires unsigned"); + if (sizeof(_Tp) <= sizeof(unsigned int)) + return __libcpp_popcount(static_cast<unsigned int>(__t)); + else if (sizeof(_Tp) <= sizeof(unsigned long)) + return __libcpp_popcount(static_cast<unsigned long>(__t)); + else if (sizeof(_Tp) <= sizeof(unsigned long long)) + return __libcpp_popcount(static_cast<unsigned long long>(__t)); + else + { + int __ret = 0; + while (__t != 0) + { + __ret += __libcpp_popcount(static_cast<unsigned long long>(__t)); + __t >>= numeric_limits<unsigned long long>::digits; + } + return __ret; + } +} + + +// integral log base 2 +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +unsigned __bit_log2(_Tp __t) _NOEXCEPT +{ + static_assert(__bitop_unsigned_integer<_Tp>::value, "__bit_log2 requires unsigned"); + return std::numeric_limits<_Tp>::digits - 1 - __countl_zero(__t); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +bool __ispow2(_Tp __t) _NOEXCEPT +{ + static_assert(__bitop_unsigned_integer<_Tp>::value, "__ispow2 requires unsigned"); + return __t != 0 && (((__t & (__t - 1)) == 0)); +} + + +#if _LIBCPP_STD_VER > 17 + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp> +rotl(_Tp __t, unsigned int __cnt) noexcept +{ + return __rotl(__t, __cnt); +} + + +// rotr +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp> +rotr(_Tp __t, unsigned int __cnt) noexcept +{ + return __rotr(__t, __cnt); +} + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, int> +countl_zero(_Tp __t) noexcept +{ + return __countl_zero(__t); +} + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, int> +countl_one(_Tp __t) noexcept +{ + return __countl_one(__t); +} + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, int> +countr_zero(_Tp __t) noexcept +{ + return __countr_zero(__t); +} + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, int> +countr_one(_Tp __t) noexcept +{ + return __countr_one(__t); +} + + +template<class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, int> +popcount(_Tp __t) noexcept +{ + return __popcount(__t); +} + + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, bool> +ispow2(_Tp __t) noexcept +{ + return __ispow2(__t); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp> +floor2(_Tp __t) noexcept +{ + return __t == 0 ? 0 : _Tp{1} << __bit_log2(__t); +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp> +ceil2(_Tp __t) noexcept +{ + if (__t < 2) return 1; + const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u)); + _LIBCPP_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to ceil2"); + + if constexpr (sizeof(_Tp) >= sizeof(unsigned)) + return _Tp{1} << __n; + else + { + const unsigned __extra = numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits; + const unsigned __retVal = 1u << (__n + __extra); + return (_Tp) (__retVal >> __extra); + } +} + +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp> +log2p1(_Tp __t) noexcept +{ + return __t == 0 ? 0 : __bit_log2(__t) + 1; +} + +#endif // _LIBCPP_STD_VER > 17 + _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_BIT diff --git a/include/bitset b/include/bitset index 98947e027c1c..4755fbeb2152 100644 --- a/include/bitset +++ b/include/bitset @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- bitset ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -680,7 +679,7 @@ public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset(unsigned long long __v) _NOEXCEPT : base(__v) {} - template<class _CharT> + template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> > explicit bitset(const _CharT* __str, typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos, _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); @@ -761,7 +760,7 @@ private: }; template <size_t _Size> -template<class _CharT> +template<class _CharT, class> bitset<_Size>::bitset(const _CharT* __str, typename basic_string<_CharT>::size_type __n, _CharT __zero, _CharT __one) diff --git a/include/cassert b/include/cassert index 3775990640a9..25a0a746b8d1 100644 --- a/include/cassert +++ b/include/cassert @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- cassert -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/ccomplex b/include/ccomplex index 6ed116445e64..0d2e0f5a0f2c 100644 --- a/include/ccomplex +++ b/include/ccomplex @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- ccomplex ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cctype b/include/cctype index 7fc81344696d..55fc9ebc66ce 100644 --- a/include/cctype +++ b/include/cctype @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- cctype ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cerrno b/include/cerrno index bab13b8aa861..a9268a281f4e 100644 --- a/include/cerrno +++ b/include/cerrno @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- cerrno ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cfenv b/include/cfenv index 4fc630419bde..6cd91db5a463 100644 --- a/include/cfenv +++ b/include/cfenv @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- cfenv -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cfloat b/include/cfloat index 0abe84bf175d..da22c6f60a2a 100644 --- a/include/cfloat +++ b/include/cfloat @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cfloat -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/charconv b/include/charconv index 064f2e11c3f3..a644fe094846 100644 --- a/include/charconv +++ b/include/charconv @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------------ charconv ------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -97,7 +96,7 @@ _LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer); _LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer); } -#if _LIBCPP_STD_VER > 11 +#ifndef _LIBCPP_CXX03_LANG enum class _LIBCPP_ENUM_VIS chars_format { @@ -125,7 +124,7 @@ void from_chars(const char*, const char*, bool, int = 10) = delete; namespace __itoa { -static constexpr uint64_t __pow10_64[] = { +static _LIBCPP_CONSTEXPR uint64_t __pow10_64[] = { UINT64_C(0), UINT64_C(10), UINT64_C(100), @@ -148,7 +147,7 @@ static constexpr uint64_t __pow10_64[] = { UINT64_C(10000000000000000000), }; -static constexpr uint32_t __pow10_32[] = { +static _LIBCPP_CONSTEXPR uint32_t __pow10_32[] = { UINT32_C(0), UINT32_C(10), UINT32_C(100), UINT32_C(1000), UINT32_C(10000), UINT32_C(100000), UINT32_C(1000000), UINT32_C(10000000), UINT32_C(100000000), @@ -173,7 +172,7 @@ struct _LIBCPP_HIDDEN __traits_base return __u64toa(__v, __p); } - static _LIBCPP_INLINE_VISIBILITY auto& __pow() { return __pow10_64; } + static _LIBCPP_INLINE_VISIBILITY decltype(__pow10_64)& __pow() { return __pow10_64; } }; template <typename _Tp> @@ -195,7 +194,7 @@ struct _LIBCPP_HIDDEN return __u32toa(__v, __p); } - static _LIBCPP_INLINE_VISIBILITY auto& __pow() { return __pow10_32; } + static _LIBCPP_INLINE_VISIBILITY decltype(__pow10_32)& __pow() { return __pow10_32; } }; template <typename _Tp> @@ -240,7 +239,7 @@ __mul_overflowed(_Tp __a, _Up __b, _Tp& __r) template <typename _Tp> struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp> { - static constexpr int digits = numeric_limits<_Tp>::digits10 + 1; + static _LIBCPP_CONSTEXPR int digits = numeric_limits<_Tp>::digits10 + 1; using __traits_base<_Tp>::__pow; using typename __traits_base<_Tp>::type; @@ -286,10 +285,10 @@ __complement(_Tp __x) } template <typename _Tp> -inline _LIBCPP_INLINE_VISIBILITY auto +inline _LIBCPP_INLINE_VISIBILITY typename make_unsigned<_Tp>::type __to_unsigned(_Tp __x) { - return static_cast<make_unsigned_t<_Tp>>(__x); + return static_cast<typename make_unsigned<_Tp>::type>(__x); } template <typename _Tp> @@ -315,7 +314,7 @@ __to_chars_itoa(char* __first, char* __last, _Tp __value, false_type) #if !defined(_LIBCPP_COMPILER_MSVC) if (__tx::digits <= __diff || __tx::__width(__value) <= __diff) - return {__tx::__convert(__value, __first), {}}; + return {__tx::__convert(__value, __first), errc(0)}; else return {__last, errc::value_too_large}; #else @@ -380,14 +379,14 @@ __to_chars_integral(char* __first, char* __last, _Tp __value, int __base, } } -template <typename _Tp, enable_if_t<is_integral<_Tp>::value, int> = 0> +template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0> inline _LIBCPP_INLINE_VISIBILITY to_chars_result to_chars(char* __first, char* __last, _Tp __value) { return __to_chars_itoa(__first, __last, __value, is_signed<_Tp>()); } -template <typename _Tp, enable_if_t<is_integral<_Tp>::value, int> = 0> +template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0> inline _LIBCPP_INLINE_VISIBILITY to_chars_result to_chars(char* __first, char* __last, _Tp __value, int __base) { @@ -502,7 +501,7 @@ __subject_seq_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, return __r; } -template <typename _Tp, enable_if_t<is_unsigned<_Tp>::value, int> = 0> +template <typename _Tp, typename enable_if<is_unsigned<_Tp>::value, int>::type = 0> inline _LIBCPP_INLINE_VISIBILITY from_chars_result __from_chars_atoi(const char* __first, const char* __last, _Tp& __value) { @@ -528,7 +527,7 @@ __from_chars_atoi(const char* __first, const char* __last, _Tp& __value) }); } -template <typename _Tp, enable_if_t<is_signed<_Tp>::value, int> = 0> +template <typename _Tp, typename enable_if<is_signed<_Tp>::value, int>::type = 0> inline _LIBCPP_INLINE_VISIBILITY from_chars_result __from_chars_atoi(const char* __first, const char* __last, _Tp& __value) { @@ -536,7 +535,7 @@ __from_chars_atoi(const char* __first, const char* __last, _Tp& __value) return __sign_combinator(__first, __last, __value, __from_chars_atoi<__t>); } -template <typename _Tp, enable_if_t<is_unsigned<_Tp>::value, int> = 0> +template <typename _Tp, typename enable_if<is_unsigned<_Tp>::value, int>::type = 0> inline _LIBCPP_INLINE_VISIBILITY from_chars_result __from_chars_integral(const char* __first, const char* __last, _Tp& __value, int __base) @@ -583,7 +582,7 @@ __from_chars_integral(const char* __first, const char* __last, _Tp& __value, __base); } -template <typename _Tp, enable_if_t<is_signed<_Tp>::value, int> = 0> +template <typename _Tp, typename enable_if<is_signed<_Tp>::value, int>::type = 0> inline _LIBCPP_INLINE_VISIBILITY from_chars_result __from_chars_integral(const char* __first, const char* __last, _Tp& __value, int __base) @@ -593,14 +592,14 @@ __from_chars_integral(const char* __first, const char* __last, _Tp& __value, __from_chars_integral<__t>, __base); } -template <typename _Tp, enable_if_t<is_integral<_Tp>::value, int> = 0> +template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0> inline _LIBCPP_INLINE_VISIBILITY from_chars_result from_chars(const char* __first, const char* __last, _Tp& __value) { return __from_chars_atoi(__first, __last, __value); } -template <typename _Tp, enable_if_t<is_integral<_Tp>::value, int> = 0> +template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0> inline _LIBCPP_INLINE_VISIBILITY from_chars_result from_chars(const char* __first, const char* __last, _Tp& __value, int __base) { @@ -608,7 +607,7 @@ from_chars(const char* __first, const char* __last, _Tp& __value, int __base) return __from_chars_integral(__first, __last, __value, __base); } -#endif // _LIBCPP_STD_VER > 11 +#endif // _LIBCPP_CXX03_LANG _LIBCPP_END_NAMESPACE_STD diff --git a/include/chrono b/include/chrono index 96759f9860ee..1b907571aa14 100644 --- a/include/chrono +++ b/include/chrono @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- chrono ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -1263,34 +1262,15 @@ operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) // Duration / -template <class _Duration, class _Rep, bool = __is_duration<_Rep>::value> -struct __duration_divide_result -{ -}; - -template <class _Duration, class _Rep2, - bool = is_convertible<_Rep2, - typename common_type<typename _Duration::rep, _Rep2>::type>::value> -struct __duration_divide_imp -{ -}; - -template <class _Rep1, class _Period, class _Rep2> -struct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true> -{ - typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type; -}; - -template <class _Rep1, class _Period, class _Rep2> -struct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false> - : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2> -{ -}; - template <class _Rep1, class _Period, class _Rep2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type +typename enable_if +< + !__is_duration<_Rep2>::value && + is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> +>::type operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { typedef typename common_type<_Rep1, _Rep2>::type _Cr; @@ -1313,7 +1293,12 @@ operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2 template <class _Rep1, class _Period, class _Rep2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR -typename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type +typename enable_if +< + !__is_duration<_Rep2>::value && + is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, + duration<typename common_type<_Rep1, _Rep2>::type, _Period> +>::type operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) { typedef typename common_type<_Rep1, _Rep2>::type _Cr; @@ -1605,9 +1590,9 @@ using local_seconds = local_time<seconds>; using local_days = local_time<days>; -struct _LIBCPP_TYPE_VIS last_spec { explicit last_spec() = default; }; +struct last_spec { explicit last_spec() = default; }; -class _LIBCPP_TYPE_VIS day { +class day { private: unsigned char __d; public: @@ -1672,7 +1657,7 @@ inline constexpr day& day::operator-=(const days& __dd) noexcept { *this = *this - __dd; return *this; } -class _LIBCPP_TYPE_VIS month { +class month { private: unsigned char __m; public: @@ -1743,21 +1728,21 @@ inline constexpr month& month::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } -class _LIBCPP_TYPE_VIS year { +class year { private: short __y; public: year() = default; explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {} - inline constexpr year& operator++() noexcept { ++__y; return *this; }; - inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }; - inline constexpr year& operator--() noexcept { --__y; return *this; }; - inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }; + inline constexpr year& operator++() noexcept { ++__y; return *this; } + inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; } + inline constexpr year& operator--() noexcept { --__y; return *this; } + inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; } constexpr year& operator+=(const years& __dy) noexcept; constexpr year& operator-=(const years& __dy) noexcept; inline constexpr year operator+() const noexcept { return *this; } - inline constexpr year operator-() const noexcept { return year{-__y}; }; + inline constexpr year operator-() const noexcept { return year{-__y}; } inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); } explicit inline constexpr operator int() const noexcept { return __y; } @@ -1817,10 +1802,10 @@ inline constexpr year& year::operator-=(const years& __dy) noexcept inline constexpr bool year::ok() const noexcept { return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); } -class _LIBCPP_TYPE_VIS weekday_indexed; -class _LIBCPP_TYPE_VIS weekday_last; +class weekday_indexed; +class weekday_last; -class _LIBCPP_TYPE_VIS weekday { +class weekday { private: unsigned char __wd; public: @@ -1906,7 +1891,7 @@ inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept { *this = *this - __dd; return *this; } -class _LIBCPP_TYPE_VIS weekday_indexed { +class weekday_indexed { private: _VSTD::chrono::weekday __wd; unsigned char __idx; @@ -1928,7 +1913,7 @@ bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noex { return !(__lhs == __rhs); } -class _LIBCPP_TYPE_VIS weekday_last { +class weekday_last { private: _VSTD::chrono::weekday __wd; public: @@ -1949,7 +1934,7 @@ bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept inline constexpr weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; } -inline constexpr +inline constexpr weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; } @@ -1976,7 +1961,7 @@ inline constexpr month November{11}; inline constexpr month December{12}; -class _LIBCPP_TYPE_VIS month_day { +class month_day { private: chrono::month __m; chrono::day __d; @@ -2051,7 +2036,7 @@ bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept -class _LIBCPP_TYPE_VIS month_day_last { +class month_day_last { private: chrono::month __m; public: @@ -2102,7 +2087,7 @@ month_day_last operator/(last_spec, int __rhs) noexcept { return month_day_last{month(__rhs)}; } -class _LIBCPP_TYPE_VIS month_weekday { +class month_weekday { private: chrono::month __m; chrono::weekday_indexed __wdi; @@ -2140,7 +2125,7 @@ month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept { return month_weekday{month(__rhs), __lhs}; } -class _LIBCPP_TYPE_VIS month_weekday_last { +class month_weekday_last { chrono::month __m; chrono::weekday_last __wdl; public: @@ -2177,7 +2162,7 @@ month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept { return month_weekday_last{month(__rhs), __lhs}; } -class _LIBCPP_TYPE_VIS year_month { +class year_month { chrono::year __y; chrono::month __m; public: @@ -2251,7 +2236,7 @@ constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noex class year_month_day_last; -class _LIBCPP_TYPE_VIS year_month_day { +class year_month_day { private: chrono::year __y; chrono::month __m; @@ -2260,7 +2245,7 @@ public: year_month_day() = default; inline constexpr year_month_day( const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept - : __y{__yval}, __m{__mval}, __d{__dval} {} + : __y{__yval}, __m{__mval}, __d{__dval} {} constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; inline constexpr year_month_day(const sys_days& __sysd) noexcept : year_month_day(__from_days(__sysd.time_since_epoch())) {} @@ -2405,7 +2390,7 @@ inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } -class _LIBCPP_TYPE_VIS year_month_day_last { +class year_month_day_last { private: chrono::year __y; chrono::month_day_last __mdl; @@ -2515,7 +2500,7 @@ inline constexpr year_month_day_last& year_month_day_last::operator+=(const year inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept - : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {} + : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {} inline constexpr bool year_month_day::ok() const noexcept { @@ -2523,7 +2508,7 @@ inline constexpr bool year_month_day::ok() const noexcept return chrono::day{1} <= __d && __d <= (__y / __m / last).day(); } -class _LIBCPP_TYPE_VIS year_month_weekday { +class year_month_weekday { chrono::year __y; chrono::month __m; chrono::weekday_indexed __wdi; @@ -2566,7 +2551,7 @@ year_month_weekday year_month_weekday::__from_days(days __d) noexcept const sys_days __sysd{__d}; const chrono::weekday __wd = chrono::weekday(__sysd); const year_month_day __ymd = year_month_day(__sysd); - return year_month_weekday{__ymd.year(), __ymd.month(), + return year_month_weekday{__ymd.year(), __ymd.month(), __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]}; } @@ -2637,7 +2622,7 @@ inline constexpr year_month_weekday& year_month_weekday::operator-=(const months inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } -class _LIBCPP_TYPE_VIS year_month_weekday_last { +class year_month_weekday_last { private: chrono::year __y; chrono::month __m; @@ -2658,9 +2643,9 @@ public: inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); } - + constexpr days __to_days() const noexcept; - + }; inline constexpr @@ -2698,7 +2683,7 @@ year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& _ inline constexpr year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept -{ return year(__rhs) / __lhs; } +{ return year(__rhs) / __lhs; } inline constexpr @@ -2810,7 +2795,7 @@ inline namespace literals { return chrono::day(static_cast<unsigned>(__d)); } - + constexpr chrono::year operator ""y(unsigned long long __y) noexcept { return chrono::year(static_cast<int>(__y)); @@ -2842,7 +2827,7 @@ struct _FilesystemClock { static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; - _LIBCPP_FUNC_VIS static time_point now() noexcept; + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept; _LIBCPP_INLINE_VISIBILITY static time_t to_time_t(const time_point& __t) noexcept { diff --git a/include/cinttypes b/include/cinttypes index 3f61b0634b17..55af85cc395d 100644 --- a/include/cinttypes +++ b/include/cinttypes @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cinttypes --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/ciso646 b/include/ciso646 index b2efc72a9aa1..172f1676ad9b 100644 --- a/include/ciso646 +++ b/include/ciso646 @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- ciso646 ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/climits b/include/climits index 81ffecdf6eef..43eb2d3f1520 100644 --- a/include/climits +++ b/include/climits @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- climits ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/clocale b/include/clocale index 05fa9c6edda8..bff4e92f99ff 100644 --- a/include/clocale +++ b/include/clocale @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- clocale ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cmath b/include/cmath index f5f62adcfb8d..f5864be5e11a 100644 --- a/include/cmath +++ b/include/cmath @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- cmath -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -530,7 +529,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y template <class _A1, class _A2, class _A3> inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if +typename _EnableIf < is_arithmetic<_A1>::value && is_arithmetic<_A2>::value && @@ -607,6 +606,32 @@ __libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT return isfinite(__lcpp_x); } +#if _LIBCPP_STD_VER > 17 +template <typename _Fp> +constexpr +_Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept { + if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0)) + return __t * __b + (1 - __t) * __a; + + if (__t == 1) return __b; + const _Fp __x = __a + __t * (__b - __a); + if (__t > 1 == __b > __a) + return __b < __x ? __x : __b; + else + return __x < __b ? __x : __b; +} + +constexpr float +lerp(float __a, float __b, float __t) _NOEXCEPT { return __lerp(__a, __b, __t); } + +constexpr double +lerp(double __a, double __b, double __t) _NOEXCEPT { return __lerp(__a, __b, __t); } + +constexpr long double +lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); } + +#endif // _LIBCPP_STD_VER > 17 + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_CMATH diff --git a/include/codecvt b/include/codecvt index 5eb9d1549118..5ea411ea781b 100644 --- a/include/codecvt +++ b/include/codecvt @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- codecvt -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/compare b/include/compare index 07f88f09cb37..e05257bebfa5 100644 --- a/include/compare +++ b/include/compare @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- compare -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/complex b/include/complex index 8cf6a946d711..c168406befbd 100644 --- a/include/complex +++ b/include/complex @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- complex ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -1450,10 +1449,10 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) return __os << __s.str(); } -#if _LIBCPP_STD_VER > 11 +#if _LIBCPP_STD_VER > 11 // Literal suffix for complex number literals [complex.literals] inline namespace literals -{ +{ inline namespace complex_literals { constexpr complex<long double> operator""il(long double __im) diff --git a/include/complex.h b/include/complex.h index c2359665add5..b78733b8093a 100644 --- a/include/complex.h +++ b/include/complex.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- complex.h --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/condition_variable b/include/condition_variable index c45a326d8985..8c733448e3c5 100644 --- a/include/condition_variable +++ b/include/condition_variable @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------- condition_variable ----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/csetjmp b/include/csetjmp index 58a9c73ab56f..ed94b50d1618 100644 --- a/include/csetjmp +++ b/include/csetjmp @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- csetjmp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/csignal b/include/csignal index 97282661872a..99abd02de066 100644 --- a/include/csignal +++ b/include/csignal @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- csignal ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cstdarg b/include/cstdarg index c8b6999242f7..e8147d496a77 100644 --- a/include/cstdarg +++ b/include/cstdarg @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cstdarg ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cstdbool b/include/cstdbool index 2c764a61f211..fad47141476c 100644 --- a/include/cstdbool +++ b/include/cstdbool @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cstdbool ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cstddef b/include/cstddef index b4c42b19ddb2..bd62d6db39e8 100644 --- a/include/cstddef +++ b/include/cstddef @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cstddef ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cstdint b/include/cstdint index 7a187d3ebf28..f72fa067373e 100644 --- a/include/cstdint +++ b/include/cstdint @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cstdint ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cstdio b/include/cstdio index 00b989fad7c8..675569382344 100644 --- a/include/cstdio +++ b/include/cstdio @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- cstdio ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cstdlib b/include/cstdlib index 00c604e67623..68b3ded3fd51 100644 --- a/include/cstdlib +++ b/include/cstdlib @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cstdlib ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cstring b/include/cstring index d550695caa42..8bc96a023302 100644 --- a/include/cstring +++ b/include/cstring @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cstring ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/ctgmath b/include/ctgmath index 535eb7dccd15..ba1eeeac9f70 100644 --- a/include/ctgmath +++ b/include/ctgmath @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- ctgmath -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/ctime b/include/ctime index 8264fe33b964..cb8474f8f0b5 100644 --- a/include/ctime +++ b/include/ctime @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- ctime -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/ctype.h b/include/ctype.h index e97ff3c48876..dcc7935a29a0 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- ctype.h ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cwchar b/include/cwchar index d268e8bbd393..451c621f9c06 100644 --- a/include/cwchar +++ b/include/cwchar @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cwchar -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/cwctype b/include/cwctype index 25b2489edf2c..575fd5661293 100644 --- a/include/cwctype +++ b/include/cwctype @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- cwctype ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/deque b/include/deque index 6f7d04be52be..d3ccf2ef6f71 100644 --- a/include/deque +++ b/include/deque @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- deque -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -1331,21 +1330,21 @@ public: // element access: _LIBCPP_INLINE_VISIBILITY - reference operator[](size_type __i); + reference operator[](size_type __i) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - const_reference operator[](size_type __i) const; + const_reference operator[](size_type __i) const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reference at(size_type __i); _LIBCPP_INLINE_VISIBILITY const_reference at(size_type __i) const; _LIBCPP_INLINE_VISIBILITY - reference front(); + reference front() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - const_reference front() const; + const_reference front() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - reference back(); + reference back() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - const_reference back() const; + const_reference back() const _NOEXCEPT; // 23.2.2.3 modifiers: void push_front(const value_type& __v); @@ -1746,7 +1745,7 @@ deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT template <class _Tp, class _Allocator> inline typename deque<_Tp, _Allocator>::reference -deque<_Tp, _Allocator>::operator[](size_type __i) +deque<_Tp, _Allocator>::operator[](size_type __i) _NOEXCEPT { size_type __p = __base::__start_ + __i; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); @@ -1755,7 +1754,7 @@ deque<_Tp, _Allocator>::operator[](size_type __i) template <class _Tp, class _Allocator> inline typename deque<_Tp, _Allocator>::const_reference -deque<_Tp, _Allocator>::operator[](size_type __i) const +deque<_Tp, _Allocator>::operator[](size_type __i) const _NOEXCEPT { size_type __p = __base::__start_ + __i; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); @@ -1786,7 +1785,7 @@ deque<_Tp, _Allocator>::at(size_type __i) const template <class _Tp, class _Allocator> inline typename deque<_Tp, _Allocator>::reference -deque<_Tp, _Allocator>::front() +deque<_Tp, _Allocator>::front() _NOEXCEPT { return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) + __base::__start_ % __base::__block_size); @@ -1795,7 +1794,7 @@ deque<_Tp, _Allocator>::front() template <class _Tp, class _Allocator> inline typename deque<_Tp, _Allocator>::const_reference -deque<_Tp, _Allocator>::front() const +deque<_Tp, _Allocator>::front() const _NOEXCEPT { return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) + __base::__start_ % __base::__block_size); @@ -1804,7 +1803,7 @@ deque<_Tp, _Allocator>::front() const template <class _Tp, class _Allocator> inline typename deque<_Tp, _Allocator>::reference -deque<_Tp, _Allocator>::back() +deque<_Tp, _Allocator>::back() _NOEXCEPT { size_type __p = __base::size() + __base::__start_ - 1; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); @@ -1813,7 +1812,7 @@ deque<_Tp, _Allocator>::back() template <class _Tp, class _Allocator> inline typename deque<_Tp, _Allocator>::const_reference -deque<_Tp, _Allocator>::back() const +deque<_Tp, _Allocator>::back() const _NOEXCEPT { size_type __p = __base::size() + __base::__start_ - 1; return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); diff --git a/include/errno.h b/include/errno.h index ee6429110cc1..447319effd35 100644 --- a/include/errno.h +++ b/include/errno.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- errno.h -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/exception b/include/exception index fdd83d10c3da..c7dcac2b2b33 100644 --- a/include/exception +++ b/include/exception @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- exception ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -83,7 +82,7 @@ template <class E> void rethrow_if_nested(const E& e); #include <type_traits> #include <version> -#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +#if defined(_LIBCPP_ABI_VCRUNTIME) #include <vcruntime_exception.h> #endif @@ -94,7 +93,7 @@ template <class E> void rethrow_if_nested(const E& e); namespace std // purposefully not using versioning namespace { -#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) +#if !defined(_LIBCPP_ABI_VCRUNTIME) class _LIBCPP_EXCEPTION_ABI exception { public: @@ -111,7 +110,7 @@ public: virtual ~bad_exception() _NOEXCEPT; virtual const char* what() const _NOEXCEPT; }; -#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME +#endif // !_LIBCPP_ABI_VCRUNTIME #if _LIBCPP_STD_VER <= 14 \ || defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \ @@ -261,11 +260,7 @@ struct __throw_with_nested; template <class _Tp, class _Up> struct __throw_with_nested<_Tp, _Up, true> { _LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void -#ifndef _LIBCPP_CXX03_LANG __do_throw(_Tp&& __t) -#else - __do_throw (_Tp& __t) -#endif // _LIBCPP_CXX03_LANG { throw __nested<_Up>(_VSTD::forward<_Tp>(__t)); } @@ -288,11 +283,7 @@ struct __throw_with_nested<_Tp, _Up, false> { template <class _Tp> _LIBCPP_NORETURN void -#ifndef _LIBCPP_CXX03_LANG throw_with_nested(_Tp&& __t) -#else -throw_with_nested (_Tp& __t) -#endif // _LIBCPP_CXX03_LANG { #ifndef _LIBCPP_NO_EXCEPTIONS typedef typename decay<_Tp>::type _Up; diff --git a/include/experimental/__config b/include/experimental/__config index c6f177620224..375dc3743fcf 100644 --- a/include/experimental/__config +++ b/include/experimental/__config @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- __config ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -37,8 +36,14 @@ namespace chrono { namespace experimental { inline namespace fundamentals_v1 { #define _LIBCPP_END_NAMESPACE_CHRONO_LFTS _LIBCPP_END_NAMESPACE_STD } } } +#if defined(_LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM) +# define _LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM /* nothing */ +#else +# define _LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM __attribute__((deprecated("std::experimental::filesystem has now been deprecated in favor of C++17's std::filesystem. Please stop using it and start using std::filesystem. This experimental version will be removed in LLVM 11. You can remove this warning by defining the _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM macro."))) +#endif + #define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM \ - _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace filesystem { \ + _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace filesystem _LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM { \ inline namespace v1 { #define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM \ diff --git a/include/experimental/__memory b/include/experimental/__memory index 229fea605bfd..4cf8978468ce 100644 --- a/include/experimental/__memory +++ b/include/experimental/__memory @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/algorithm b/include/experimental/algorithm index eb3bad6ef98c..79fd7b1b22de 100644 --- a/include/experimental/algorithm +++ b/include/experimental/algorithm @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- algorithm ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/any b/include/experimental/any deleted file mode 100644 index d9c95342589f..000000000000 --- a/include/experimental/any +++ /dev/null @@ -1,21 +0,0 @@ -// -*- C++ -*- -//===------------------------------- any ----------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef _LIBCPP_EXPERIMENTAL_ANY -#define _LIBCPP_EXPERIMENTAL_ANY - -#include <__config> - -#ifdef _LIBCPP_WARNING -_LIBCPP_WARNING("<experimental/any> has been removed. Use <any> instead.") -#else -# warning "<experimental/any> has been removed. Use <any> instead." -#endif - -#endif // _LIBCPP_EXPERIMENTAL_ANY diff --git a/include/experimental/chrono b/include/experimental/chrono deleted file mode 100644 index 30c7e4a9d5ac..000000000000 --- a/include/experimental/chrono +++ /dev/null @@ -1,21 +0,0 @@ -// -*- C++ -*- -//===---------------------------- chrono ----------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef _LIBCPP_EXPERIMENTAL_CHRONO -#define _LIBCPP_EXPERIMENTAL_CHRONO - -#include <__config> - -#ifdef _LIBCPP_WARNING -_LIBCPP_WARNING("<experimental/chrono> has been removed. Use <chrono> instead.") -#else -# warning "<experimental/chrono> has been removed. Use <chrono> instead." -#endif - -#endif // _LIBCPP_EXPERIMENTAL_CHRONO diff --git a/include/experimental/coroutine b/include/experimental/coroutine index 7cb39b81b48f..e2f0a25f77ed 100644 --- a/include/experimental/coroutine +++ b/include/experimental/coroutine @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------- coroutine -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -82,7 +81,7 @@ struct __coroutine_traits_sfinae< }; template <typename _Ret, typename... _Args> -struct _LIBCPP_TEMPLATE_VIS coroutine_traits +struct coroutine_traits : public __coroutine_traits_sfinae<_Ret> { }; @@ -299,7 +298,7 @@ noop_coroutine_handle noop_coroutine() _NOEXCEPT { } #endif // __has_builtin(__builtin_coro_noop) -struct _LIBCPP_TYPE_VIS suspend_never { +struct suspend_never { _LIBCPP_INLINE_VISIBILITY bool await_ready() const _NOEXCEPT { return true; } _LIBCPP_INLINE_VISIBILITY @@ -308,7 +307,7 @@ struct _LIBCPP_TYPE_VIS suspend_never { void await_resume() const _NOEXCEPT {} }; -struct _LIBCPP_TYPE_VIS suspend_always { +struct suspend_always { _LIBCPP_INLINE_VISIBILITY bool await_ready() const _NOEXCEPT { return false; } _LIBCPP_INLINE_VISIBILITY diff --git a/include/experimental/deque b/include/experimental/deque index f8495743c1f9..73c2787c7a04 100644 --- a/include/experimental/deque +++ b/include/experimental/deque @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- deque ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/filesystem b/include/experimental/filesystem index 28d8dcf4fc13..d2e6237df348 100644 --- a/include/experimental/filesystem +++ b/include/experimental/filesystem @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- filesystem -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_EXPERIMENTAL_FILESYSTEM diff --git a/include/experimental/forward_list b/include/experimental/forward_list index 55e195f446f5..93f6debe9cb3 100644 --- a/include/experimental/forward_list +++ b/include/experimental/forward_list @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- forward_list -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/functional b/include/experimental/functional index f63dfb07bb06..755eda641556 100644 --- a/include/experimental/functional +++ b/include/experimental/functional @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- functional --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -110,8 +109,7 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS #if _LIBCPP_STD_VER > 11 // default searcher template<class _ForwardIterator, class _BinaryPredicate = equal_to<>> -_LIBCPP_TYPE_VIS -class default_searcher { +class _LIBCPP_TYPE_VIS default_searcher { public: _LIBCPP_INLINE_VISIBILITY default_searcher(_ForwardIterator __f, _ForwardIterator __l, @@ -209,8 +207,7 @@ public: template <class _RandomAccessIterator1, class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>, class _BinaryPredicate = equal_to<>> -_LIBCPP_TYPE_VIS -class boyer_moore_searcher { +class _LIBCPP_TYPE_VIS boyer_moore_searcher { private: typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type difference_type; typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type value_type; @@ -361,8 +358,7 @@ make_boyer_moore_searcher( _RandomAccessIterator __f, _RandomAccessIterator __l, template <class _RandomAccessIterator1, class _Hash = hash<typename iterator_traits<_RandomAccessIterator1>::value_type>, class _BinaryPredicate = equal_to<>> -_LIBCPP_TYPE_VIS -class boyer_moore_horspool_searcher { +class _LIBCPP_TYPE_VIS boyer_moore_horspool_searcher { private: typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type difference_type; typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type value_type; diff --git a/include/experimental/iterator b/include/experimental/iterator index ea672e966315..6a6e51d820d1 100644 --- a/include/experimental/iterator +++ b/include/experimental/iterator @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------- iterator -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/list b/include/experimental/list index 1678ee3e93cb..adc64a8b537a 100644 --- a/include/experimental/list +++ b/include/experimental/list @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- list ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/map b/include/experimental/map index cff2c5e52c0d..965d7582c9dd 100644 --- a/include/experimental/map +++ b/include/experimental/map @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------- map ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/memory_resource b/include/experimental/memory_resource index 83781d462034..f999fb9befda 100644 --- a/include/experimental/memory_resource +++ b/include/experimental/memory_resource @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------ memory_resource -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/numeric b/include/experimental/numeric deleted file mode 100644 index 19c65313f0f2..000000000000 --- a/include/experimental/numeric +++ /dev/null @@ -1,21 +0,0 @@ -// -*- C++ -*- -//===--------------------------- numeric ----------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef _LIBCPP_EXPERIMENTAL_NUMERIC -#define _LIBCPP_EXPERIMENTAL_NUMERIC - -#include <__config> - -#ifdef _LIBCPP_WARNING -_LIBCPP_WARNING("<experimental/numeric> has been removed. Use <numeric> instead.") -#else -# warning "<experimental/numeric> has been removed. Use <numeric> instead." -#endif - -#endif // _LIBCPP_EXPERIMENTAL_NUMERIC diff --git a/include/experimental/optional b/include/experimental/optional deleted file mode 100644 index 6eb4a2618d2c..000000000000 --- a/include/experimental/optional +++ /dev/null @@ -1,21 +0,0 @@ -// -*- C++ -*- -//===-------------------------- optional ----------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef _LIBCPP_EXPERIMENTAL_OPTIONAL -#define _LIBCPP_EXPERIMENTAL_OPTIONAL - -#include <__config> - -#ifdef _LIBCPP_WARNING -_LIBCPP_WARNING("<experimental/optional> has been removed. Use <optional> instead.") -#else -# warning "<experimental/optional> has been removed. Use <optional> instead." -#endif - -#endif // _LIBCPP_EXPERIMENTAL_OPTIONAL diff --git a/include/experimental/propagate_const b/include/experimental/propagate_const index 188548596b84..092b013bb904 100644 --- a/include/experimental/propagate_const +++ b/include/experimental/propagate_const @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------ propagate_const -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/ratio b/include/experimental/ratio deleted file mode 100644 index 52c12004dba0..000000000000 --- a/include/experimental/ratio +++ /dev/null @@ -1,21 +0,0 @@ -// -*- C++ -*- -//===----------------------------- ratio ----------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef _LIBCPP_EXPERIMENTAL_RATIO -#define _LIBCPP_EXPERIMENTAL_RATIO - -#include <__config> - -#ifdef _LIBCPP_WARNING -_LIBCPP_WARNING("<experimental/ratio> has been removed. Use <ratio> instead.") -#else -# warning "<experimental/ratio> has been removed. Use <ratio> instead." -#endif - -#endif // _LIBCPP_EXPERIMENTAL_RATIO diff --git a/include/experimental/regex b/include/experimental/regex index d38891c374bb..17193cf2f6f6 100644 --- a/include/experimental/regex +++ b/include/experimental/regex @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------- regex ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/set b/include/experimental/set index 20cf6d4a3890..52f4df384278 100644 --- a/include/experimental/set +++ b/include/experimental/set @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- list ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/simd b/include/experimental/simd index 6580443f7b03..39ac35e4eb0a 100644 --- a/include/experimental/simd +++ b/include/experimental/simd @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------------- simd ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_EXPERIMENTAL_SIMD diff --git a/include/experimental/string b/include/experimental/string index 8b8545128f2a..264ff9236822 100644 --- a/include/experimental/string +++ b/include/experimental/string @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- string ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/string_view b/include/experimental/string_view deleted file mode 100644 index 100bdfe72735..000000000000 --- a/include/experimental/string_view +++ /dev/null @@ -1,21 +0,0 @@ -// -*- C++ -*- -//===------------------------ string_view ---------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef _LIBCPP_EXPERIMENTAL_STRING_VIEW -#define _LIBCPP_EXPERIMENTAL_STRING_VIEW - -#include <__config> - -#ifdef _LIBCPP_WARNING -_LIBCPP_WARNING("<experimental/string_view> has been removed. Use <string_view> instead.") -#else -# warning "<experimental/string_view> has been removed. Use <string_view> instead." -#endif - -#endif // _LIBCPP_EXPERIMENTAL_STRING_VIEW diff --git a/include/experimental/system_error b/include/experimental/system_error deleted file mode 100644 index 1cf84ee01251..000000000000 --- a/include/experimental/system_error +++ /dev/null @@ -1,21 +0,0 @@ -// -*- C++ -*- -//===-------------------------- system_error ------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef _LIBCPP_EXPERIMENTAL_SYSTEM_ERROR -#define _LIBCPP_EXPERIMENTAL_SYSTEM_ERROR - -#include <__config> - -#ifdef _LIBCPP_WARNING -_LIBCPP_WARNING("<experimental/system_error> has been removed. Use <system_error> instead.") -#else -# warning "<experimental/system_error> has been removed. Use <system_error> instead." -#endif - -#endif // _LIBCPP_EXPERIMENTAL_SYSTEM_ERROR diff --git a/include/experimental/tuple b/include/experimental/tuple deleted file mode 100644 index 6d71bb559b02..000000000000 --- a/include/experimental/tuple +++ /dev/null @@ -1,21 +0,0 @@ -// -*- C++ -*- -//===----------------------------- tuple ----------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -#ifndef _LIBCPP_EXPERIMENTAL_TUPLE -#define _LIBCPP_EXPERIMENTAL_TUPLE - -#include <__config> - -#ifdef _LIBCPP_WARNING -_LIBCPP_WARNING("<experimental/tuple> has been removed. Use <tuple> instead.") -#else -# warning "<experimental/tuple> has been removed. Use <tuple> instead." -#endif - -#endif // _LIBCPP_EXPERIMENTAL_TUPLE diff --git a/include/experimental/type_traits b/include/experimental/type_traits index afe491567cec..19466e9a5a5d 100644 --- a/include/experimental/type_traits +++ b/include/experimental/type_traits @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- type_traits -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -73,6 +72,7 @@ inline namespace fundamentals_v1 { #if _LIBCPP_STD_VER > 11 +#include <initializer_list> #include <type_traits> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -105,11 +105,10 @@ using raw_invocation_type_t = typename raw_invocation_type<_Tp>::type; // 3.3.4, Detection idiom template <class...> using void_t = void; -struct nonesuch { - nonesuch() = delete; - ~nonesuch() = delete; - nonesuch (nonesuch const&) = delete; - void operator=(nonesuch const&) = delete; +struct nonesuch : private _VSTD::__nat { // make nonesuch "not an aggregate" + ~nonesuch() = delete; + nonesuch (nonesuch const&) = delete; + void operator=(nonesuch const&) = delete; }; template <class _Default, class _AlwaysVoid, template <class...> class _Op, class... _Args> diff --git a/include/experimental/unordered_map b/include/experimental/unordered_map index 1f998c2d4c7e..eca9cea793a4 100644 --- a/include/experimental/unordered_map +++ b/include/experimental/unordered_map @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------- unordered_map ------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/unordered_set b/include/experimental/unordered_set index d00a83753401..323868f785a5 100644 --- a/include/experimental/unordered_set +++ b/include/experimental/unordered_set @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------- unordered_set ------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/utility b/include/experimental/utility index 8effa71c1316..0bca0f7c9c46 100644 --- a/include/experimental/utility +++ b/include/experimental/utility @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- utility ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/experimental/vector b/include/experimental/vector index bd10492bfefc..9b810120695a 100644 --- a/include/experimental/vector +++ b/include/experimental/vector @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- vector ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/ext/__hash b/include/ext/__hash index 318cb1f97b02..d03f101e95a1 100644 --- a/include/ext/__hash +++ b/include/ext/__hash @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------- hash_set ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -17,32 +16,31 @@ #include <cstring> namespace __gnu_cxx { -using namespace std; template <typename _Tp> struct _LIBCPP_TEMPLATE_VIS hash { }; template <> struct _LIBCPP_TEMPLATE_VIS hash<const char*> - : public unary_function<const char*, size_t> + : public std::unary_function<const char*, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(const char *__c) const _NOEXCEPT { - return __do_string_hash(__c, __c + strlen(__c)); + return std::__do_string_hash(__c, __c + strlen(__c)); } }; template <> struct _LIBCPP_TEMPLATE_VIS hash<char *> - : public unary_function<char*, size_t> + : public std::unary_function<char*, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(char *__c) const _NOEXCEPT { - return __do_string_hash<const char *>(__c, __c + strlen(__c)); + return std::__do_string_hash<const char *>(__c, __c + strlen(__c)); } }; template <> struct _LIBCPP_TEMPLATE_VIS hash<char> - : public unary_function<char, size_t> + : public std::unary_function<char, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(char __c) const _NOEXCEPT @@ -52,7 +50,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<char> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<signed char> - : public unary_function<signed char, size_t> + : public std::unary_function<signed char, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(signed char __c) const _NOEXCEPT @@ -62,7 +60,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<signed char> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> - : public unary_function<unsigned char, size_t> + : public std::unary_function<unsigned char, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(unsigned char __c) const _NOEXCEPT @@ -72,7 +70,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned char> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<short> - : public unary_function<short, size_t> + : public std::unary_function<short, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(short __c) const _NOEXCEPT @@ -82,7 +80,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<short> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> - : public unary_function<unsigned short, size_t> + : public std::unary_function<unsigned short, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(unsigned short __c) const _NOEXCEPT @@ -92,7 +90,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned short> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<int> - : public unary_function<int, size_t> + : public std::unary_function<int, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(int __c) const _NOEXCEPT @@ -102,7 +100,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<int> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> - : public unary_function<unsigned int, size_t> + : public std::unary_function<unsigned int, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(unsigned int __c) const _NOEXCEPT @@ -112,7 +110,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned int> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<long> - : public unary_function<long, size_t> + : public std::unary_function<long, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(long __c) const _NOEXCEPT @@ -122,7 +120,7 @@ template <> struct _LIBCPP_TEMPLATE_VIS hash<long> }; template <> struct _LIBCPP_TEMPLATE_VIS hash<unsigned long> - : public unary_function<unsigned long, size_t> + : public std::unary_function<unsigned long, size_t> { _LIBCPP_INLINE_VISIBILITY size_t operator()(unsigned long __c) const _NOEXCEPT diff --git a/include/ext/hash_map b/include/ext/hash_map index 998e8f65994e..24823c6bf0cc 100644 --- a/include/ext/hash_map +++ b/include/ext/hash_map @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- hash_map ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -220,10 +219,8 @@ template <class Key, class T, class Hash, class Pred, class Alloc> namespace __gnu_cxx { -using namespace std; - template <class _Tp, class _Hash, - bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value + bool = std::is_empty<_Hash>::value && !std::__libcpp_is_final<_Hash>::value > class __hash_map_hasher : private _Hash @@ -257,7 +254,7 @@ public: }; template <class _Tp, class _Pred, - bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value + bool = std::is_empty<_Pred>::value && !std::__libcpp_is_final<_Pred>::value > class __hash_map_equal : private _Pred @@ -308,7 +305,7 @@ template <class _Alloc> class __hash_map_node_destructor { typedef _Alloc allocator_type; - typedef allocator_traits<allocator_type> __alloc_traits; + typedef std::allocator_traits<allocator_type> __alloc_traits; typedef typename __alloc_traits::value_type::__node_value_type value_type; public: typedef typename __alloc_traits::pointer pointer; @@ -333,7 +330,7 @@ public: #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - __hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x) + __hash_map_node_destructor(std::__hash_node_destructor<allocator_type>&& __x) : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) @@ -342,7 +339,7 @@ public: } #else // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - __hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x) + __hash_map_node_destructor(const std::__hash_node_destructor<allocator_type>& __x) : __na_(__x.__na_), __first_constructed(__x.__value_constructed), __second_constructed(__x.__value_constructed) @@ -371,11 +368,11 @@ class _LIBCPP_TEMPLATE_VIS __hash_map_iterator typedef const typename _HashIterator::value_type::first_type key_type; typedef typename _HashIterator::value_type::second_type mapped_type; public: - typedef forward_iterator_tag iterator_category; - typedef pair<key_type, mapped_type> value_type; + typedef std::forward_iterator_tag iterator_category; + typedef std::pair<key_type, mapped_type> value_type; typedef typename _HashIterator::difference_type difference_type; typedef value_type& reference; - typedef typename __rebind_pointer<typename _HashIterator::pointer, value_type>::type + typedef typename std::__rebind_pointer<typename _HashIterator::pointer, value_type>::type pointer; _LIBCPP_INLINE_VISIBILITY __hash_map_iterator() {} @@ -416,11 +413,11 @@ class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator typedef const typename _HashIterator::value_type::first_type key_type; typedef typename _HashIterator::value_type::second_type mapped_type; public: - typedef forward_iterator_tag iterator_category; - typedef pair<key_type, mapped_type> value_type; + typedef std::forward_iterator_tag iterator_category; + typedef std::pair<key_type, mapped_type> value_type; typedef typename _HashIterator::difference_type difference_type; typedef const value_type& reference; - typedef typename __rebind_pointer<typename _HashIterator::pointer, const value_type>::type + typedef typename std::__rebind_pointer<typename _HashIterator::pointer, const value_type>::type pointer; _LIBCPP_INLINE_VISIBILITY __hash_map_const_iterator() {} @@ -460,8 +457,8 @@ public: template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator; }; -template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, - class _Alloc = allocator<pair<const _Key, _Tp> > > +template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>, + class _Alloc = std::allocator<std::pair<const _Key, _Tp> > > class _LIBCPP_TEMPLATE_VIS hash_map { public: @@ -472,17 +469,18 @@ public: typedef _Hash hasher; typedef _Pred key_equal; typedef _Alloc allocator_type; - typedef pair<const key_type, mapped_type> value_type; + typedef std::pair<const key_type, mapped_type> value_type; typedef value_type& reference; typedef const value_type& const_reference; private: - typedef pair<key_type, mapped_type> __value_type; + typedef std::pair<key_type, mapped_type> __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; - typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type; + typedef typename std::__rebind_alloc_helper< + std::allocator_traits<allocator_type>, __value_type>::type __allocator_type; - typedef __hash_table<__value_type, __hasher, + typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; __table __table_; @@ -493,8 +491,8 @@ private: typedef typename __table::__node_allocator __node_allocator; typedef typename __table::__node __node; typedef __hash_map_node_destructor<__node_allocator> _Dp; - typedef unique_ptr<__node, _Dp> __node_holder; - typedef allocator_traits<allocator_type> __alloc_traits; + typedef std::unique_ptr<__node, _Dp> __node_holder; + typedef std::allocator_traits<allocator_type> __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; @@ -544,7 +542,7 @@ public: const_iterator end() const {return __table_.end();} _LIBCPP_INLINE_VISIBILITY - pair<iterator, bool> insert(const value_type& __x) + std::pair<iterator, bool> insert(const value_type& __x) {return __table_.__insert_unique(__x);} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} @@ -579,10 +577,10 @@ public: _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} _LIBCPP_INLINE_VISIBILITY - pair<iterator, iterator> equal_range(const key_type& __k) + std::pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_unique(__k);} _LIBCPP_INLINE_VISIBILITY - pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {return __table_.__equal_range_unique(__k);} mapped_type& operator[](const key_type& __k); @@ -692,7 +690,7 @@ hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k) if (__i != end()) return __i->second; __node_holder __h = __construct_node(__k); - pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); + std::pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get()); __h.release(); return __r.first->second; } @@ -734,8 +732,8 @@ operator!=(const hash_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, return !(__x == __y); } -template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>, - class _Alloc = allocator<pair<const _Key, _Tp> > > +template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = std::equal_to<_Key>, + class _Alloc = std::allocator<std::pair<const _Key, _Tp> > > class _LIBCPP_TEMPLATE_VIS hash_multimap { public: @@ -746,17 +744,17 @@ public: typedef _Hash hasher; typedef _Pred key_equal; typedef _Alloc allocator_type; - typedef pair<const key_type, mapped_type> value_type; + typedef std::pair<const key_type, mapped_type> value_type; typedef value_type& reference; typedef const value_type& const_reference; private: - typedef pair<key_type, mapped_type> __value_type; + typedef std::pair<key_type, mapped_type> __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; - typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __value_type>::type __allocator_type; + typedef typename std::__rebind_alloc_helper<std::allocator_traits<allocator_type>, __value_type>::type __allocator_type; - typedef __hash_table<__value_type, __hasher, + typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; __table __table_; @@ -765,8 +763,8 @@ private: typedef typename __table::__node_allocator __node_allocator; typedef typename __table::__node __node; typedef __hash_map_node_destructor<__node_allocator> _Dp; - typedef unique_ptr<__node, _Dp> __node_holder; - typedef allocator_traits<allocator_type> __alloc_traits; + typedef std::unique_ptr<__node, _Dp> __node_holder; + typedef std::allocator_traits<allocator_type> __alloc_traits; public: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; @@ -851,10 +849,10 @@ public: _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} _LIBCPP_INLINE_VISIBILITY - pair<iterator, iterator> equal_range(const key_type& __k) + std::pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY - pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY @@ -956,7 +954,7 @@ operator==(const hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x, return false; typedef typename hash_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::const_iterator const_iterator; - typedef pair<const_iterator, const_iterator> _EqRng; + typedef std::pair<const_iterator, const_iterator> _EqRng; for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) { _EqRng __xeq = __x.equal_range(__i->first); diff --git a/include/ext/hash_set b/include/ext/hash_set index 38f81ed3b5c8..e5141824b601 100644 --- a/include/ext/hash_set +++ b/include/ext/hash_set @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------- hash_set ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -208,10 +207,9 @@ template <class Value, class Hash, class Pred, class Alloc> namespace __gnu_cxx { -using namespace std; -template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, - class _Alloc = allocator<_Value> > +template <class _Value, class _Hash = hash<_Value>, class _Pred = std::equal_to<_Value>, + class _Alloc = std::allocator<_Value> > class _LIBCPP_TEMPLATE_VIS hash_set { public: @@ -225,7 +223,7 @@ public: typedef const value_type& const_reference; private: - typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; + typedef std::__hash_table<value_type, hasher, key_equal, allocator_type> __table; __table __table_; @@ -277,7 +275,7 @@ public: const_iterator end() const {return __table_.end();} _LIBCPP_INLINE_VISIBILITY - pair<iterator, bool> insert(const value_type& __x) + std::pair<iterator, bool> insert(const value_type& __x) {return __table_.__insert_unique(__x);} _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator, const value_type& __x) {return insert(__x).first;} @@ -310,10 +308,10 @@ public: _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} _LIBCPP_INLINE_VISIBILITY - pair<iterator, iterator> equal_range(const key_type& __k) + std::pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_unique(__k);} _LIBCPP_INLINE_VISIBILITY - pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {return __table_.__equal_range_unique(__k);} _LIBCPP_INLINE_VISIBILITY @@ -432,8 +430,8 @@ operator!=(const hash_set<_Value, _Hash, _Pred, _Alloc>& __x, return !(__x == __y); } -template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>, - class _Alloc = allocator<_Value> > +template <class _Value, class _Hash = hash<_Value>, class _Pred = std::equal_to<_Value>, + class _Alloc = std::allocator<_Value> > class _LIBCPP_TEMPLATE_VIS hash_multiset { public: @@ -447,7 +445,7 @@ public: typedef const value_type& const_reference; private: - typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; + typedef std::__hash_table<value_type, hasher, key_equal, allocator_type> __table; __table __table_; @@ -531,10 +529,10 @@ public: _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} _LIBCPP_INLINE_VISIBILITY - pair<iterator, iterator> equal_range(const key_type& __k) + std::pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY - pair<const_iterator, const_iterator> equal_range(const key_type& __k) const + std::pair<const_iterator, const_iterator> equal_range(const key_type& __k) const {return __table_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY @@ -611,7 +609,7 @@ template <class _InputIterator> inline void hash_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first, - _InputIterator __last) + _InputIterator __last) { for (; __first != __last; ++__first) __table_.__insert_multi(*__first); @@ -635,7 +633,7 @@ operator==(const hash_multiset<_Value, _Hash, _Pred, _Alloc>& __x, return false; typedef typename hash_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator const_iterator; - typedef pair<const_iterator, const_iterator> _EqRng; + typedef std::pair<const_iterator, const_iterator> _EqRng; for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;) { _EqRng __xeq = __x.equal_range(*__i); diff --git a/include/fenv.h b/include/fenv.h new file mode 100644 index 000000000000..988cd9b112fb --- /dev/null +++ b/include/fenv.h @@ -0,0 +1,116 @@ +// -*- C++ -*- +//===---------------------------- math.h ----------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_FENV_H +#define _LIBCPP_FENV_H + + +/* + fenv.h synopsis + +This entire header is C99 / C++0X + +Macros: + + FE_DIVBYZERO + FE_INEXACT + FE_INVALID + FE_OVERFLOW + FE_UNDERFLOW + FE_ALL_EXCEPT + FE_DOWNWARD + FE_TONEAREST + FE_TOWARDZERO + FE_UPWARD + FE_DFL_ENV + +Types: + + fenv_t + fexcept_t + +int feclearexcept(int excepts); +int fegetexceptflag(fexcept_t* flagp, int excepts); +int feraiseexcept(int excepts); +int fesetexceptflag(const fexcept_t* flagp, int excepts); +int fetestexcept(int excepts); +int fegetround(); +int fesetround(int round); +int fegetenv(fenv_t* envp); +int feholdexcept(fenv_t* envp); +int fesetenv(const fenv_t* envp); +int feupdateenv(const fenv_t* envp); + + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <fenv.h> + +#ifdef __cplusplus + +extern "C++" { + +#ifdef feclearexcept +#undef feclearexcept +#endif + +#ifdef fegetexceptflag +#undef fegetexceptflag +#endif + + +#ifdef feraiseexcept +#undef feraiseexcept +#endif + +#ifdef fesetexceptflag +#undef fesetexceptflag +#endif + + +#ifdef fetestexcept +#undef fetestexcept +#endif + +#ifdef fegetround +#undef fegetround +#endif + +#ifdef fesetround +#undef fesetround +#endif + +#ifdef fegetenv +#undef fegetenv +#endif + +#ifdef feholdexcept +#undef feholdexcept +#endif + + +#ifdef fesetenv +#undef fesetenv +#endif + +#ifdef feupdateenv +#undef feupdateenv +#endif + +} // extern "C++" + +#endif // defined(__cplusplus) + +#endif // _LIBCPP_FENV_H diff --git a/include/filesystem b/include/filesystem index af713a063587..3aaa7988a872 100644 --- a/include/filesystem +++ b/include/filesystem @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- filesystem -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_FILESYSTEM @@ -259,6 +258,8 @@ _LIBCPP_PUSH_MACROS _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + typedef chrono::time_point<_FilesystemClock> file_time_type; struct _LIBCPP_TYPE_VIS space_info { @@ -1311,7 +1312,11 @@ inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs, return !(__lhs == __rhs); } -class _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error { +// TODO(ldionne): We need to pop the pragma and push it again after +// filesystem_error to work around PR41078. +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error { public: _LIBCPP_INLINE_VISIBILITY filesystem_error(const string& __what, error_code __ec) @@ -1348,11 +1353,10 @@ public: return __storage_->__what_.c_str(); } - _LIBCPP_FUNC_VIS void __create_what(int __num_paths); private: - struct _Storage { + struct _LIBCPP_HIDDEN _Storage { _LIBCPP_INLINE_VISIBILITY _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {} @@ -1363,16 +1367,16 @@ private: shared_ptr<_Storage> __storage_; }; +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + template <class... _Args> _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY #ifndef _LIBCPP_NO_EXCEPTIONS - void - __throw_filesystem_error(_Args&&... __args) { +void __throw_filesystem_error(_Args&&... __args) { throw filesystem_error(std::forward<_Args>(__args)...); } #else - void - __throw_filesystem_error(_Args&&...) { +void __throw_filesystem_error(_Args&&...) { _VSTD::abort(); } #endif @@ -1938,7 +1942,7 @@ inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p, class directory_iterator; class recursive_directory_iterator; -class __dir_stream; +class _LIBCPP_HIDDEN __dir_stream; class directory_entry { typedef _VSTD_FS::path _Path; @@ -2601,7 +2605,7 @@ private: operator==(const recursive_directory_iterator&, const recursive_directory_iterator&) noexcept; - struct __shared_imp; + struct _LIBCPP_HIDDEN __shared_imp; shared_ptr<__shared_imp> __imp_; bool __rec_; }; // class recursive_directory_iterator @@ -2628,6 +2632,8 @@ end(const recursive_directory_iterator&) noexcept { return recursive_directory_iterator(); } +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + _LIBCPP_END_NAMESPACE_FILESYSTEM #endif // !_LIBCPP_CXX03_LANG diff --git a/include/float.h b/include/float.h index 759ac8e79543..5c1e1db79766 100644 --- a/include/float.h +++ b/include/float.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- float.h ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/forward_list b/include/forward_list index b506acd1ff20..d59ddd4ef97a 100644 --- a/include/forward_list +++ b/include/forward_list @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------- forward_list ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -121,10 +120,12 @@ public: const_iterator first, const_iterator last); void splice_after(const_iterator p, forward_list&& x, const_iterator first, const_iterator last); - void remove(const value_type& v); - template <class Predicate> void remove_if(Predicate pred); - void unique(); - template <class BinaryPredicate> void unique(BinaryPredicate binary_pred); + size_type remove(const value_type& v); // void before C++20 + template <class Predicate> + size_type remove_if(Predicate pred); // void before C++20 + size_type unique(); // void before C++20 + template <class BinaryPredicate> + size_type unique(BinaryPredicate binary_pred); // void before C++20 void merge(forward_list& x); void merge(forward_list&& x); template <class Compare> void merge(forward_list& x, Compare comp); @@ -531,7 +532,7 @@ public: #if _LIBCPP_STD_VER >= 14 _NOEXCEPT; #else - _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || + _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || __is_nothrow_swappable<__node_allocator>::value); #endif protected: @@ -596,11 +597,11 @@ __forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT #else - _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || + _NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value || __is_nothrow_swappable<__node_allocator>::value) #endif { - __swap_allocator(__alloc(), __x.__alloc(), + __swap_allocator(__alloc(), __x.__alloc(), integral_constant<bool, __node_traits::propagate_on_container_swap::value>()); using _VSTD::swap; swap(__before_begin()->__next_, __x.__before_begin()->__next_); @@ -648,6 +649,11 @@ public: typedef typename base::iterator iterator; typedef typename base::const_iterator const_iterator; +#if _LIBCPP_STD_VER > 17 + typedef size_type __remove_return_type; +#else + typedef void __remove_return_type; +#endif _LIBCPP_INLINE_VISIBILITY forward_list() @@ -809,7 +815,6 @@ public: _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT {base::clear();} -#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void splice_after(const_iterator __p, forward_list&& __x); _LIBCPP_INLINE_VISIBILITY @@ -817,16 +822,15 @@ public: _LIBCPP_INLINE_VISIBILITY void splice_after(const_iterator __p, forward_list&& __x, const_iterator __f, const_iterator __l); -#endif // _LIBCPP_CXX03_LANG void splice_after(const_iterator __p, forward_list& __x); void splice_after(const_iterator __p, forward_list& __x, const_iterator __i); void splice_after(const_iterator __p, forward_list& __x, const_iterator __f, const_iterator __l); - void remove(const value_type& __v); - template <class _Predicate> void remove_if(_Predicate __pred); + __remove_return_type remove(const value_type& __v); + template <class _Predicate> __remove_return_type remove_if(_Predicate __pred); _LIBCPP_INLINE_VISIBILITY - void unique() {unique(__equal_to<value_type>());} - template <class _BinaryPredicate> void unique(_BinaryPredicate __binary_pred); + __remove_return_type unique() {return unique(__equal_to<value_type>());} + template <class _BinaryPredicate> __remove_return_type unique(_BinaryPredicate __binary_pred); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void merge(forward_list&& __x) {merge(__x, __less<value_type>());} @@ -1469,8 +1473,6 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, } } -#ifndef _LIBCPP_CXX03_LANG - template <class _Tp, class _Alloc> inline _LIBCPP_INLINE_VISIBILITY void @@ -1500,21 +1502,21 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p, splice_after(__p, __x, __f, __l); } -#endif // _LIBCPP_CXX03_LANG - template <class _Tp, class _Alloc> -void +typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Alloc>::remove(const value_type& __v) { - forward_list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing - iterator __e = end(); + forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing + typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0; + const iterator __e = end(); for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;) { if (__i.__get_begin()->__next_->__value_ == __v) { + ++__count_removed; iterator __j = _VSTD::next(__i, 2); for (; __j != __e && *__j == __v; ++__j) - ; + ++__count_removed; __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j); if (__j == __e) break; @@ -1523,22 +1525,27 @@ forward_list<_Tp, _Alloc>::remove(const value_type& __v) else ++__i; } + + return (__remove_return_type) __count_removed; } template <class _Tp, class _Alloc> template <class _Predicate> -void +typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred) { - iterator __e = end(); + forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing + typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0; + const iterator __e = end(); for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;) { if (__pred(__i.__get_begin()->__next_->__value_)) { + ++__count_removed; iterator __j = _VSTD::next(__i, 2); for (; __j != __e && __pred(*__j); ++__j) - ; - erase_after(__i, __j); + ++__count_removed; + __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j); if (__j == __e) break; __i = __j; @@ -1546,22 +1553,28 @@ forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred) else ++__i; } + + return (__remove_return_type) __count_removed; } template <class _Tp, class _Alloc> template <class _BinaryPredicate> -void +typename forward_list<_Tp, _Alloc>::__remove_return_type forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred) { + forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing + typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0; for (iterator __i = begin(), __e = end(); __i != __e;) { iterator __j = _VSTD::next(__i); for (; __j != __e && __binary_pred(*__i, *__j); ++__j) - ; + ++__count_removed; if (__i.__get_begin()->__next_ != __j.__get_unsafe_node_pointer()) - erase_after(__i, __j); + __deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j); __i = __j; } + + return (__remove_return_type) __count_removed; } template <class _Tp, class _Alloc> diff --git a/include/fstream b/include/fstream index 711e484e2dcf..60a05b0d4b95 100644 --- a/include/fstream +++ b/include/fstream @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------- fstream ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -236,7 +235,7 @@ public: basic_filebuf* open(const string& __s, ios_base::openmode __mode); #if _LIBCPP_STD_VER >= 17 - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY basic_filebuf* open(const _VSTD_FS::path& __p, ios_base::openmode __mode) { return open(__p.c_str(), __mode); } @@ -758,7 +757,7 @@ basic_filebuf<_CharT, _Traits>::underflow() this->eback() + __ibs_, __inext); if (__r == codecvt_base::noconv) { - this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, + this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)const_cast<char *>(__extbufend_)); __c = traits_type::to_int_type(*this->gptr()); } @@ -1152,7 +1151,7 @@ public: _LIBCPP_INLINE_VISIBILITY explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in); #if _LIBCPP_STD_VER >= 17 - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY explicit basic_ifstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in) : basic_ifstream(__p.c_str(), __mode) {} #endif // _LIBCPP_STD_VER >= 17 @@ -1178,7 +1177,7 @@ public: #endif void open(const string& __s, ios_base::openmode __mode = ios_base::in); #if _LIBCPP_STD_VER >= 17 - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in) { return open(__p.c_str(), __mode); @@ -1366,7 +1365,7 @@ public: explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out); #if _LIBCPP_STD_VER >= 17 - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY explicit basic_ofstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out) : basic_ofstream(__p.c_str(), __mode) {} #endif // _LIBCPP_STD_VER >= 17 @@ -1393,7 +1392,7 @@ public: void open(const string& __s, ios_base::openmode __mode = ios_base::out); #if _LIBCPP_STD_VER >= 17 - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out) { return open(__p.c_str(), __mode); } #endif // _LIBCPP_STD_VER >= 17 @@ -1580,7 +1579,7 @@ public: explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); #if _LIBCPP_STD_VER >= 17 - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY explicit basic_fstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in | ios_base::out) : basic_fstream(__p.c_str(), __mode) {} #endif // _LIBCPP_STD_VER >= 17 @@ -1608,7 +1607,7 @@ public: void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); #if _LIBCPP_STD_VER >= 17 - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in|ios_base::out) { return open(__p.c_str(), __mode); } #endif // _LIBCPP_STD_VER >= 17 diff --git a/include/functional b/include/functional index 95491879b0c7..bcd74a9ee597 100644 --- a/include/functional +++ b/include/functional @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------ functional ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -231,6 +230,10 @@ template<class Fn, class... BoundArgs> template<class R, class Fn, class... BoundArgs> unspecified bind(Fn&&, BoundArgs&&...); +template<class F, class... Args> + invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17 + noexcept(is_nothrow_invocable_v<F, Args...>); + namespace placeholders { // M is the implementation-defined number of placeholders extern unspecified _1; @@ -1476,6 +1479,8 @@ namespace __function { // __alloc_func holds a functor and an allocator. template <class _Fp, class _Ap, class _FB> class __alloc_func; +template <class _Fp, class _FB> +class __default_alloc_func; template <class _Fp, class _Ap, class _Rp, class... _ArgTypes> class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> @@ -1483,14 +1488,15 @@ class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> __compressed_pair<_Fp, _Ap> __f_; public: - typedef _Fp _Target; - typedef _Ap _Alloc; + typedef _LIBCPP_NODEBUG_TYPE _Fp _Target; + typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc; _LIBCPP_INLINE_VISIBILITY const _Target& __target() const { return __f_.first(); } + // WIN32 APIs may define __allocator, so use __get_allocator instead. _LIBCPP_INLINE_VISIBILITY - const _Alloc& __allocator() const { return __f_.second(); } + const _Alloc& __get_allocator() const { return __f_.second(); } _LIBCPP_INLINE_VISIBILITY explicit __alloc_func(_Target&& __f) @@ -1544,6 +1550,56 @@ class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> _LIBCPP_INLINE_VISIBILITY void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } + + static void __destroy_and_delete(__alloc_func* __f) { + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type + _FunAlloc; + _FunAlloc __a(__f->__get_allocator()); + __f->destroy(); + __a.deallocate(__f, 1); + } +}; + +template <class _Fp, class _Rp, class... _ArgTypes> +class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { + _Fp __f_; + +public: + typedef _LIBCPP_NODEBUG_TYPE _Fp _Target; + + _LIBCPP_INLINE_VISIBILITY + const _Target& __target() const { return __f_; } + + _LIBCPP_INLINE_VISIBILITY + explicit __default_alloc_func(_Target&& __f) : __f_(std::move(__f)) {} + + _LIBCPP_INLINE_VISIBILITY + explicit __default_alloc_func(const _Target& __f) : __f_(__f) {} + + _LIBCPP_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __arg) { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...); + } + + _LIBCPP_INLINE_VISIBILITY + __default_alloc_func* __clone() const { + __builtin_new_allocator::__holder_t __hold = + __builtin_new_allocator::__allocate_type<__default_alloc_func>(1); + __default_alloc_func* __res = + ::new (__hold.get()) __default_alloc_func(__f_); + (void)__hold.release(); + return __res; + } + + _LIBCPP_INLINE_VISIBILITY + void destroy() _NOEXCEPT { __f_.~_Target(); } + + static void __destroy_and_delete(__default_alloc_func* __f) { + __f->destroy(); + __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1); + } }; // __base provides an abstract interface for copyable functors. @@ -1612,7 +1668,7 @@ __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const { typedef allocator_traits<_Alloc> __alloc_traits; typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.__allocator()); + _Ap __a(__f_.__get_allocator()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a)); @@ -1623,7 +1679,7 @@ template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> void __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const { - ::new (__p) __func(__f_.__target(), __f_.__allocator()); + ::new (__p) __func(__f_.__target(), __f_.__get_allocator()); } template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> @@ -1639,7 +1695,7 @@ __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT { typedef allocator_traits<_Alloc> __alloc_traits; typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.__allocator()); + _Ap __a(__f_.__get_allocator()); __f_.destroy(); __a.deallocate(this, 1); } @@ -1692,7 +1748,7 @@ template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)> __value_func() _NOEXCEPT : __f_(0) {} template <class _Fp, class _Alloc> - _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc __a) + _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a) : __f_(0) { typedef allocator_traits<_Alloc> __alloc_traits; @@ -1720,6 +1776,11 @@ template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)> } } + template <class _Fp, + class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type> + _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f) + : __value_func(std::forward<_Fp>(__f), allocator<_Fp>()) {} + _LIBCPP_INLINE_VISIBILITY __value_func(const __value_func& __f) { @@ -1919,29 +1980,22 @@ struct __policy return __f->__clone(); } - template <typename _Fun> static void __large_destroy(void* __s) - { - typedef allocator_traits<typename _Fun::_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type - _FunAlloc; - _Fun* __f = static_cast<_Fun*>(__s); - _FunAlloc __a(__f->__allocator()); - __f->destroy(); - __a.deallocate(__f, 1); + template <typename _Fun> + static void __large_destroy(void* __s) { + _Fun::__destroy_and_delete(static_cast<_Fun*>(__s)); } template <typename _Fun> _LIBCPP_INLINE_VISIBILITY static const __policy* - __choose_policy(/* is_small = */ false_type) - { - static const _LIBCPP_CONSTEXPR __policy __policy_ = { - &__large_clone<_Fun>, &__large_destroy<_Fun>, false, + __choose_policy(/* is_small = */ false_type) { + static const _LIBCPP_CONSTEXPR __policy __policy_ = { + &__large_clone<_Fun>, &__large_destroy<_Fun>, false, #ifndef _LIBCPP_NO_RTTI - &typeid(typename _Fun::_Target) + &typeid(typename _Fun::_Target) #else - nullptr + nullptr #endif - }; + }; return &__policy_; } @@ -2066,6 +2120,25 @@ template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)> } } + template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type> + _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f) + : __policy_(__policy::__create_empty()) { + typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun; + + if (__function::__not_null(__f)) { + __invoker_ = __invoker::template __create<_Fun>(); + __policy_ = __policy::__create<_Fun>(); + if (__use_small_storage<_Fun>()) { + ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f)); + } else { + __builtin_new_allocator::__holder_t __hold = + __builtin_new_allocator::__allocate_type<_Fun>(1); + __buf_.__large = ::new (__hold.get()) _Fun(_VSTD::move(__f)); + (void)__hold.release(); + } + } + } + _LIBCPP_INLINE_VISIBILITY __policy_func(const __policy_func& __f) : __buf_(__f.__buf_), __invoker_(__f.__invoker_), @@ -2173,8 +2246,8 @@ class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> __func __f_; - template <class _Fp, bool = __lazy_and< - integral_constant<bool, !is_same<__uncvref_t<_Fp>, function>::value>, + template <class _Fp, bool = _And< + _IsNotSame<__uncvref_t<_Fp>, function>, __invokable<_Fp&, _ArgTypes...> >::value> struct __callable; @@ -2286,8 +2359,7 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, template <class _Rp, class... _ArgTypes> template <class _Fp, class> -function<_Rp(_ArgTypes...)>::function(_Fp __f) - : __f_(_VSTD::move(__f), allocator<_Fp>()) {} +function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {} #if _LIBCPP_STD_VER <= 14 template <class _Rp, class... _ArgTypes> @@ -2484,7 +2556,7 @@ __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) template <class _Ti, class ..._Uj> inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if +typename _EnableIf < is_bind_expression<_Ti>::value, __invoke_of<_Ti&, _Uj...> @@ -2769,9 +2841,9 @@ bind(_Fp&& __f, _BoundArgs&&... __bound_args) #if _LIBCPP_STD_VER > 14 template <class _Fn, class ..._Args> -result_of_t<_Fn&&(_Args&&...)> +invoke_result_t<_Fn, _Args...> invoke(_Fn&& __f, _Args&&... __args) - noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...))) + noexcept(is_nothrow_invocable_v<_Fn, _Args...>) { return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); } diff --git a/include/future b/include/future index b3ffc7e35177..6da88c6e62b2 100644 --- a/include/future +++ b/include/future @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- future -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -409,11 +408,7 @@ _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch) #ifndef _LIBCPP_HAS_NO_STRONG_ENUMS -#ifdef _LIBCPP_UNDERLYING_TYPE typedef underlying_type<launch>::type __launch_underlying_type; -#else -typedef int __launch_underlying_type; -#endif inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR @@ -2016,7 +2011,7 @@ public: class = typename enable_if < !is_same< - typename __uncvref<_Fp>::type, + typename __uncvref<_Fp>::type, packaged_task >::value >::type @@ -2027,7 +2022,7 @@ public: class = typename enable_if < !is_same< - typename __uncvref<_Fp>::type, + typename __uncvref<_Fp>::type, packaged_task >::value >::type @@ -2145,7 +2140,7 @@ public: class = typename enable_if < !is_same< - typename __uncvref<_Fp>::type, + typename __uncvref<_Fp>::type, packaged_task >::value >::type @@ -2156,11 +2151,11 @@ public: class = typename enable_if < !is_same< - typename __uncvref<_Fp>::type, + typename __uncvref<_Fp>::type, packaged_task >::value >::type - > + > _LIBCPP_INLINE_VISIBILITY packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f) : __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)), diff --git a/include/initializer_list b/include/initializer_list index b934637b83d3..893736f57ead 100644 --- a/include/initializer_list +++ b/include/initializer_list @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------- initializer_list -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -83,7 +82,7 @@ public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 size_t size() const _NOEXCEPT {return __size_;} - + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Ep* begin() const _NOEXCEPT {return __begin_;} diff --git a/include/inttypes.h b/include/inttypes.h index 058f54b5161f..e136b234a4ae 100644 --- a/include/inttypes.h +++ b/include/inttypes.h @@ -1,15 +1,19 @@ // -*- C++ -*- //===--------------------------- inttypes.h -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_INTTYPES_H +// AIX system headers need inttypes.h to be re-enterable while _STD_TYPES_T +// is defined until an inclusion of it without _STD_TYPES_T occurs, in which +// case the header guard macro is defined. +#if !defined(_AIX) || !defined(_STD_TYPES_T) #define _LIBCPP_INTTYPES_H +#endif // _STD_TYPES_T /* inttypes.h synopsis diff --git a/include/iomanip b/include/iomanip index 36c11167a44e..3f78f4d02b3c 100644 --- a/include/iomanip +++ b/include/iomanip @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- iomanip ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -516,7 +515,7 @@ put_time(const tm* __tm, const _CharT* __fmt) template <class _CharT, class _Traits, class _ForwardIterator> std::basic_ostream<_CharT, _Traits> & -__quoted_output ( basic_ostream<_CharT, _Traits> &__os, +__quoted_output ( basic_ostream<_CharT, _Traits> &__os, _ForwardIterator __first, _ForwardIterator __last, _CharT __delim, _CharT __escape ) { _VSTD::basic_string<_CharT, _Traits> __str; @@ -571,7 +570,7 @@ __quoted_input ( basic_istream<_CharT, _Traits> &__is, _String & __string, _Char template <class _CharT, class _Traits, class _Iter> basic_ostream<_CharT, _Traits>& operator<<( - basic_ostream<_CharT, _Traits>& __os, + basic_ostream<_CharT, _Traits>& __os, const __quoted_output_proxy<_CharT, _Iter, _Traits> & __proxy) { return __quoted_output (__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape); @@ -591,7 +590,7 @@ struct __quoted_proxy template <class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY basic_ostream<_CharT, _Traits>& operator<<( - basic_ostream<_CharT, _Traits>& __os, + basic_ostream<_CharT, _Traits>& __os, const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy) { return __quoted_output (__os, __proxy.__string.cbegin (), __proxy.__string.cend (), __proxy.__delim, __proxy.__escape); @@ -601,7 +600,7 @@ basic_ostream<_CharT, _Traits>& operator<<( template <class _CharT, class _Traits, class _Allocator> _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& operator>>( - basic_istream<_CharT, _Traits>& __is, + basic_istream<_CharT, _Traits>& __is, const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy) { return __quoted_input ( __is, __proxy.__string, __proxy.__delim, __proxy.__escape ); @@ -661,7 +660,7 @@ __quoted_output_proxy<_CharT, const _CharT *, _Traits> quoted (basic_string_view <_CharT, _Traits> __sv, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\')) { - return __quoted_output_proxy<_CharT, const _CharT *, _Traits> + return __quoted_output_proxy<_CharT, const _CharT *, _Traits> ( __sv.data(), __sv.data() + __sv.size(), __delim, __escape ); } #endif diff --git a/include/ios b/include/ios index 040b2d4e04f1..88efefb46ff2 100644 --- a/include/ios +++ b/include/ios @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- ios -------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -203,8 +202,8 @@ enum class io_errc }; concept_map ErrorCodeEnum<io_errc> { }; -error_code make_error_code(io_errc e) noexcept; -error_condition make_error_condition(io_errc e) noexcept; +error_code make_error_code(io_errc e) noexcept; +error_condition make_error_condition(io_errc e) noexcept; storage-class-specifier const error_category& iostream_category() noexcept; } // std @@ -331,6 +330,15 @@ public: void __set_badbit_and_consider_rethrow(); void __set_failbit_and_consider_rethrow(); + _LIBCPP_INLINE_VISIBILITY + void __setstate_nothrow(iostate __state) + { + if (__rdbuf_) + __rdstate_ |= __state; + else + __rdstate_ |= __state | ios_base::badbit; + } + protected: _LIBCPP_INLINE_VISIBILITY ios_base() {// purposefully does no initialization @@ -426,6 +434,16 @@ public: virtual ~failure() throw(); }; +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +void __throw_failure(char const* __msg) { +#ifndef _LIBCPP_NO_EXCEPTIONS + throw ios_base::failure(__msg); +#else + ((void)__msg); + _VSTD::abort(); +#endif +} + class _LIBCPP_TYPE_VIS ios_base::Init { public: @@ -626,47 +644,47 @@ public: virtual ~basic_ios(); // 27.5.4.2 Members: - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY basic_ostream<char_type, traits_type>* tie() const; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr); - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY basic_streambuf<char_type, traits_type>* rdbuf() const; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb); basic_ios& copyfmt(const basic_ios& __rhs); - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY char_type fill() const; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY char_type fill(char_type __ch); - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY locale imbue(const locale& __loc); - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY char narrow(char_type __c, char __dfault) const; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY char_type widen(char __c) const; protected: _LIBCPP_INLINE_VISIBILITY basic_ios() {// purposefully does no initialization } - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY void init(basic_streambuf<char_type, traits_type>* __sb); - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY void move(basic_ios& __rhs); #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void move(basic_ios&& __rhs) {move(__rhs);} #endif - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY void swap(basic_ios& __rhs) _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb); private: basic_ostream<char_type, traits_type>* __tie_; diff --git a/include/iosfwd b/include/iosfwd index 31f1902e5f59..0ffe75f197c3 100644 --- a/include/iosfwd +++ b/include/iosfwd @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- iosfwd -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/iostream b/include/iostream index 136a849777fe..595620b8aa62 100644 --- a/include/iostream +++ b/include/iostream @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- iostream ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/istream b/include/istream index 30ee4f4b8710..d6217bbb8009 100644 --- a/include/istream +++ b/include/istream @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- istream ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -363,26 +362,31 @@ template <class _Tp, class _CharT, class _Traits> _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& __input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __s(__is); + if (__s) { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_istream<_CharT, _Traits>::sentry __s(__is); - if (__s) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS typedef istreambuf_iterator<_CharT, _Traits> _Ip; typedef num_get<_CharT, _Ip> _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __n); - __is.setstate(__err); - } + use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __n); #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); } - catch (...) - { - __is.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS return __is; } @@ -467,39 +471,46 @@ template <class _Tp, class _CharT, class _Traits> _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& __input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __s(__is); + if (__s) { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_istream<_CharT, _Traits>::sentry __s(__is); - if (__s) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS typedef istreambuf_iterator<_CharT, _Traits> _Ip; typedef num_get<_CharT, _Ip> _Fp; - ios_base::iostate __err = ios_base::goodbit; long __temp; - use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __temp); + use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __temp); if (__temp < numeric_limits<_Tp>::min()) { - __err |= ios_base::failbit; + __state |= ios_base::failbit; __n = numeric_limits<_Tp>::min(); } else if (__temp > numeric_limits<_Tp>::max()) { - __err |= ios_base::failbit; + __state |= ios_base::failbit; __n = numeric_limits<_Tp>::max(); } else + { __n = static_cast<_Tp>(__temp); - __is.setstate(__err); - } + } #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __is.__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } #endif // _LIBCPP_NO_EXCEPTIONS + __is.setstate(__state); + } return __is; } @@ -522,22 +533,22 @@ _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_istream<_CharT, _Traits>::sentry __sen(__is); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { - auto __s = __p; +#endif + _CharT* __s = __p; const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); - ios_base::iostate __err = ios_base::goodbit; while (__s != __p + (__n-1)) { typename _Traits::int_type __i = __is.rdbuf()->sgetc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { - __err |= ios_base::eofbit; + __state |= ios_base::eofbit; break; } _CharT __ch = _Traits::to_char_type(__i); @@ -549,16 +560,21 @@ __input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n) *__s = _CharT(); __is.width(0); if (__s == __p) - __err |= ios_base::failbit; - __is.setstate(__err); - } + __state |= ios_base::failbit; #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); } - catch (...) - { - __is.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS return __is; } @@ -569,7 +585,7 @@ inline _LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, _CharT (&__buf)[_Np]) { - auto __n = _Np; + size_t __n = _Np; if (__is.width() > 0) __n = _VSTD::min(size_t(__is.width()), _Np); return _VSTD::__input_c_string(__is, __buf, __n); @@ -626,26 +642,33 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_istream<_CharT, _Traits>::sentry __sen(__is); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); if (_Traits::eq_int_type(__i, _Traits::eof())) - __is.setstate(ios_base::eofbit | ios_base::failbit); + __state |= ios_base::eofbit | ios_base::failbit; else __c = _Traits::to_char_type(__i); - } #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); } - catch (...) - { - __is.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS return __is; } @@ -669,58 +692,56 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb) { + ios_base::iostate __state = ios_base::goodbit; __gc_ = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __s(*this, true); + if (__s) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this, true); - if (__s) + if (__sb) { - if (__sb) - { #ifndef _LIBCPP_NO_EXCEPTIONS - try + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + while (true) { -#endif // _LIBCPP_NO_EXCEPTIONS - ios_base::iostate __err = ios_base::goodbit; - while (true) + typename traits_type::int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, _Traits::eof())) { - typename traits_type::int_type __i = this->rdbuf()->sgetc(); - if (traits_type::eq_int_type(__i, _Traits::eof())) - { - __err |= ios_base::eofbit; - break; - } - if (traits_type::eq_int_type( - __sb->sputc(traits_type::to_char_type(__i)), - traits_type::eof())) - break; - ++__gc_; - this->rdbuf()->sbumpc(); + __state |= ios_base::eofbit; + break; } - if (__gc_ == 0) - __err |= ios_base::failbit; - this->setstate(__err); -#ifndef _LIBCPP_NO_EXCEPTIONS + if (traits_type::eq_int_type( + __sb->sputc(traits_type::to_char_type(__i)), + traits_type::eof())) + break; + ++__gc_; + this->rdbuf()->sbumpc(); } - catch (...) + if (__gc_ == 0) + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + if (__gc_ == 0) + __state |= ios_base::failbit; + + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::failbit || this->exceptions() & ios_base::badbit) { - if (__gc_ == 0) - this->__set_failbit_and_consider_rethrow(); + throw; } -#endif // _LIBCPP_NO_EXCEPTIONS } - else - this->setstate(ios_base::failbit); +#endif // _LIBCPP_NO_EXCEPTIONS } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); + else + { + __state |= ios_base::failbit; + } + this->setstate(__state); } -#endif // _LIBCPP_NO_EXCEPTIONS return *this; } @@ -728,28 +749,34 @@ template<class _CharT, class _Traits> typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::get() { + ios_base::iostate __state = ios_base::goodbit; __gc_ = 0; int_type __r = traits_type::eof(); -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __s(*this, true); + if (__s) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this, true); - if (__s) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif __r = this->rdbuf()->sbumpc(); if (traits_type::eq_int_type(__r, traits_type::eof())) - this->setstate(ios_base::failbit | ios_base::eofbit); + __state |= ios_base::failbit | ios_base::eofbit; else __gc_ = 1; - } #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + this->__setstate_nothrow(this->rdstate() | ios_base::badbit); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + this->setstate(__state); } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS return __r; } @@ -757,23 +784,23 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm) { + ios_base::iostate __state = ios_base::goodbit; __gc_ = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __sen(*this, true); - if (__sen) + if (__n > 0) { - if (__n > 0) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { - ios_base::iostate __err = ios_base::goodbit; +#endif while (__gc_ < __n-1) { int_type __i = this->rdbuf()->sgetc(); if (traits_type::eq_int_type(__i, traits_type::eof())) { - __err |= ios_base::eofbit; + __state |= ios_base::eofbit; break; } char_type __ch = traits_type::to_char_type(__i); @@ -784,23 +811,33 @@ basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __ this->rdbuf()->sbumpc(); } if (__gc_ == 0) - __err |= ios_base::failbit; - this->setstate(__err); + __state |= ios_base::failbit; +#ifndef _LIBCPP_NO_EXCEPTIONS } - else - this->setstate(ios_base::failbit); + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + if (__n > 0) + *__s = char_type(); + throw; + } + } +#endif } + else + { + __state |= ios_base::failbit; + } + if (__n > 0) *__s = char_type(); -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - if (__n > 0) - *__s = char_type(); - this->__set_badbit_and_consider_rethrow(); + this->setstate(__state); } -#endif // _LIBCPP_NO_EXCEPTIONS + if (__n > 0) + *__s = char_type(); return *this; } @@ -809,52 +846,43 @@ basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm) { + ios_base::iostate __state = ios_base::goodbit; __gc_ = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __sen(*this, true); - if (__sen) - { - ios_base::iostate __err = ios_base::goodbit; #ifndef _LIBCPP_NO_EXCEPTIONS - try - { + try + { #endif // _LIBCPP_NO_EXCEPTIONS - while (true) + while (true) + { + typename traits_type::int_type __i = this->rdbuf()->sgetc(); + if (traits_type::eq_int_type(__i, traits_type::eof())) { - typename traits_type::int_type __i = this->rdbuf()->sgetc(); - if (traits_type::eq_int_type(__i, traits_type::eof())) - { - __err |= ios_base::eofbit; - break; - } - char_type __ch = traits_type::to_char_type(__i); - if (traits_type::eq(__ch, __dlm)) - break; - if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof())) - break; - ++__gc_; - this->rdbuf()->sbumpc(); + __state |= ios_base::eofbit; + break; } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { + char_type __ch = traits_type::to_char_type(__i); + if (traits_type::eq(__ch, __dlm)) + break; + if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof())) + break; + ++__gc_; + this->rdbuf()->sbumpc(); } -#endif // _LIBCPP_NO_EXCEPTIONS - if (__gc_ == 0) - __err |= ios_base::failbit; - this->setstate(__err); - } #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + // according to the spec, exceptions here are caught but not rethrown + } #endif // _LIBCPP_NO_EXCEPTIONS + if (__gc_ == 0) + __state |= ios_base::failbit; + this->setstate(__state); + } return *this; } @@ -862,21 +890,21 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm) { + ios_base::iostate __state = ios_base::goodbit; __gc_ = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { - ios_base::iostate __err = ios_base::goodbit; +#endif // _LIBCPP_NO_EXCEPTIONS while (true) { typename traits_type::int_type __i = this->rdbuf()->sgetc(); if (traits_type::eq_int_type(__i, traits_type::eof())) { - __err |= ios_base::eofbit; + __state |= ios_base::eofbit; break; } char_type __ch = traits_type::to_char_type(__i); @@ -888,28 +916,35 @@ basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_typ } if (__gc_ >= __n-1) { - __err |= ios_base::failbit; + __state |= ios_base::failbit; break; } *__s++ = __ch; this->rdbuf()->sbumpc(); ++__gc_; } - if (__gc_ == 0) - __err |= ios_base::failbit; - this->setstate(__err); - } - if (__n > 0) - *__s = char_type(); #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - if (__n > 0) - *__s = char_type(); - this->__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + if (__n > 0) + *__s = char_type(); + if (__gc_ == 0) + __state |= ios_base::failbit; + throw; + } + } #endif // _LIBCPP_NO_EXCEPTIONS + } + if (__n > 0) + *__s = char_type(); + if (__gc_ == 0) + __state |= ios_base::failbit; + this->setstate(__state); return *this; } @@ -917,15 +952,15 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) { + ios_base::iostate __state = ios_base::goodbit; __gc_ = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { - ios_base::iostate __err = ios_base::goodbit; +#endif // _LIBCPP_NO_EXCEPTIONS if (__n == numeric_limits<streamsize>::max()) { while (true) @@ -933,7 +968,7 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) typename traits_type::int_type __i = this->rdbuf()->sbumpc(); if (traits_type::eq_int_type(__i, traits_type::eof())) { - __err |= ios_base::eofbit; + __state |= ios_base::eofbit; break; } ++__gc_; @@ -948,7 +983,7 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) typename traits_type::int_type __i = this->rdbuf()->sbumpc(); if (traits_type::eq_int_type(__i, traits_type::eof())) { - __err |= ios_base::eofbit; + __state |= ios_base::eofbit; break; } ++__gc_; @@ -956,15 +991,20 @@ basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm) break; } } - this->setstate(__err); - } #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } #endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } return *this; } @@ -972,26 +1012,33 @@ template<class _CharT, class _Traits> typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>::peek() { + ios_base::iostate __state = ios_base::goodbit; __gc_ = 0; int_type __r = traits_type::eof(); -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS __r = this->rdbuf()->sgetc(); if (traits_type::eq_int_type(__r, traits_type::eof())) - this->setstate(ios_base::eofbit); - } + __state |= ios_base::eofbit; #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } #endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } return __r; } @@ -999,27 +1046,36 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n) { + ios_base::iostate __state = ios_base::goodbit; __gc_ = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS __gc_ = this->rdbuf()->sgetn(__s, __n); if (__gc_ != __n) - this->setstate(ios_base::failbit | ios_base::eofbit); - } - else - this->setstate(ios_base::failbit); + __state |= ios_base::failbit | ios_base::eofbit; #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS } - catch (...) + else { - this->__set_badbit_and_consider_rethrow(); + __state |= ios_base::failbit; } -#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); return *this; } @@ -1027,36 +1083,48 @@ template<class _CharT, class _Traits> streamsize basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n) { + ios_base::iostate __state = ios_base::goodbit; __gc_ = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS streamsize __c = this->rdbuf()->in_avail(); switch (__c) { case -1: - this->setstate(ios_base::eofbit); + __state |= ios_base::eofbit; break; case 0: break; default: - read(__s, _VSTD::min(__c, __n)); + __n = _VSTD::min(__c, __n); + __gc_ = this->rdbuf()->sgetn(__s, __n); + if (__gc_ != __n) + __state |= ios_base::failbit | ios_base::eofbit; break; } - } - else - this->setstate(ios_base::failbit); #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS } - catch (...) + else { - this->__set_badbit_and_consider_rethrow(); + __state |= ios_base::failbit; } -#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); return __gc_; } @@ -1064,27 +1132,36 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::putback(char_type __c) { + ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; __gc_ = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + this->clear(__state); + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - this->clear(this->rdstate() & ~ios_base::eofbit); - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof()) - this->setstate(ios_base::badbit); - } - else - this->setstate(ios_base::failbit); + __state |= ios_base::badbit; #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS } - catch (...) + else { - this->__set_badbit_and_consider_rethrow(); + __state |= ios_base::failbit; } -#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); return *this; } @@ -1092,27 +1169,36 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::unget() { + ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; __gc_ = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + this->clear(__state); + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - this->clear(this->rdstate() & ~ios_base::eofbit); - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof()) - this->setstate(ios_base::badbit); - } - else - this->setstate(ios_base::failbit); + __state |= ios_base::badbit; #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } +#endif // _LIBCPP_NO_EXCEPTIONS } - catch (...) + else { - this->__set_badbit_and_consider_rethrow(); + __state |= ios_base::failbit; } -#endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); return *this; } @@ -1120,29 +1206,36 @@ template<class _CharT, class _Traits> int basic_istream<_CharT, _Traits>::sync() { + ios_base::iostate __state = ios_base::goodbit; int __r = 0; -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS if (this->rdbuf() == 0) return -1; if (this->rdbuf()->pubsync() == -1) { - this->setstate(ios_base::badbit); + __state |= ios_base::badbit; return -1; } - } #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } #endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } return __r; } @@ -1150,21 +1243,30 @@ template<class _CharT, class _Traits> typename basic_istream<_CharT, _Traits>::pos_type basic_istream<_CharT, _Traits>::tellg() { + ios_base::iostate __state = ios_base::goodbit; pos_type __r(-1); -#ifndef _LIBCPP_NO_EXCEPTIONS - try + sentry __sen(*this, true); + if (__sen) { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { #endif // _LIBCPP_NO_EXCEPTIONS - sentry __sen(*this, true); - if (__sen) - __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); + __r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } #endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } return __r; } @@ -1172,24 +1274,31 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(pos_type __pos) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; + this->clear(__state); + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - this->clear(this->rdstate() & ~ios_base::eofbit); - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1)) - this->setstate(ios_base::failbit); - } + __state |= ios_base::failbit; #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } #endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } return *this; } @@ -1197,24 +1306,31 @@ template<class _CharT, class _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit; + this->clear(__state); + sentry __sen(*this, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - this->clear(this->rdstate() & ~ios_base::eofbit); - sentry __sen(*this, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1)) - this->setstate(ios_base::failbit); - } + __state |= ios_base::failbit; #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + this->__setstate_nothrow(__state); + if (this->exceptions() & ios_base::badbit) + { + throw; + } + } #endif // _LIBCPP_NO_EXCEPTIONS + this->setstate(__state); + } return *this; } @@ -1222,34 +1338,41 @@ template <class _CharT, class _Traits> basic_istream<_CharT, _Traits>& ws(basic_istream<_CharT, _Traits>& __is) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif // _LIBCPP_NO_EXCEPTIONS const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); while (true) { typename _Traits::int_type __i = __is.rdbuf()->sgetc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { - __is.setstate(ios_base::eofbit); + __state |= ios_base::eofbit; break; } if (!__ct.is(__ct.space, _Traits::to_char_type(__i))) break; __is.rdbuf()->sbumpc(); } - } #ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - __is.__set_badbit_and_consider_rethrow(); - } + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } #endif // _LIBCPP_NO_EXCEPTIONS + __is.setstate(__state); + } return __is; } @@ -1298,7 +1421,6 @@ protected: inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 void swap(basic_iostream& __rhs) { basic_istream<char_type, traits_type>::swap(__rhs); } -public: }; #ifndef _LIBCPP_CXX03_LANG @@ -1329,13 +1451,14 @@ basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_istream<_CharT, _Traits>::sentry __sen(__is); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif __str.clear(); streamsize __n = __is.width(); if (__n <= 0) @@ -1344,13 +1467,12 @@ operator>>(basic_istream<_CharT, _Traits>& __is, __n = numeric_limits<streamsize>::max(); streamsize __c = 0; const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); - ios_base::iostate __err = ios_base::goodbit; while (__c < __n) { typename _Traits::int_type __i = __is.rdbuf()->sgetc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { - __err |= ios_base::eofbit; + __state |= ios_base::eofbit; break; } _CharT __ch = _Traits::to_char_type(__i); @@ -1362,18 +1484,21 @@ operator>>(basic_istream<_CharT, _Traits>& __is, } __is.width(0); if (__c == 0) - __err |= ios_base::failbit; - __is.setstate(__err); - } - else - __is.setstate(ios_base::failbit); + __state |= ios_base::failbit; #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); } - catch (...) - { - __is.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS return __is; } @@ -1382,22 +1507,22 @@ basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif __str.clear(); - ios_base::iostate __err = ios_base::goodbit; streamsize __extr = 0; while (true) { typename _Traits::int_type __i = __is.rdbuf()->sbumpc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { - __err |= ios_base::eofbit; + __state |= ios_base::eofbit; break; } ++__extr; @@ -1407,21 +1532,26 @@ getline(basic_istream<_CharT, _Traits>& __is, __str.push_back(__ch); if (__str.size() == __str.max_size()) { - __err |= ios_base::failbit; + __state |= ios_base::failbit; break; } } if (__extr == 0) - __err |= ios_base::failbit; - __is.setstate(__err); - } + __state |= ios_base::failbit; #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); } - catch (...) - { - __is.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS return __is; } @@ -1460,17 +1590,17 @@ template <class _CharT, class _Traits, size_t _Size> basic_istream<_CharT, _Traits>& operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try + ios_base::iostate __state = ios_base::goodbit; + typename basic_istream<_CharT, _Traits>::sentry __sen(__is); + if (__sen) { -#endif // _LIBCPP_NO_EXCEPTIONS - typename basic_istream<_CharT, _Traits>::sentry __sen(__is); - if (__sen) +#ifndef _LIBCPP_NO_EXCEPTIONS + try { +#endif basic_string<_CharT, _Traits> __str; const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc()); size_t __c = 0; - ios_base::iostate __err = ios_base::goodbit; _CharT __zero = __ct.widen('0'); _CharT __one = __ct.widen('1'); while (__c < _Size) @@ -1478,7 +1608,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) typename _Traits::int_type __i = __is.rdbuf()->sgetc(); if (_Traits::eq_int_type(__i, _Traits::eof())) { - __err |= ios_base::eofbit; + __state |= ios_base::eofbit; break; } _CharT __ch = _Traits::to_char_type(__i); @@ -1490,18 +1620,21 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) } __x = bitset<_Size>(__str); if (__c == 0) - __err |= ios_base::failbit; - __is.setstate(__err); - } - else - __is.setstate(ios_base::failbit); + __state |= ios_base::failbit; #ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + __state |= ios_base::badbit; + __is.__setstate_nothrow(__state); + if (__is.exceptions() & ios_base::badbit) + { + throw; + } + } +#endif + __is.setstate(__state); } - catch (...) - { - __is.__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS return __is; } diff --git a/include/iterator b/include/iterator index bda177e11e6c..30801ea83dbd 100644 --- a/include/iterator +++ b/include/iterator @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- iterator ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -70,7 +69,7 @@ typename iterator_traits<InputIterator>::difference_type n = 1); template <class BidirectionalIterator> // constexpr in C++17 constexpr BidirectionalIterator prev(BidirectionalIterator x, - typename iterator_traits<BidirectionalIterator>::difference_type n = 1); + typename iterator_traits<BidirectionalIterator>::difference_type n = 1); template <class Iterator> class reverse_iterator @@ -137,7 +136,7 @@ operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2 template <class Iterator> constexpr reverse_iterator<Iterator> -operator+(typename reverse_iterator<Iterator>::difference_type n, +operator+(typename reverse_iterator<Iterator>::difference_type n, const reverse_iterator<Iterator>& x); // constexpr in C++17 template <class Iterator> @@ -217,7 +216,7 @@ public: typedef typename iterator_traits<Iterator>::value_type value_type; typedef typename iterator_traits<Iterator>::iterator_category iterator_category; typedef value_type&& reference; - + constexpr move_iterator(); // all the constexprs are in C++17 constexpr explicit move_iterator(Iterator i); template <class U> @@ -231,10 +230,10 @@ public: constexpr move_iterator operator++(int); constexpr move_iterator& operator--(); constexpr move_iterator operator--(int); - constexpr move_iterator operator+(difference_type n) const; - constexpr move_iterator& operator+=(difference_type n); - constexpr move_iterator operator-(difference_type n) const; - constexpr move_iterator& operator-=(difference_type n); + constexpr move_iterator operator+(difference_type n) const; + constexpr move_iterator& operator+=(difference_type n); + constexpr move_iterator operator-(difference_type n) const; + constexpr move_iterator& operator-=(difference_type n); constexpr unspecified operator[](difference_type n) const; private: Iterator current; // exposition only @@ -271,7 +270,7 @@ operator-(const move_iterator<Iterator1>& x, template <class Iterator> constexpr move_iterator<Iterator> operator+( // constexpr in C++17 - typename move_iterator<Iterator>::difference_type n, + typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x); template <class Iterator> // constexpr in C++17 @@ -400,6 +399,11 @@ template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // 24.8, container access: template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17 template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17 + +template <class C> constexpr auto ssize(const C& c) + -> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20 +template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20 + template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17 template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17 @@ -530,10 +534,26 @@ struct __is_random_access_iterator : public __has_iterator_category_convertible_ template <class _Tp> struct __is_exactly_input_iterator - : public integral_constant<bool, - __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && + : public integral_constant<bool, + __has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value && !__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {}; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator> +using __iter_value_type = typename iterator_traits<_InputIterator>::value_type; + +template<class _InputIterator> +using __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>; + +template<class _InputIterator> +using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type; + +template<class _InputIterator> +using __iter_to_alloc_type = pair< + add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>, + typename iterator_traits<_InputIterator>::value_type::second_type>; +#endif + template<class _Category, class _Tp, class _Distance = ptrdiff_t, class _Pointer = _Tp*, class _Reference = _Tp&> struct _LIBCPP_TEMPLATE_VIS iterator @@ -580,6 +600,8 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 void advance(_InputIter& __i, typename iterator_traits<_InputIter>::difference_type __n) { + _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value, + "Attempt to advance(it, -n) on a non-bidi iterator"); __advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category()); } @@ -614,26 +636,31 @@ template <class _InputIter> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 typename enable_if < - __is_input_iterator<_InputIter>::value, + __is_input_iterator<_InputIter>::value, _InputIter >::type next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) { + _LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value, + "Attempt to next(it, -n) on a non-bidi iterator"); + _VSTD::advance(__x, __n); return __x; } -template <class _BidirectionalIter> +template <class _InputIter> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 typename enable_if < - __is_bidirectional_iterator<_BidirectionalIter>::value, - _BidirectionalIter + __is_input_iterator<_InputIter>::value, + _InputIter >::type -prev(_BidirectionalIter __x, - typename iterator_traits<_BidirectionalIter>::difference_type __n = 1) +prev(_InputIter __x, + typename iterator_traits<_InputIter>::difference_type __n = 1) { + _LIBCPP_ASSERT(__n <= 0 || __is_bidirectional_iterator<_InputIter>::value, + "Attempt to prev(it, +n) on a non-bidi iterator"); _VSTD::advance(__x, -__n); return __x; } @@ -1079,10 +1106,6 @@ public: _LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;} _LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;} -#if !defined(__APPLE__) || \ - (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ - (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) - template <class _Ch, class _Tr> friend _LIBCPP_HIDDEN @@ -1090,7 +1113,6 @@ public: __pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s, const _Ch* __ob, const _Ch* __op, const _Ch* __oe, ios_base& __iob, _Ch __fl); -#endif }; template <class _Iter> @@ -1123,7 +1145,7 @@ public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference operator*() const { return static_cast<reference>(*__i); } _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 pointer operator->() const { return __i;} @@ -1237,50 +1259,50 @@ template <class _Iter> class __wrap_iter; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; +operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; +operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; +operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; +operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; +operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; +operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; #ifndef _LIBCPP_CXX03_LANG template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG auto -operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT -> decltype(__x.base() - __y.base()); #else template <class _Iter1, class _Iter2> _LIBCPP_INLINE_VISIBILITY typename __wrap_iter<_Iter1>::difference_type -operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; +operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; #endif template <class _Iter> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter<_Iter> -operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT_DEBUG; +operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT; template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op); template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2); @@ -1324,7 +1346,7 @@ public: private: iterator_type __i; public: - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT #if _LIBCPP_STD_VER > 11 : __i{} #endif @@ -1335,7 +1357,7 @@ public: } template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const __wrap_iter<_Up>& __u, - typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT_DEBUG + typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT : __i(__u.base()) { #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1365,7 +1387,7 @@ public: __get_db()->__erase_i(this); } #endif - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), @@ -1373,7 +1395,7 @@ public: #endif return *__i; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), @@ -1381,7 +1403,7 @@ public: #endif return (pointer)_VSTD::addressof(*__i); } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), @@ -1390,10 +1412,10 @@ public: ++__i; return *this; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT {__wrap_iter __tmp(*this); ++(*this); return __tmp;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), @@ -1402,11 +1424,11 @@ public: --__i; return *this; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT {__wrap_iter __tmp(*this); --(*this); return __tmp;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT {__wrap_iter __w(*this); __w += __n; return __w;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__addable(this, __n), @@ -1415,11 +1437,11 @@ public: __i += __n; return *this; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT {return *this + (-__n);} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT {*this += -__n; return *this;} - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT_DEBUG + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n), @@ -1428,7 +1450,7 @@ public: return __i[__n]; } - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT_DEBUG {return __i;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;} private: #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1437,61 +1459,61 @@ private: __get_db()->__insert_ic(this, __p); } #else - _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT_DEBUG : __i(__x) {} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {} #endif template <class _Up> friend class __wrap_iter; template <class _CharT, class _Traits, class _Alloc> friend class basic_string; template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector; - template <class _Tp, ptrdiff_t> friend class _LIBCPP_TEMPLATE_VIS span; + template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span; template <class _Iter1, class _Iter2> _LIBCPP_CONSTEXPR_IF_NODEBUG friend bool - operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; + operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_CONSTEXPR_IF_NODEBUG friend bool - operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; + operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_CONSTEXPR_IF_NODEBUG friend bool - operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; + operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_CONSTEXPR_IF_NODEBUG friend bool - operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; + operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_CONSTEXPR_IF_NODEBUG friend bool - operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; + operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; template <class _Iter1, class _Iter2> _LIBCPP_CONSTEXPR_IF_NODEBUG friend bool - operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; + operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; #ifndef _LIBCPP_CXX03_LANG template <class _Iter1, class _Iter2> _LIBCPP_CONSTEXPR_IF_NODEBUG friend auto - operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG + operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT -> decltype(__x.base() - __y.base()); #else template <class _Iter1, class _Iter2> _LIBCPP_CONSTEXPR_IF_NODEBUG friend typename __wrap_iter<_Iter1>::difference_type - operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT_DEBUG; + operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT; #endif template <class _Iter1> _LIBCPP_CONSTEXPR_IF_NODEBUG friend __wrap_iter<_Iter1> - operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT_DEBUG; + operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT; template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op); template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2); @@ -1522,7 +1544,7 @@ private: template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG +operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { return __x.base() == __y.base(); } @@ -1530,7 +1552,7 @@ operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG +operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), @@ -1542,7 +1564,7 @@ operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXC template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG +operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { return !(__x == __y); } @@ -1550,7 +1572,7 @@ operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG +operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { return __y < __x; } @@ -1558,7 +1580,7 @@ operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXC template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG +operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { return !(__x < __y); } @@ -1566,7 +1588,7 @@ operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG +operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { return !(__y < __x); } @@ -1574,7 +1596,7 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEX template <class _Iter1> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG +operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { return !(__x == __y); } @@ -1582,7 +1604,7 @@ operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEX template <class _Iter1> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG +operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { return __y < __x; } @@ -1590,7 +1612,7 @@ operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXC template <class _Iter1> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG +operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { return !(__x < __y); } @@ -1598,7 +1620,7 @@ operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEX template <class _Iter1> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG bool -operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT_DEBUG +operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT { return !(__y < __x); } @@ -1607,7 +1629,7 @@ operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEX template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG auto -operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT -> decltype(__x.base() - __y.base()) { #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1620,7 +1642,7 @@ operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXC template <class _Iter1, class _Iter2> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG typename __wrap_iter<_Iter1>::difference_type -operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT_DEBUG +operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y), @@ -1634,7 +1656,7 @@ template <class _Iter> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter<_Iter> operator+(typename __wrap_iter<_Iter>::difference_type __n, - __wrap_iter<_Iter> __x) _NOEXCEPT_DEBUG + __wrap_iter<_Iter> __x) _NOEXCEPT { __x += __n; return __x; @@ -1643,7 +1665,7 @@ operator+(typename __wrap_iter<_Iter>::difference_type __n, template <class _Iter> struct __libcpp_is_trivial_iterator : public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {}; - + template <class _Iter> struct __libcpp_is_trivial_iterator<move_iterator<_Iter> > : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {}; @@ -1658,7 +1680,7 @@ struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > template <class _Tp, size_t _Np> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp* begin(_Tp (&__array)[_Np]) { @@ -1666,7 +1688,7 @@ begin(_Tp (&__array)[_Np]) } template <class _Tp, size_t _Np> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp* end(_Tp (&__array)[_Np]) { @@ -1676,7 +1698,7 @@ end(_Tp (&__array)[_Np]) #if !defined(_LIBCPP_CXX03_LANG) template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto begin(_Cp& __c) -> decltype(__c.begin()) { @@ -1684,7 +1706,7 @@ begin(_Cp& __c) -> decltype(__c.begin()) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto begin(const _Cp& __c) -> decltype(__c.begin()) { @@ -1692,7 +1714,7 @@ begin(const _Cp& __c) -> decltype(__c.begin()) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto end(_Cp& __c) -> decltype(__c.end()) { @@ -1700,7 +1722,7 @@ end(_Cp& __c) -> decltype(__c.end()) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto end(const _Cp& __c) -> decltype(__c.end()) { @@ -1710,84 +1732,84 @@ end(const _Cp& __c) -> decltype(__c.end()) #if _LIBCPP_STD_VER > 11 template <class _Tp, size_t _Np> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array + _Np); } template <class _Tp, size_t _Np> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np]) { return reverse_iterator<_Tp*>(__array); } template <class _Ep> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il) { return reverse_iterator<const _Ep*>(__il.end()); } template <class _Ep> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il) { return reverse_iterator<const _Ep*>(__il.begin()); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c)) { return _VSTD::begin(__c); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c)) { return _VSTD::end(__c); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rbegin(_Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rbegin(const _Cp& __c) -> decltype(__c.rbegin()) { return __c.rbegin(); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rend(_Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto rend(const _Cp& __c) -> decltype(__c.rend()) { return __c.rend(); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c)) { return _VSTD::rbegin(__c); } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) { return _VSTD::rend(__c); @@ -1799,7 +1821,7 @@ auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c)) #else // defined(_LIBCPP_CXX03_LANG) template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename _Cp::iterator begin(_Cp& __c) { @@ -1807,7 +1829,7 @@ begin(_Cp& __c) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename _Cp::const_iterator begin(const _Cp& __c) { @@ -1815,7 +1837,7 @@ begin(const _Cp& __c) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename _Cp::iterator end(_Cp& __c) { @@ -1823,7 +1845,7 @@ end(_Cp& __c) } template <class _Cp> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY typename _Cp::const_iterator end(const _Cp& __c) { @@ -1849,51 +1871,64 @@ end(const _Cp& __c) // #endif template <class _Cont> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY constexpr auto size(const _Cont& __c) _NOEXCEPT_(noexcept(__c.size())) -> decltype (__c.size()) { return __c.size(); } template <class _Tp, size_t _Sz> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; } +#if _LIBCPP_STD_VER > 17 template <class _Cont> -_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY +constexpr auto ssize(const _Cont& __c) +_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()))) +-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>> +{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); } + +template <class _Tp, ptrdiff_t _Sz> +_LIBCPP_INLINE_VISIBILITY +constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; } +#endif + +template <class _Cont> +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY constexpr auto empty(const _Cont& __c) _NOEXCEPT_(noexcept(__c.empty())) -> decltype (__c.empty()) { return __c.empty(); } template <class _Tp, size_t _Sz> -_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; } template <class _Ep> -_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; } template <class _Cont> constexpr -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY auto data(_Cont& __c) _NOEXCEPT_(noexcept(__c.data())) -> decltype (__c.data()) { return __c.data(); } template <class _Cont> constexpr -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY auto data(const _Cont& __c) _NOEXCEPT_(noexcept(__c.data())) --> decltype (__c.data()) +-> decltype (__c.data()) { return __c.data(); } template <class _Tp, size_t _Sz> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; } template <class _Ep> -inline _LIBCPP_INLINE_VISIBILITY +_LIBCPP_INLINE_VISIBILITY constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); } #endif diff --git a/include/limits b/include/limits index 5ea9a9e6fdfa..6d5d1e1aca75 100644 --- a/include/limits +++ b/include/limits @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- limits ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -410,7 +409,7 @@ protected: static _LIBCPP_CONSTEXPR const bool is_exact = false; static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __LDBL_EPSILON__;} - _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return 0.5;} + _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return 0.5L;} static _LIBCPP_CONSTEXPR const int min_exponent = __LDBL_MIN_EXP__; static _LIBCPP_CONSTEXPR const int min_exponent10 = __LDBL_MIN_10_EXP__; diff --git a/include/limits.h b/include/limits.h index 1867b1048574..4a212f8f35a8 100644 --- a/include/limits.h +++ b/include/limits.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- limits.h ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/list b/include/list index c69e31d93a44..c92ef79282ed 100644 --- a/include/list +++ b/include/list @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- list ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -130,11 +129,12 @@ public: void splice(const_iterator position, list&& x, const_iterator first, const_iterator last); - void remove(const value_type& value); - template <class Pred> void remove_if(Pred pred); - void unique(); + size_type remove(const value_type& value); // void before C++20 + template <class Pred> + size_type remove_if(Pred pred); // void before C++20 + size_type unique(); // void before C++20 template <class BinaryPredicate> - void unique(BinaryPredicate binary_pred); + size_type unique(BinaryPredicate binary_pred); // void before C++20 void merge(list& x); void merge(list&& x); template <class Compare> @@ -648,9 +648,9 @@ protected: void swap(__list_imp& __c) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT_DEBUG; + _NOEXCEPT; #else - _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); #endif @@ -770,9 +770,9 @@ template <class _Tp, class _Alloc> void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT_DEBUG + _NOEXCEPT #else - _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) #endif { @@ -858,6 +858,11 @@ public: typedef typename base::const_iterator const_iterator; typedef _VSTD::reverse_iterator<iterator> reverse_iterator; typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; +#if _LIBCPP_STD_VER > 17 + typedef size_type __remove_return_type; +#else + typedef void __remove_return_type; +#endif _LIBCPP_INLINE_VISIBILITY list() @@ -1039,9 +1044,9 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(list& __c) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT_DEBUG + _NOEXCEPT #else - _NOEXCEPT_DEBUG_(!__node_alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) #endif {base::swap(__c);} @@ -1071,12 +1076,12 @@ public: void splice(const_iterator __p, list& __c, const_iterator __i); void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); - void remove(const value_type& __x); - template <class _Pred> void remove_if(_Pred __pred); + __remove_return_type remove(const value_type& __x); + template <class _Pred> __remove_return_type remove_if(_Pred __pred); _LIBCPP_INLINE_VISIBILITY - void unique(); + __remove_return_type unique() { return unique(__equal_to<value_type>()); } template <class _BinaryPred> - void unique(_BinaryPred __binary_pred); + __remove_return_type unique(_BinaryPred __binary_pred); _LIBCPP_INLINE_VISIBILITY void merge(list& __c); #ifndef _LIBCPP_CXX03_LANG @@ -2014,22 +2019,24 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) base::__sz() += __c.__sz(); __c.__sz() = 0; #if _LIBCPP_DEBUG_LEVEL >= 2 - __libcpp_db* __db = __get_db(); - __c_node* __cn1 = __db->__find_c_and_lock(this); - __c_node* __cn2 = __db->__find_c(&__c); - for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) - { - --__ip; - iterator* __i = static_cast<iterator*>((*__ip)->__i_); - if (__i->__ptr_ != __c.__end_as_link()) + if (&__c != this) { + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { - __cn1->__add(*__ip); - (*__ip)->__c_ = __cn1; - if (--__cn2->end_ != __ip) - memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); + --__ip; + iterator* __i = static_cast<iterator*>((*__ip)->__i_); + if (__i->__ptr_ != __c.__end_as_link()) + { + __cn1->__add(*__ip); + (*__ip)->__c_ = __cn1; + if (--__cn2->end_ != __ip) + memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); + } } + __db->unlock(); } - __db->unlock(); #endif } } @@ -2057,22 +2064,24 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) --__c.__sz(); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 - __libcpp_db* __db = __get_db(); - __c_node* __cn1 = __db->__find_c_and_lock(this); - __c_node* __cn2 = __db->__find_c(&__c); - for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) - { - --__ip; - iterator* __j = static_cast<iterator*>((*__ip)->__i_); - if (__j->__ptr_ == __f) + if (&__c != this) { + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { - __cn1->__add(*__ip); - (*__ip)->__c_ = __cn1; - if (--__cn2->end_ != __ip) - memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); + --__ip; + iterator* __j = static_cast<iterator*>((*__ip)->__i_); + if (__j->__ptr_ == __f) + { + __cn1->__add(*__ip); + (*__ip)->__c_ = __cn1; + if (--__cn2->end_ != __ip) + memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); + } } + __db->unlock(); } - __db->unlock(); #endif } } @@ -2111,32 +2120,34 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con base::__unlink_nodes(__first, __last); __link_nodes(__p.__ptr_, __first, __last); #if _LIBCPP_DEBUG_LEVEL >= 2 - __libcpp_db* __db = __get_db(); - __c_node* __cn1 = __db->__find_c_and_lock(this); - __c_node* __cn2 = __db->__find_c(&__c); - for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) - { - --__ip; - iterator* __j = static_cast<iterator*>((*__ip)->__i_); - for (__link_pointer __k = __f.__ptr_; - __k != __l.__ptr_; __k = __k->__next_) + if (&__c != this) { + __libcpp_db* __db = __get_db(); + __c_node* __cn1 = __db->__find_c_and_lock(this); + __c_node* __cn2 = __db->__find_c(&__c); + for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { - if (__j->__ptr_ == __k) + --__ip; + iterator* __j = static_cast<iterator*>((*__ip)->__i_); + for (__link_pointer __k = __f.__ptr_; + __k != __l.__ptr_; __k = __k->__next_) { - __cn1->__add(*__ip); - (*__ip)->__c_ = __cn1; - if (--__cn2->end_ != __ip) - memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); + if (__j->__ptr_ == __k) + { + __cn1->__add(*__ip); + (*__ip)->__c_ = __cn1; + if (--__cn2->end_ != __ip) + memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*)); + } } } + __db->unlock(); } - __db->unlock(); #endif } } template <class _Tp, class _Alloc> -void +typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove(const value_type& __x) { list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing @@ -2155,13 +2166,16 @@ list<_Tp, _Alloc>::remove(const value_type& __x) else ++__i; } + + return (__remove_return_type) __deleted_nodes.size(); } template <class _Tp, class _Alloc> template <class _Pred> -void +typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove_if(_Pred __pred) { + list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing for (iterator __i = begin(), __e = end(); __i != __e;) { if (__pred(*__i)) @@ -2169,36 +2183,36 @@ list<_Tp, _Alloc>::remove_if(_Pred __pred) iterator __j = _VSTD::next(__i); for (; __j != __e && __pred(*__j); ++__j) ; - __i = erase(__i, __j); + __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j); + __i = __j; if (__i != __e) ++__i; } else ++__i; } -} -template <class _Tp, class _Alloc> -inline -void -list<_Tp, _Alloc>::unique() -{ - unique(__equal_to<value_type>()); + return (__remove_return_type) __deleted_nodes.size(); } template <class _Tp, class _Alloc> template <class _BinaryPred> -void +typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) { + list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing for (iterator __i = begin(), __e = end(); __i != __e;) { iterator __j = _VSTD::next(__i); for (; __j != __e && __binary_pred(*__i, *__j); ++__j) ; - if (++__i != __j) - __i = erase(__i, __j); + if (++__i != __j) { + __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j); + __i = __j; + } } + + return (__remove_return_type) __deleted_nodes.size(); } template <class _Tp, class _Alloc> diff --git a/include/locale b/include/locale index 2043892fa2dc..3fe44300227a 100644 --- a/include/locale +++ b/include/locale @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- locale ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -127,7 +126,7 @@ public: wbuffer_convert(const wbuffer_convert&) = delete; // C++14 wbuffer_convert & operator=(const wbuffer_convert &) = delete; // C++14 ~wbuffer_convert(); // C++14 - + streambuf* rdbuf() const; streambuf* rdbuf(streambuf* bytebuf); @@ -547,7 +546,7 @@ __num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __ex __exp = 'P'; else if ((__x & 0x5F) == __exp) { - __exp |= 0x80; + __exp |= (char) 0x80; if (__in_units) { __in_units = false; @@ -1373,10 +1372,6 @@ __pad_and_output(_OutputIterator __s, return __s; } -#if !defined(__APPLE__) || \ - (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_8) || \ - (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_6_0) - template <class _CharT, class _Traits> _LIBCPP_HIDDEN ostreambuf_iterator<_CharT, _Traits> @@ -1423,8 +1418,6 @@ __pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s, return __s; } -#endif - template <class _CharT, class _OutputIterator> _OutputIterator num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob, @@ -3930,7 +3923,7 @@ private: wbuffer_convert(const wbuffer_convert&); wbuffer_convert& operator=(const wbuffer_convert&); public: - _LIBCPP_EXPLICIT_AFTER_CXX11 wbuffer_convert(streambuf* __bytebuf = 0, + _LIBCPP_EXPLICIT_AFTER_CXX11 wbuffer_convert(streambuf* __bytebuf = 0, _Codecvt* __pcvt = new _Codecvt, state_type __state = state_type()); ~wbuffer_convert(); @@ -4045,7 +4038,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow() this->egptr(), __inext); if (__r == codecvt_base::noconv) { - this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, + this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*) const_cast<char *>(__extbufend_)); __c = *this->gptr(); } diff --git a/include/locale.h b/include/locale.h index cad7b8b53eb1..a21ee385c331 100644 --- a/include/locale.h +++ b/include/locale.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- locale.h --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/map b/include/map index 616bb46cfccd..eb6ae57b011f 100644 --- a/include/map +++ b/include/map @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------- map ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -194,8 +193,8 @@ public: const_iterator find(const K& x) const; // C++14 template<typename K> size_type count(const K& x) const; // C++14 - size_type count(const key_type& k) const; + bool contains(const key_type& x) const; // C++20 iterator lower_bound(const key_type& k); const_iterator lower_bound(const key_type& k) const; template<typename K> @@ -408,8 +407,8 @@ public: const_iterator find(const K& x) const; // C++14 template<typename K> size_type count(const K& x) const; // C++14 - size_type count(const key_type& k) const; + bool contains(const key_type& x) const; // C++20 iterator lower_bound(const key_type& k); const_iterator lower_bound(const key_type& k) const; template<typename K> @@ -903,12 +902,11 @@ public: typedef _Key key_type; typedef _Tp mapped_type; typedef pair<const key_type, mapped_type> value_type; - typedef _Compare key_compare; - typedef _Allocator allocator_type; + typedef typename __identity<_Compare>::type key_compare; + typedef typename __identity<_Allocator>::type allocator_type; typedef value_type& reference; typedef const value_type& const_reference; - static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); static_assert((is_same<typename allocator_type::value_type, value_type>::value), "Allocator::value_type must be same type as value_type"); @@ -1087,6 +1085,11 @@ public: } _LIBCPP_INLINE_VISIBILITY + ~map() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __tree_.begin();} @@ -1395,6 +1398,12 @@ public: typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type count(const _K2& __k) const {return __tree_.__count_multi(__k);} #endif + +#if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const {return find(__k) != end();} +#endif // _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) {return __tree_.lower_bound(__k);} @@ -1462,6 +1471,32 @@ private: #endif }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>, + class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, + class = enable_if_t<!__is_allocator<_Compare>::value, void>, + class = enable_if_t<__is_allocator<_Allocator>::value, void>> +map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) + -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>; + +template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>, + class _Allocator = allocator<pair<const _Key, _Tp>>, + class = enable_if_t<!__is_allocator<_Compare>::value, void>, + class = enable_if_t<__is_allocator<_Allocator>::value, void>> +map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator()) + -> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = enable_if_t<__is_allocator<_Allocator>::value, void>> +map(_InputIterator, _InputIterator, _Allocator) + -> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + less<__iter_key_type<_InputIterator>>, _Allocator>; + +template<class _Key, class _Tp, class _Allocator, + class = enable_if_t<__is_allocator<_Allocator>::value, void>> +map(initializer_list<pair<_Key, _Tp>>, _Allocator) + -> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>; +#endif #ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Tp, class _Compare, class _Allocator> @@ -1536,10 +1571,8 @@ map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) { __parent_pointer __parent; __node_base_pointer& __child = __tree_.__find_equal(__parent, __k); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) - throw out_of_range("map::at: key not found"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_out_of_range("map::at: key not found"); return static_cast<__node_pointer>(__child)->__value_.__get_value().second; } @@ -1549,10 +1582,8 @@ map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const { __parent_pointer __parent; __node_base_pointer __child = __tree_.__find_equal(__parent, __k); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__child == nullptr) - throw out_of_range("map::at: key not found"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_out_of_range("map::at: key not found"); return static_cast<__node_pointer>(__child)->__value_.__get_value().second; } @@ -1638,12 +1669,11 @@ public: typedef _Key key_type; typedef _Tp mapped_type; typedef pair<const key_type, mapped_type> value_type; - typedef _Compare key_compare; - typedef _Allocator allocator_type; + typedef typename __identity<_Compare>::type key_compare; + typedef typename __identity<_Allocator>::type allocator_type; typedef value_type& reference; typedef const value_type& const_reference; - static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); static_assert((is_same<typename allocator_type::value_type, value_type>::value), "Allocator::value_type must be same type as value_type"); @@ -1823,6 +1853,11 @@ public: } _LIBCPP_INLINE_VISIBILITY + ~multimap() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __tree_.begin();} @@ -2026,6 +2061,12 @@ public: typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type count(const _K2& __k) const {return __tree_.__count_multi(__k);} #endif + +#if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const {return find(__k) != end();} +#endif // _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) {return __tree_.lower_bound(__k);} @@ -2087,6 +2128,33 @@ private: typedef unique_ptr<__node, _Dp> __node_holder; }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>, + class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, + class = enable_if_t<!__is_allocator<_Compare>::value, void>, + class = enable_if_t<__is_allocator<_Allocator>::value, void>> +multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) + -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>; + +template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>, + class _Allocator = allocator<pair<const _Key, _Tp>>, + class = enable_if_t<!__is_allocator<_Compare>::value, void>, + class = enable_if_t<__is_allocator<_Allocator>::value, void>> +multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator()) + -> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = enable_if_t<__is_allocator<_Allocator>::value, void>> +multimap(_InputIterator, _InputIterator, _Allocator) + -> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + less<__iter_key_type<_InputIterator>>, _Allocator>; + +template<class _Key, class _Tp, class _Allocator, + class = enable_if_t<__is_allocator<_Allocator>::value, void>> +multimap(initializer_list<pair<_Key, _Tp>>, _Allocator) + -> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>; +#endif + #ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Tp, class _Compare, class _Allocator> multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a) diff --git a/include/math.h b/include/math.h index 3cc72aa2791e..194df2077bb1 100644 --- a/include/math.h +++ b/include/math.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- math.h ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -298,6 +297,9 @@ long double truncl(long double x); #pragma GCC system_header #endif +#define _LIBCPP_STDLIB_INCLUDE_NEXT +#include <stdlib.h> + #include_next <math.h> #ifdef __cplusplus @@ -755,20 +757,61 @@ isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT // abs +#undef abs +#undef labs +#ifndef _LIBCPP_HAS_NO_LONG_LONG +#undef llabs +#endif + +// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined +#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) +inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT { + return ::labs(__x); +} +#ifndef _LIBCPP_HAS_NO_LONG_LONG +inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT { + return ::llabs(__x); +} +#endif // _LIBCPP_HAS_NO_LONG_LONG +#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) + + #if !(defined(_AIX) || defined(__sun__)) -inline _LIBCPP_INLINE_VISIBILITY -float -abs(float __lcpp_x) _NOEXCEPT {return ::fabsf(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT { + return ::fabsf(__lcpp_x); +} -inline _LIBCPP_INLINE_VISIBILITY -double -abs(double __lcpp_x) _NOEXCEPT {return ::fabs(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY double abs(double __lcpp_x) _NOEXCEPT { + return ::fabs(__lcpp_x); +} -inline _LIBCPP_INLINE_VISIBILITY -long double -abs(long double __lcpp_x) _NOEXCEPT {return ::fabsl(__lcpp_x);} +inline _LIBCPP_INLINE_VISIBILITY long double +abs(long double __lcpp_x) _NOEXCEPT { + return ::fabsl(__lcpp_x); +} #endif // !(defined(_AIX) || defined(__sun__)) +// div + +#undef div +#undef ldiv +#ifndef _LIBCPP_HAS_NO_LONG_LONG +#undef lldiv +#endif + +// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined +#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) +inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT { + return ::ldiv(__x, __y); +} +#ifndef _LIBCPP_HAS_NO_LONG_LONG +inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, + long long __y) _NOEXCEPT { + return ::lldiv(__x, __y); +} +#endif // _LIBCPP_HAS_NO_LONG_LONG +#endif // _LIBCPP_MSVCRT / __sun__ / _AIX + // acos #if !(defined(_AIX) || defined(__sun__)) @@ -814,7 +857,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long do template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -823,8 +866,8 @@ typename std::__lazy_enable_if atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::atan2((__result_type)__lcpp_y, (__result_type)__lcpp_x); } @@ -909,7 +952,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long dou template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -918,8 +961,8 @@ typename std::__lazy_enable_if fmod(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::fmod((__result_type)__lcpp_x, (__result_type)__lcpp_y); } @@ -987,7 +1030,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long doub template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -996,8 +1039,8 @@ typename std::__lazy_enable_if pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::pow((__result_type)__lcpp_x, (__result_type)__lcpp_y); } @@ -1114,7 +1157,7 @@ copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT { template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -1123,8 +1166,8 @@ typename std::__lazy_enable_if copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y); } @@ -1175,7 +1218,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long dou template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -1184,8 +1227,8 @@ typename std::__lazy_enable_if fdim(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::fdim((__result_type)__lcpp_x, (__result_type)__lcpp_y); } @@ -1196,7 +1239,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long doub template <class _A1, class _A2, class _A3> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value && @@ -1206,9 +1249,9 @@ typename std::__lazy_enable_if fma(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT { typedef typename std::__promote<_A1, _A2, _A3>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value && - std::is_same<_A3, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value && + std::_IsSame<_A3, __result_type>::value)), ""); return ::fma((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); } @@ -1219,7 +1262,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long dou template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -1228,8 +1271,8 @@ typename std::__lazy_enable_if fmax(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::fmax((__result_type)__lcpp_x, (__result_type)__lcpp_y); } @@ -1240,7 +1283,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long dou template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -1249,8 +1292,8 @@ typename std::__lazy_enable_if fmin(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::fmin((__result_type)__lcpp_x, (__result_type)__lcpp_y); } @@ -1261,7 +1304,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long do template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -1270,8 +1313,8 @@ typename std::__lazy_enable_if hypot(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y); } @@ -1384,7 +1427,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, lon template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -1393,8 +1436,8 @@ typename std::__lazy_enable_if nextafter(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::nextafter((__result_type)__lcpp_x, (__result_type)__lcpp_y); } @@ -1415,7 +1458,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, lon template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -1424,8 +1467,8 @@ typename std::__lazy_enable_if remainder(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::remainder((__result_type)__lcpp_x, (__result_type)__lcpp_y); } @@ -1436,7 +1479,7 @@ inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long d template <class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename std::__lazy_enable_if +typename std::_EnableIf < std::is_arithmetic<_A1>::value && std::is_arithmetic<_A2>::value, @@ -1445,8 +1488,8 @@ typename std::__lazy_enable_if remquo(_A1 __lcpp_x, _A2 __lcpp_y, int* __lcpp_z) _NOEXCEPT { typedef typename std::__promote<_A1, _A2>::type __result_type; - static_assert((!(std::is_same<_A1, __result_type>::value && - std::is_same<_A2, __result_type>::value)), ""); + static_assert((!(std::_IsSame<_A1, __result_type>::value && + std::_IsSame<_A2, __result_type>::value)), ""); return ::remquo((__result_type)__lcpp_x, (__result_type)__lcpp_y, __lcpp_z); } diff --git a/include/memory b/include/memory index ce2c35766233..d9222b3ada7e 100644 --- a/include/memory +++ b/include/memory @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- memory ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -549,7 +548,7 @@ template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept; template<class T> struct owner_less; template<class T> -struct owner_less<shared_ptr<T>> +struct owner_less<shared_ptr<T> > : binary_function<shared_ptr<T>, shared_ptr<T>, bool> { typedef bool result_type; @@ -559,7 +558,7 @@ struct owner_less<shared_ptr<T>> }; template<class T> -struct owner_less<weak_ptr<T>> +struct owner_less<weak_ptr<T> > : binary_function<weak_ptr<T>, weak_ptr<T>, bool> { typedef bool result_type; @@ -684,7 +683,7 @@ inline _LIBCPP_INLINE_VISIBILITY _ValueType __libcpp_relaxed_load(_ValueType const* __value) { #if !defined(_LIBCPP_HAS_NO_THREADS) && \ defined(__ATOMIC_RELAXED) && \ - (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) + (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) return __atomic_load_n(__value, __ATOMIC_RELAXED); #else return *__value; @@ -696,7 +695,7 @@ inline _LIBCPP_INLINE_VISIBILITY _ValueType __libcpp_acquire_load(_ValueType const* __value) { #if !defined(_LIBCPP_HAS_NO_THREADS) && \ defined(__ATOMIC_ACQUIRE) && \ - (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) + (__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC)) return __atomic_load_n(__value, __ATOMIC_ACQUIRE); #else return *__value; @@ -744,7 +743,7 @@ struct __pointer_traits_element_type; template <class _Ptr> struct __pointer_traits_element_type<_Ptr, true> { - typedef typename _Ptr::element_type type; + typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type; }; #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -752,13 +751,13 @@ struct __pointer_traits_element_type<_Ptr, true> template <template <class, class...> class _Sp, class _Tp, class ..._Args> struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true> { - typedef typename _Sp<_Tp, _Args...>::element_type type; + typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type; }; template <template <class, class...> class _Sp, class _Tp, class ..._Args> struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false> { - typedef _Tp type; + typedef _LIBCPP_NODEBUG_TYPE _Tp type; }; #else // _LIBCPP_HAS_NO_VARIADICS @@ -825,13 +824,13 @@ struct __has_difference_type<_Tp, template <class _Ptr, bool = __has_difference_type<_Ptr>::value> struct __pointer_traits_difference_type { - typedef ptrdiff_t type; + typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type; }; template <class _Ptr> struct __pointer_traits_difference_type<_Ptr, true> { - typedef typename _Ptr::difference_type type; + typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type; }; template <class _Tp, class _Up> @@ -849,9 +848,9 @@ template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> struct __pointer_traits_rebind { #ifndef _LIBCPP_CXX03_LANG - typedef typename _Tp::template rebind<_Up> type; + typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type; #else - typedef typename _Tp::template rebind<_Up>::other type; + typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type; #endif }; @@ -861,9 +860,9 @@ template <template <class, class...> class _Sp, class _Tp, class ..._Args, class struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true> { #ifndef _LIBCPP_CXX03_LANG - typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type; + typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type; #else - typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; + typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type; #endif }; @@ -1014,13 +1013,13 @@ namespace __pointer_type_imp template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value> struct __pointer_type { - typedef typename _Dp::pointer type; + typedef _LIBCPP_NODEBUG_TYPE typename _Dp::pointer type; }; template <class _Tp, class _Dp> struct __pointer_type<_Tp, _Dp, false> { - typedef _Tp* type; + typedef _LIBCPP_NODEBUG_TYPE _Tp* type; }; } // __pointer_type_imp @@ -1028,7 +1027,7 @@ struct __pointer_type<_Tp, _Dp, false> template <class _Tp, class _Dp> struct __pointer_type { - typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type; }; template <class _Tp, class = void> @@ -1041,14 +1040,14 @@ struct __has_const_pointer<_Tp, template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value> struct __const_pointer { - typedef typename _Alloc::const_pointer type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_pointer type; }; template <class _Tp, class _Ptr, class _Alloc> struct __const_pointer<_Tp, _Ptr, _Alloc, false> { #ifndef _LIBCPP_CXX03_LANG - typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type; + typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const _Tp> type; #else typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type; #endif @@ -1064,16 +1063,16 @@ struct __has_void_pointer<_Tp, template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value> struct __void_pointer { - typedef typename _Alloc::void_pointer type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::void_pointer type; }; template <class _Ptr, class _Alloc> struct __void_pointer<_Ptr, _Alloc, false> { #ifndef _LIBCPP_CXX03_LANG - typedef typename pointer_traits<_Ptr>::template rebind<void> type; + typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void> type; #else - typedef typename pointer_traits<_Ptr>::template rebind<void>::other type; + typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void>::other type; #endif }; @@ -1087,16 +1086,16 @@ struct __has_const_void_pointer<_Tp, template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value> struct __const_void_pointer { - typedef typename _Alloc::const_void_pointer type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_void_pointer type; }; template <class _Ptr, class _Alloc> struct __const_void_pointer<_Ptr, _Alloc, false> { #ifndef _LIBCPP_CXX03_LANG - typedef typename pointer_traits<_Ptr>::template rebind<const void> type; + typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void> type; #else - typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type; + typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void>::other type; #endif }; @@ -1162,13 +1161,13 @@ struct __has_size_type<_Tp, template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value> struct __size_type { - typedef typename make_unsigned<_DiffType>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename make_unsigned<_DiffType>::type type; }; template <class _Alloc, class _DiffType> struct __size_type<_Alloc, _DiffType, true> { - typedef typename _Alloc::size_type type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::size_type type; }; template <class _Tp, class = void> @@ -1182,13 +1181,13 @@ struct __has_propagate_on_container_copy_assignment<_Tp, template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value> struct __propagate_on_container_copy_assignment { - typedef false_type type; + typedef _LIBCPP_NODEBUG_TYPE false_type type; }; template <class _Alloc> struct __propagate_on_container_copy_assignment<_Alloc, true> { - typedef typename _Alloc::propagate_on_container_copy_assignment type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_copy_assignment type; }; template <class _Tp, class = void> @@ -1208,7 +1207,7 @@ struct __propagate_on_container_move_assignment template <class _Alloc> struct __propagate_on_container_move_assignment<_Alloc, true> { - typedef typename _Alloc::propagate_on_container_move_assignment type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_move_assignment type; }; template <class _Tp, class = void> @@ -1228,7 +1227,7 @@ struct __propagate_on_container_swap template <class _Alloc> struct __propagate_on_container_swap<_Alloc, true> { - typedef typename _Alloc::propagate_on_container_swap type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_swap type; }; template <class _Tp, class = void> @@ -1242,13 +1241,13 @@ struct __has_is_always_equal<_Tp, template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value> struct __is_always_equal { - typedef typename _VSTD::is_empty<_Alloc>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename _VSTD::is_empty<_Alloc>::type type; }; template <class _Alloc> struct __is_always_equal<_Alloc, true> { - typedef typename _Alloc::is_always_equal type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::is_always_equal type; }; template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> @@ -1271,7 +1270,7 @@ struct __has_rebind_other<_Tp, _Up, false> template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value> struct __allocator_traits_rebind { - typedef typename _Tp::template rebind<_Up>::other type; + typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type; }; #ifndef _LIBCPP_HAS_NO_VARIADICS @@ -1279,13 +1278,13 @@ struct __allocator_traits_rebind template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> { - typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type; }; template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up> struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false> { - typedef _Alloc<_Up, _Args...> type; + typedef _LIBCPP_NODEBUG_TYPE _Alloc<_Up, _Args...> type; }; #else // _LIBCPP_HAS_NO_VARIADICS @@ -1493,13 +1492,13 @@ struct __has_select_on_container_copy_construction template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value> struct __alloc_traits_difference_type { - typedef typename pointer_traits<_Ptr>::difference_type type; + typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::difference_type type; }; template <class _Alloc, class _Ptr> struct __alloc_traits_difference_type<_Alloc, _Ptr, true> { - typedef typename _Alloc::difference_type type; + typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::difference_type type; }; template <class _Tp> @@ -1534,7 +1533,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits #ifndef _LIBCPP_CXX03_LANG template <class _Tp> using rebind_alloc = typename __allocator_traits_rebind<allocator_type, _Tp>::type; - template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>; + template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp> >; #else // _LIBCPP_CXX03_LANG template <class _Tp> struct rebind_alloc {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;}; @@ -1769,7 +1768,7 @@ template <class _Traits, class _Tp> struct __rebind_alloc_helper { #ifndef _LIBCPP_CXX03_LANG - typedef typename _Traits::template rebind_alloc<_Tp> type; + typedef _LIBCPP_NODEBUG_TYPE typename _Traits::template rebind_alloc<_Tp> type; #else typedef typename _Traits::template rebind_alloc<_Tp>::other type; #endif @@ -2210,8 +2209,8 @@ struct __second_tag {}; template <class _T1, class _T2> class __compressed_pair : private __compressed_pair_elem<_T1, 0>, private __compressed_pair_elem<_T2, 1> { - typedef __compressed_pair_elem<_T1, 0> _Base1; - typedef __compressed_pair_elem<_T2, 1> _Base2; + typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1; + typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2; // NOTE: This static assert should never fire because __compressed_pair // is *almost never* used in a scenario where it's possible for T1 == T2. @@ -2321,7 +2320,7 @@ struct _LIBCPP_TEMPLATE_VIS default_delete { static_assert(!is_function<_Tp>::value, "default_delete cannot be instantiated for function types"); #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; + _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; #else _LIBCPP_INLINE_VISIBILITY default_delete() {} #endif @@ -2349,7 +2348,7 @@ private: public: #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_INLINE_VISIBILITY constexpr default_delete() noexcept = default; + _LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default; #else _LIBCPP_INLINE_VISIBILITY default_delete() {} #endif @@ -2371,9 +2370,6 @@ public: } }; - - -#ifndef _LIBCPP_CXX03_LANG template <class _Deleter> struct __unique_ptr_deleter_sfinae { static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); @@ -2395,14 +2391,13 @@ struct __unique_ptr_deleter_sfinae<_Deleter&> { typedef _Deleter&& __bad_rval_ref_type; typedef false_type __enable_rval_overload; }; -#endif // !defined(_LIBCPP_CXX03_LANG) template <class _Tp, class _Dp = default_delete<_Tp> > class _LIBCPP_TEMPLATE_VIS unique_ptr { public: typedef _Tp element_type; typedef _Dp deleter_type; - typedef typename __pointer_type<_Tp, deleter_type>::type pointer; + typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type<_Tp, deleter_type>::type pointer; static_assert(!is_rvalue_reference<deleter_type>::value, "the specified deleter type cannot be an rvalue reference"); @@ -2412,39 +2407,38 @@ private: struct __nat { int __for_bool_; }; -#ifndef _LIBCPP_CXX03_LANG - typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; + typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; template <bool _Dummy> - using _LValRefType = + using _LValRefType _LIBCPP_NODEBUG_TYPE = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; template <bool _Dummy> - using _GoodRValRefType = + using _GoodRValRefType _LIBCPP_NODEBUG_TYPE = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; template <bool _Dummy> - using _BadRValRefType = + using _BadRValRefType _LIBCPP_NODEBUG_TYPE = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; template <bool _Dummy, class _Deleter = typename __dependent_type< __identity<deleter_type>, _Dummy>::type> - using _EnableIfDeleterDefaultConstructible = + using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE = typename enable_if<is_default_constructible<_Deleter>::value && !is_pointer<_Deleter>::value>::type; template <class _ArgType> - using _EnableIfDeleterConstructible = + using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE = typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; template <class _UPtr, class _Up> - using _EnableIfMoveConvertible = typename enable_if< + using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< is_convertible<typename _UPtr::pointer, pointer>::value && !is_array<_Up>::value >::type; template <class _UDel> - using _EnableIfDeleterConvertible = typename enable_if< + using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) >::type; @@ -2456,42 +2450,42 @@ private: public: template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy>> + class = _EnableIfDeleterDefaultConstructible<_Dummy> > _LIBCPP_INLINE_VISIBILITY - constexpr unique_ptr() noexcept : __ptr_(pointer()) {} + _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {} template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy>> + class = _EnableIfDeleterDefaultConstructible<_Dummy> > _LIBCPP_INLINE_VISIBILITY - constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} + _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {} template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy>> + class = _EnableIfDeleterDefaultConstructible<_Dummy> > _LIBCPP_INLINE_VISIBILITY - explicit unique_ptr(pointer __p) noexcept : __ptr_(__p) {} + explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p) {} template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > _LIBCPP_INLINE_VISIBILITY - unique_ptr(pointer __p, _LValRefType<_Dummy> __d) noexcept + unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(__p, __d) {} template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > _LIBCPP_INLINE_VISIBILITY - unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) noexcept + unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(__p, _VSTD::move(__d)) { static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); } template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>> + class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > > _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; _LIBCPP_INLINE_VISIBILITY - unique_ptr(unique_ptr&& __u) noexcept + unique_ptr(unique_ptr&& __u) _NOEXCEPT : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { } @@ -2508,7 +2502,7 @@ public: _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p, typename enable_if<is_convertible<_Up*, _Tp*>::value && - is_same<_Dp, default_delete<_Tp>>::value, + is_same<_Dp, default_delete<_Tp> >::value, __nat>::type = __nat()) _NOEXCEPT : __ptr_(__p.release()) {} #endif @@ -2531,65 +2525,6 @@ public: return *this; } -#else // _LIBCPP_CXX03_LANG -private: - unique_ptr(unique_ptr&); - template <class _Up, class _Ep> unique_ptr(unique_ptr<_Up, _Ep>&); - - unique_ptr& operator=(unique_ptr&); - template <class _Up, class _Ep> unique_ptr& operator=(unique_ptr<_Up, _Ep>&); - -public: - _LIBCPP_INLINE_VISIBILITY - unique_ptr() : __ptr_(pointer()) - { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - static_assert(is_default_constructible<deleter_type>::value, - "unique_ptr::deleter_type is not default constructible"); - } - _LIBCPP_INLINE_VISIBILITY - unique_ptr(nullptr_t) : __ptr_(pointer()) - { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - _LIBCPP_INLINE_VISIBILITY - explicit unique_ptr(pointer __p) - : __ptr_(_VSTD::move(__p)) { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - - _LIBCPP_INLINE_VISIBILITY - operator __rv<unique_ptr>() { - return __rv<unique_ptr>(*this); - } - - _LIBCPP_INLINE_VISIBILITY - unique_ptr(__rv<unique_ptr> __u) - : __ptr_(__u->release(), - _VSTD::forward<deleter_type>(__u->get_deleter())) {} - - template <class _Up, class _Ep> - _LIBCPP_INLINE_VISIBILITY - typename enable_if< - !is_array<_Up>::value && - is_convertible<typename unique_ptr<_Up, _Ep>::pointer, - pointer>::value && - is_assignable<deleter_type&, _Ep&>::value, - unique_ptr&>::type - operator=(unique_ptr<_Up, _Ep> __u) { - reset(__u.release()); - __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); - return *this; - } - - _LIBCPP_INLINE_VISIBILITY - unique_ptr(pointer __p, deleter_type __d) - : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {} -#endif // _LIBCPP_CXX03_LANG - #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) template <class _Up> _LIBCPP_INLINE_VISIBILITY @@ -2602,6 +2537,12 @@ public: } #endif +#ifdef _LIBCPP_CXX03_LANG + unique_ptr(unique_ptr const&) = delete; + unique_ptr& operator=(unique_ptr const&) = delete; +#endif + + _LIBCPP_INLINE_VISIBILITY ~unique_ptr() { reset(); } @@ -2681,39 +2622,38 @@ private: > {}; -#ifndef _LIBCPP_CXX03_LANG typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; template <bool _Dummy> - using _LValRefType = + using _LValRefType _LIBCPP_NODEBUG_TYPE = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; template <bool _Dummy> - using _GoodRValRefType = + using _GoodRValRefType _LIBCPP_NODEBUG_TYPE = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; template <bool _Dummy> - using _BadRValRefType = + using _BadRValRefType _LIBCPP_NODEBUG_TYPE = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; template <bool _Dummy, class _Deleter = typename __dependent_type< __identity<deleter_type>, _Dummy>::type> - using _EnableIfDeleterDefaultConstructible = + using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE = typename enable_if<is_default_constructible<_Deleter>::value && !is_pointer<_Deleter>::value>::type; template <class _ArgType> - using _EnableIfDeleterConstructible = + using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE = typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; template <class _Pp> - using _EnableIfPointerConvertible = typename enable_if< + using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< _CheckArrayPointerConversion<_Pp>::value >::type; template <class _UPtr, class _Up, class _ElemT = typename _UPtr::element_type> - using _EnableIfMoveConvertible = typename enable_if< + using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< is_array<_Up>::value && is_same<pointer, element_type*>::value && is_same<typename _UPtr::pointer, _ElemT*>::value && @@ -2721,79 +2661,79 @@ private: >::type; template <class _UDel> - using _EnableIfDeleterConvertible = typename enable_if< + using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if< (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) >::type; template <class _UDel> - using _EnableIfDeleterAssignable = typename enable_if< + using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE = typename enable_if< is_assignable<_Dp&, _UDel&&>::value >::type; public: template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy>> + class = _EnableIfDeleterDefaultConstructible<_Dummy> > _LIBCPP_INLINE_VISIBILITY - constexpr unique_ptr() noexcept : __ptr_(pointer()) {} + _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {} template <bool _Dummy = true, - class = _EnableIfDeleterDefaultConstructible<_Dummy>> + class = _EnableIfDeleterDefaultConstructible<_Dummy> > _LIBCPP_INLINE_VISIBILITY - constexpr unique_ptr(nullptr_t) noexcept : __ptr_(pointer()) {} + _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {} template <class _Pp, bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy>, - class = _EnableIfPointerConvertible<_Pp>> + class = _EnableIfPointerConvertible<_Pp> > _LIBCPP_INLINE_VISIBILITY - explicit unique_ptr(_Pp __p) noexcept + explicit unique_ptr(_Pp __p) _NOEXCEPT : __ptr_(__p) {} template <class _Pp, bool _Dummy = true, - class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>, - class = _EnableIfPointerConvertible<_Pp>> + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >, + class = _EnableIfPointerConvertible<_Pp> > _LIBCPP_INLINE_VISIBILITY - unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) noexcept + unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(__p, __d) {} template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_LValRefType<_Dummy>>> + class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > _LIBCPP_INLINE_VISIBILITY - unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) noexcept + unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(nullptr, __d) {} template <class _Pp, bool _Dummy = true, - class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>, - class = _EnableIfPointerConvertible<_Pp>> + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >, + class = _EnableIfPointerConvertible<_Pp> > _LIBCPP_INLINE_VISIBILITY - unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) noexcept + unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(__p, _VSTD::move(__d)) { static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); } template <bool _Dummy = true, - class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy>>> + class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > _LIBCPP_INLINE_VISIBILITY - unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) noexcept + unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT : __ptr_(nullptr, _VSTD::move(__d)) { static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference"); } template <class _Pp, bool _Dummy = true, - class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy>>, - class = _EnableIfPointerConvertible<_Pp>> + class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >, + class = _EnableIfPointerConvertible<_Pp> > _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; _LIBCPP_INLINE_VISIBILITY - unique_ptr(unique_ptr&& __u) noexcept + unique_ptr(unique_ptr&& __u) _NOEXCEPT : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) { } _LIBCPP_INLINE_VISIBILITY - unique_ptr& operator=(unique_ptr&& __u) noexcept { + unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT { reset(__u.release()); __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter()); return *this; @@ -2804,7 +2744,7 @@ public: class = _EnableIfDeleterConvertible<_Ep> > _LIBCPP_INLINE_VISIBILITY - unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept + unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) { } @@ -2814,73 +2754,16 @@ public: > _LIBCPP_INLINE_VISIBILITY unique_ptr& - operator=(unique_ptr<_Up, _Ep>&& __u) noexcept { + operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT { reset(__u.release()); __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter()); return *this; } -#else // _LIBCPP_CXX03_LANG -private: - template <class _Up> explicit unique_ptr(_Up); - - unique_ptr(unique_ptr&); - template <class _Up> unique_ptr(unique_ptr<_Up>&); - - unique_ptr& operator=(unique_ptr&); - template <class _Up> unique_ptr& operator=(unique_ptr<_Up>&); - - template <class _Up> - unique_ptr(_Up __u, - typename conditional< - is_reference<deleter_type>::value, deleter_type, - typename add_lvalue_reference<const deleter_type>::type>::type, - typename enable_if<is_convertible<_Up, pointer>::value, - __nat>::type = __nat()); -public: - _LIBCPP_INLINE_VISIBILITY - unique_ptr() : __ptr_(pointer()) { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - _LIBCPP_INLINE_VISIBILITY - unique_ptr(nullptr_t) : __ptr_(pointer()) { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - - _LIBCPP_INLINE_VISIBILITY - explicit unique_ptr(pointer __p) : __ptr_(__p) { - static_assert(!is_pointer<deleter_type>::value, - "unique_ptr constructed with null function pointer deleter"); - } - - _LIBCPP_INLINE_VISIBILITY - unique_ptr(pointer __p, deleter_type __d) - : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {} - - _LIBCPP_INLINE_VISIBILITY - unique_ptr(nullptr_t, deleter_type __d) - : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {} - - _LIBCPP_INLINE_VISIBILITY - operator __rv<unique_ptr>() { - return __rv<unique_ptr>(*this); - } - - _LIBCPP_INLINE_VISIBILITY - unique_ptr(__rv<unique_ptr> __u) - : __ptr_(__u->release(), - _VSTD::forward<deleter_type>(__u->get_deleter())) {} - - _LIBCPP_INLINE_VISIBILITY - unique_ptr& operator=(__rv<unique_ptr> __u) { - reset(__u->release()); - __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter()); - return *this; - } - -#endif // _LIBCPP_CXX03_LANG +#ifdef _LIBCPP_CXX03_LANG + unique_ptr(unique_ptr const&) = delete; + unique_ptr& operator=(unique_ptr const&) = delete; +#endif public: _LIBCPP_INLINE_VISIBILITY @@ -3092,18 +2975,6 @@ operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) return !(nullptr < __x); } -#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES - -template <class _Tp, class _Dp> -inline _LIBCPP_INLINE_VISIBILITY -unique_ptr<_Tp, _Dp> -move(unique_ptr<_Tp, _Dp>& __t) -{ - return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t)); -} - -#endif - #if _LIBCPP_STD_VER > 11 template<class _Tp> @@ -3152,7 +3023,7 @@ template <class _Tp, class _Dp> struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> > #else struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< - unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer>> + unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> > #endif { typedef unique_ptr<_Tp, _Dp> argument_type; @@ -3207,10 +3078,10 @@ public: template <class _Alloc> class __allocator_destructor { - typedef allocator_traits<_Alloc> __alloc_traits; + typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits; public: - typedef typename __alloc_traits::pointer pointer; - typedef typename __alloc_traits::size_type size_type; + typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer; + typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type; private: _Alloc& __alloc_; size_type __s_; @@ -3467,7 +3338,7 @@ uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) { && defined(__ATOMIC_RELAXED) \ && defined(__ATOMIC_ACQ_REL) # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT -#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407 +#elif defined(_LIBCPP_COMPILER_GCC) # define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT #endif @@ -5669,6 +5540,52 @@ struct __is_allocator<_Alloc, > : true_type {}; +// __builtin_new_allocator -- A non-templated helper for allocating and +// deallocating memory using __builtin_operator_new and +// __builtin_operator_delete. It should be used in preference to +// `std::allocator<T>` to avoid additional instantiations. +struct __builtin_new_allocator { + struct __builtin_new_deleter { + typedef void* pointer_type; + + _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align) + : __size_(__size), __align_(__align) {} + + void operator()(void* p) const _NOEXCEPT { + std::__libcpp_deallocate(p, __size_, __align_); + } + + private: + size_t __size_; + size_t __align_; + }; + + typedef unique_ptr<void, __builtin_new_deleter> __holder_t; + + static __holder_t __allocate_bytes(size_t __s, size_t __align) { + return __holder_t(std::__libcpp_allocate(__s, __align), + __builtin_new_deleter(__s, __align)); + } + + static void __deallocate_bytes(void* __p, size_t __s, + size_t __align) _NOEXCEPT { + std::__libcpp_deallocate(__p, __s, __align); + } + + template <class _Tp> + _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE + static __holder_t __allocate_type(size_t __n) { + return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + } + + template <class _Tp> + _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE + static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT { + __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); + } +}; + + _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/include/module.modulemap b/include/module.modulemap index 6d88f52113cb..bbfe90ed57f5 100644 --- a/include/module.modulemap +++ b/include/module.modulemap @@ -24,7 +24,10 @@ module std [system] { header "errno.h" export * } - // <fenv.h> provided by C library. + module fenv_h { + header "fenv.h" + export * + } // <float.h> provided by compiler or C library. module inttypes_h { header "inttypes.h" diff --git a/include/mutex b/include/mutex index 6d2de2b460e2..20c3ffc38b63 100644 --- a/include/mutex +++ b/include/mutex @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- mutex ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -189,6 +188,7 @@ template<class Callable, class ...Args> #include <__config> #include <__mutex_base> +#include <cstdint> #include <functional> #include <memory> #ifndef _LIBCPP_CXX03_LANG @@ -576,11 +576,18 @@ struct _LIBCPP_TEMPLATE_VIS once_flag _LIBCPP_CONSTEXPR once_flag() _NOEXCEPT : __state_(0) {} +#if defined(_LIBCPP_ABI_MICROSOFT) + typedef uintptr_t _State_type; +#else + typedef unsigned long _State_type; +#endif + + private: once_flag(const once_flag&); // = delete; once_flag& operator=(const once_flag&); // = delete; - unsigned long __state_; + _State_type __state_; #ifndef _LIBCPP_CXX03_LANG template<class _Callable, class... _Args> @@ -650,7 +657,8 @@ __call_once_proxy(void* __vp) (*__p)(); } -_LIBCPP_FUNC_VIS void __call_once(volatile unsigned long&, void*, void(*)(void*)); +_LIBCPP_FUNC_VIS void __call_once(volatile once_flag::_State_type&, void*, + void (*)(void*)); #ifndef _LIBCPP_CXX03_LANG @@ -659,7 +667,7 @@ inline _LIBCPP_INLINE_VISIBILITY void call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args) { - if (__libcpp_acquire_load(&__flag.__state_) != ~0ul) + if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) { typedef tuple<_Callable&&, _Args&&...> _Gp; _Gp __f(_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...); @@ -675,7 +683,7 @@ inline _LIBCPP_INLINE_VISIBILITY void call_once(once_flag& __flag, _Callable& __func) { - if (__libcpp_acquire_load(&__flag.__state_) != ~0ul) + if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) { __call_once_param<_Callable> __p(__func); __call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>); @@ -687,7 +695,7 @@ inline _LIBCPP_INLINE_VISIBILITY void call_once(once_flag& __flag, const _Callable& __func) { - if (__libcpp_acquire_load(&__flag.__state_) != ~0ul) + if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0)) { __call_once_param<const _Callable> __p(__func); __call_once(__flag.__state_, &__p, &__call_once_proxy<const _Callable>); diff --git a/include/new b/include/new index 24ffcad5a6bc..85e4c4b3fcf2 100644 --- a/include/new +++ b/include/new @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------- new ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -34,6 +33,12 @@ public: }; enum class align_val_t : size_t {}; // C++17 + +struct destroying_delete_t { // C++20 + explicit destroying_delete_t() = default; +}; +inline constexpr destroying_delete_t destroying_delete{}; // C++20 + struct nothrow_t {}; extern const nothrow_t nothrow; typedef void (*new_handler)(); @@ -90,7 +95,7 @@ void operator delete[](void* ptr, void*) noexcept; #include <cstdlib> #endif -#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +#if defined(_LIBCPP_ABI_VCRUNTIME) #include <new.h> #endif @@ -120,7 +125,7 @@ void operator delete[](void* ptr, void*) noexcept; namespace std // purposefully not using versioning namespace { -#if !defined(_LIBCPP_ABI_MICROSOFT) || defined(_LIBCPP_NO_VCRUNTIME) +#if !defined(_LIBCPP_ABI_VCRUNTIME) struct _LIBCPP_TYPE_VIS nothrow_t {}; extern _LIBCPP_FUNC_VIS const nothrow_t nothrow; @@ -146,12 +151,12 @@ typedef void (*new_handler)(); _LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT; _LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT; -#endif // !_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME +#endif // !_LIBCPP_ABI_VCRUNTIME _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec #if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) && \ - !defined(_LIBCPP_DEFER_NEW_TO_VCRUNTIME) + !defined(_LIBCPP_ABI_VCRUNTIME) #ifndef _LIBCPP_CXX03_LANG enum class _LIBCPP_ENUM_VIS align_val_t : size_t { }; #else @@ -159,6 +164,15 @@ enum align_val_t { __zero = 0, __max = (size_t)-1 }; #endif #endif +#if _LIBCPP_STD_VER > 17 +// Enable the declaration even if the compiler doesn't support the language +// feature. +struct destroying_delete_t { + explicit destroying_delete_t() = default; +}; +_LIBCPP_INLINE_VAR constexpr destroying_delete_t destroying_delete{}; +#endif // _LIBCPP_STD_VER > 17 + } // std #if defined(_LIBCPP_CXX03_LANG) @@ -167,10 +181,10 @@ enum align_val_t { __zero = 0, __max = (size_t)-1 }; #define _THROW_BAD_ALLOC #endif -#if !defined(_LIBCPP_DEFER_NEW_TO_VCRUNTIME) +#if !defined(_LIBCPP_ABI_VCRUNTIME) _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC; -_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION @@ -178,7 +192,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operato #endif _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC; -_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION @@ -187,7 +201,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operato #ifndef _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; -_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION @@ -195,7 +209,7 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operato #endif _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC; -_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS; +_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT; _LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION @@ -208,7 +222,7 @@ _LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator ne inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {} inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {} -#endif // !_LIBCPP_DEFER_NEW_TO_VCRUNTIME +#endif // !_LIBCPP_ABI_VCRUNTIME _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/include/numeric b/include/numeric index 4e68239d059e..2118704d57f3 100644 --- a/include/numeric +++ b/include/numeric @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- numeric ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -134,6 +133,10 @@ template <class M, class N> template <class M, class N> constexpr common_type_t<M,N> lcm(M m, N n); // C++17 +integer midpoint(integer a, integer b); // C++20 +pointer midpoint(pointer a, pointer b); // C++20 +floating_point midpoint(floating_point a, floating_point b); // C++20 + } // std */ @@ -142,6 +145,7 @@ template <class M, class N> #include <iterator> #include <limits> // for numeric_limits #include <functional> +#include <cmath> // for isnormal #include <version> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -456,10 +460,10 @@ iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_) #if _LIBCPP_STD_VER > 14 -template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __abs; +template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __ct_abs; template <typename _Result, typename _Source> -struct __abs<_Result, _Source, true> { +struct __ct_abs<_Result, _Source, true> { _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY _Result operator()(_Source __t) const noexcept { @@ -470,7 +474,7 @@ struct __abs<_Result, _Source, true> { }; template <typename _Result, typename _Source> -struct __abs<_Result, _Source, false> { +struct __ct_abs<_Result, _Source, false> { _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY _Result operator()(_Source __t) const noexcept { return __t; } }; @@ -496,8 +500,8 @@ gcd(_Tp __m, _Up __n) using _Rp = common_type_t<_Tp,_Up>; using _Wp = make_unsigned_t<_Rp>; return static_cast<_Rp>(_VSTD::__gcd( - static_cast<_Wp>(__abs<_Rp, _Tp>()(__m)), - static_cast<_Wp>(__abs<_Rp, _Up>()(__n)))); + static_cast<_Wp>(__ct_abs<_Rp, _Tp>()(__m)), + static_cast<_Wp>(__ct_abs<_Rp, _Up>()(__n)))); } template<class _Tp, class _Up> @@ -512,14 +516,72 @@ lcm(_Tp __m, _Up __n) return 0; using _Rp = common_type_t<_Tp,_Up>; - _Rp __val1 = __abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n); - _Rp __val2 = __abs<_Rp, _Up>()(__n); + _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n); + _Rp __val2 = __ct_abs<_Rp, _Up>()(__n); _LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm"); return __val1 * __val2; } #endif /* _LIBCPP_STD_VER > 14 */ +#if _LIBCPP_STD_VER > 17 +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp> +midpoint(_Tp __a, _Tp __b) noexcept +_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ + using _Up = std::make_unsigned_t<_Tp>; + + int __sign = 1; + _Up __m = __a; + _Up __M = __b; + if (__a > __b) + { + __sign = -1; + __m = __b; + __M = __a; + } + return __a + __sign * _Tp(_Up(__M-__m) >> 1); +} + + +template <class _TPtr> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<is_pointer_v<_TPtr> + && is_object_v<remove_pointer_t<_TPtr>> + && ! is_void_v<remove_pointer_t<_TPtr>> + && (sizeof(remove_pointer_t<_TPtr>) > 0), _TPtr> +midpoint(_TPtr __a, _TPtr __b) noexcept +{ + return __a + _VSTD::midpoint(ptrdiff_t(0), __b - __a); +} + + +template <typename _Tp> +constexpr int __sign(_Tp __val) { + return (_Tp(0) < __val) - (__val < _Tp(0)); +} + +template <typename _Fp> +constexpr _Fp __fp_abs(_Fp __f) { return __f >= 0 ? __f : -__f; } + +template <class _Fp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<is_floating_point_v<_Fp>, _Fp> +midpoint(_Fp __a, _Fp __b) noexcept +{ + constexpr _Fp __lo = numeric_limits<_Fp>::min()*2; + constexpr _Fp __hi = numeric_limits<_Fp>::max()/2; + return __fp_abs(__a) <= __hi && __fp_abs(__b) <= __hi ? // typical case: overflow is impossible + (__a + __b)/2 : // always correctly rounded + __fp_abs(__a) < __lo ? __a + __b/2 : // not safe to halve a + __fp_abs(__a) < __lo ? __a/2 + __b : // not safe to halve b + __a/2 + __b/2; // otherwise correctly rounded +} + +#endif // _LIBCPP_STD_VER > 17 + _LIBCPP_END_NAMESPACE_STD _LIBCPP_POP_MACROS diff --git a/include/optional b/include/optional index 70422068e285..a147d69da00f 100644 --- a/include/optional +++ b/include/optional @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- optional ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -593,7 +592,7 @@ public: private: // Disable the reference extension using this static assert. - static_assert(!is_same_v<value_type, in_place_t>, + static_assert(!is_same_v<__uncvref_t<value_type>, in_place_t>, "instantiation of optional with in_place_t is ill-formed"); static_assert(!is_same_v<__uncvref_t<value_type>, nullopt_t>, "instantiation of optional with nullopt_t is ill-formed"); @@ -601,6 +600,8 @@ private: "instantiation of optional with a reference type is ill-formed"); static_assert(is_destructible_v<value_type>, "instantiation of optional with a non-destructible type is ill-formed"); + static_assert(!is_array_v<value_type>, + "instantiation of optional with an array type is ill-formed"); // LWG2756: conditionally explicit conversion from _Up struct _CheckOptionalArgsConstructor { @@ -617,16 +618,16 @@ private: } }; template <class _Up> - using _CheckOptionalArgsCtor = conditional_t< - !is_same_v<__uncvref_t<_Up>, in_place_t> && - !is_same_v<__uncvref_t<_Up>, optional>, + using _CheckOptionalArgsCtor = _If< + _IsNotSame<__uncvref_t<_Up>, in_place_t>::value && + _IsNotSame<__uncvref_t<_Up>, optional>::value, _CheckOptionalArgsConstructor, __check_tuple_constructor_fail >; template <class _QualUp> struct _CheckOptionalLikeConstructor { template <class _Up, class _Opt = optional<_Up>> - using __check_constructible_from_opt = __lazy_or< + using __check_constructible_from_opt = _Or< is_constructible<_Tp, _Opt&>, is_constructible<_Tp, _Opt const&>, is_constructible<_Tp, _Opt&&>, @@ -637,7 +638,7 @@ private: is_convertible<_Opt const&&, _Tp> >; template <class _Up, class _Opt = optional<_Up>> - using __check_assignable_from_opt = __lazy_or< + using __check_assignable_from_opt = _Or< is_assignable<_Tp&, _Opt&>, is_assignable<_Tp&, _Opt const&>, is_assignable<_Tp&, _Opt&&>, @@ -663,18 +664,18 @@ private: }; template <class _Up, class _QualUp> - using _CheckOptionalLikeCtor = conditional_t< - __lazy_and< - __lazy_not<is_same<_Up, _Tp>>, + using _CheckOptionalLikeCtor = _If< + _And< + _IsNotSame<_Up, _Tp>, is_constructible<_Tp, _QualUp> >::value, _CheckOptionalLikeConstructor<_QualUp>, __check_tuple_constructor_fail >; template <class _Up, class _QualUp> - using _CheckOptionalLikeAssign = conditional_t< - __lazy_and< - __lazy_not<is_same<_Up, _Tp>>, + using _CheckOptionalLikeAssign = _If< + _And< + _IsNotSame<_Up, _Tp>, is_constructible<_Tp, _QualUp>, is_assignable<_Tp&, _QualUp> >::value, @@ -688,28 +689,32 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr optional(optional&&) = default; _LIBCPP_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {} - template <class... _Args, class = enable_if_t< - is_constructible_v<value_type, _Args...>> + template <class _InPlaceT, class... _Args, class = _EnableIf< + _And< + _IsSame<_InPlaceT, in_place_t>, + is_constructible<value_type, _Args...> + >::value + > > _LIBCPP_INLINE_VISIBILITY - constexpr explicit optional(in_place_t, _Args&&... __args) + constexpr explicit optional(_InPlaceT, _Args&&... __args) : __base(in_place, _VSTD::forward<_Args>(__args)...) {} - template <class _Up, class... _Args, class = enable_if_t< + template <class _Up, class... _Args, class = _EnableIf< is_constructible_v<value_type, initializer_list<_Up>&, _Args...>> > _LIBCPP_INLINE_VISIBILITY constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args) : __base(in_place, __il, _VSTD::forward<_Args>(__args)...) {} - template <class _Up = value_type, enable_if_t< + template <class _Up = value_type, _EnableIf< _CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY constexpr optional(_Up&& __v) : __base(in_place, _VSTD::forward<_Up>(__v)) {} - template <class _Up, enable_if_t< + template <class _Up, _EnableIf< _CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY @@ -717,7 +722,7 @@ public: : __base(in_place, _VSTD::forward<_Up>(__v)) {} // LWG2756: conditionally explicit conversion from const optional<_Up>& - template <class _Up, enable_if_t< + template <class _Up, _EnableIf< _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_implicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY @@ -725,7 +730,7 @@ public: { this->__construct_from(__v); } - template <class _Up, enable_if_t< + template <class _Up, _EnableIf< _CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_explicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY @@ -735,7 +740,7 @@ public: } // LWG2756: conditionally explicit conversion from optional<_Up>&& - template <class _Up, enable_if_t< + template <class _Up, _EnableIf< _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_implicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY @@ -743,7 +748,7 @@ public: { this->__construct_from(_VSTD::move(__v)); } - template <class _Up, enable_if_t< + template <class _Up, _EnableIf< _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_explicit<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY @@ -764,11 +769,12 @@ public: // LWG2756 template <class _Up = value_type, - class = enable_if_t - <__lazy_and< - integral_constant<bool, - !is_same_v<__uncvref_t<_Up>, optional> && - !(is_same_v<_Up, value_type> && is_scalar_v<value_type>) + class = _EnableIf< + _And< + _IsNotSame<__uncvref_t<_Up>, optional>, + _Or< + _IsNotSame<__uncvref_t<_Up>, value_type>, + _Not<is_scalar<value_type>> >, is_constructible<value_type, _Up>, is_assignable<value_type&, _Up> @@ -786,7 +792,7 @@ public: } // LWG2756 - template <class _Up, enable_if_t< + template <class _Up, _EnableIf< _CheckOptionalLikeAssign<_Up, _Up const&>::template __enable_assign<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY @@ -798,7 +804,7 @@ public: } // LWG2756 - template <class _Up, enable_if_t< + template <class _Up, _EnableIf< _CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_assign<_Up>() , int> = 0> _LIBCPP_INLINE_VISIBILITY @@ -810,7 +816,7 @@ public: } template <class... _Args, - class = enable_if_t + class = _EnableIf < is_constructible_v<value_type, _Args...> > @@ -825,7 +831,7 @@ public: } template <class _Up, class... _Args, - class = enable_if_t + class = _EnableIf < is_constructible_v<value_type, initializer_list<_Up>&, _Args...> > @@ -1021,7 +1027,7 @@ template<class T> // Comparisons between optionals template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() == _VSTD::declval<const _Up&>()), bool>, bool @@ -1037,7 +1043,7 @@ operator==(const optional<_Tp>& __x, const optional<_Up>& __y) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() != _VSTD::declval<const _Up&>()), bool>, bool @@ -1053,7 +1059,7 @@ operator!=(const optional<_Tp>& __x, const optional<_Up>& __y) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() < _VSTD::declval<const _Up&>()), bool>, bool @@ -1069,7 +1075,7 @@ operator<(const optional<_Tp>& __x, const optional<_Up>& __y) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() > _VSTD::declval<const _Up&>()), bool>, bool @@ -1085,7 +1091,7 @@ operator>(const optional<_Tp>& __x, const optional<_Up>& __y) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <= _VSTD::declval<const _Up&>()), bool>, bool @@ -1101,7 +1107,7 @@ operator<=(const optional<_Tp>& __x, const optional<_Up>& __y) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >= _VSTD::declval<const _Up&>()), bool>, bool @@ -1215,7 +1221,7 @@ operator>=(nullopt_t, const optional<_Tp>& __x) noexcept // Comparisons with T template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() == _VSTD::declval<const _Up&>()), bool>, bool @@ -1227,7 +1233,7 @@ operator==(const optional<_Tp>& __x, const _Up& __v) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() == _VSTD::declval<const _Up&>()), bool>, bool @@ -1239,7 +1245,7 @@ operator==(const _Tp& __v, const optional<_Up>& __x) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() != _VSTD::declval<const _Up&>()), bool>, bool @@ -1251,7 +1257,7 @@ operator!=(const optional<_Tp>& __x, const _Up& __v) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() != _VSTD::declval<const _Up&>()), bool>, bool @@ -1263,7 +1269,7 @@ operator!=(const _Tp& __v, const optional<_Up>& __x) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() < _VSTD::declval<const _Up&>()), bool>, bool @@ -1275,7 +1281,7 @@ operator<(const optional<_Tp>& __x, const _Up& __v) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() < _VSTD::declval<const _Up&>()), bool>, bool @@ -1287,7 +1293,7 @@ operator<(const _Tp& __v, const optional<_Up>& __x) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <= _VSTD::declval<const _Up&>()), bool>, bool @@ -1299,7 +1305,7 @@ operator<=(const optional<_Tp>& __x, const _Up& __v) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <= _VSTD::declval<const _Up&>()), bool>, bool @@ -1311,7 +1317,7 @@ operator<=(const _Tp& __v, const optional<_Up>& __x) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() > _VSTD::declval<const _Up&>()), bool>, bool @@ -1323,7 +1329,7 @@ operator>(const optional<_Tp>& __x, const _Up& __v) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() > _VSTD::declval<const _Up&>()), bool>, bool @@ -1335,7 +1341,7 @@ operator>(const _Tp& __v, const optional<_Up>& __x) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >= _VSTD::declval<const _Up&>()), bool>, bool @@ -1347,7 +1353,7 @@ operator>=(const optional<_Tp>& __x, const _Up& __v) template <class _Tp, class _Up> _LIBCPP_INLINE_VISIBILITY constexpr -enable_if_t< +_EnableIf< is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >= _VSTD::declval<const _Up&>()), bool>, bool @@ -1360,7 +1366,7 @@ operator>=(const _Tp& __v, const optional<_Up>& __x) template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY -enable_if_t< +_EnableIf< is_move_constructible_v<_Tp> && is_swappable_v<_Tp>, void > diff --git a/include/ostream b/include/ostream index d700a369b34a..e6cf9c970f72 100644 --- a/include/ostream +++ b/include/ostream @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- ostream -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -57,6 +56,7 @@ public: basic_ostream& operator<<(long double f); basic_ostream& operator<<(const void* p); basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb); + basic_ostream& operator<<(nullptr_t); // 27.7.2.7 Unformatted output: basic_ostream& put(char_type c); @@ -219,6 +219,10 @@ public: basic_ostream& operator<<(const void* __p); basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb); + _LIBCPP_INLINE_VISIBILITY + basic_ostream& operator<<(nullptr_t) + { return *this << "nullptr"; } + // 27.7.2.7 Unformatted output: basic_ostream& put(char_type __c); basic_ostream& write(const char_type* __s, streamsize __n); diff --git a/include/queue b/include/queue index 4677e52ae3a7..97ec6f633c51 100644 --- a/include/queue +++ b/include/queue @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- queue ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -71,8 +70,8 @@ public: template<class Container> queue(Container) -> queue<typename Container::value_type, Container>; // C++17 - -template<class Container, class Allocator> + +template<class Container, class Allocator> queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17 template <class T, class Container> @@ -166,13 +165,13 @@ public: template <class Compare, class Container> priority_queue(Compare, Container) -> priority_queue<typename Container::value_type, Container, Compare>; // C++17 - -template<class InputIterator, + +template<class InputIterator, class Compare = less<typename iterator_traits<InputIterator>::value_type>, class Container = vector<typename iterator_traits<InputIterator>::value_type>> priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container()) -> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>; // C++17 - + template<class Compare, class Container, class Allocator> priority_queue(Compare, Container, Allocator) -> priority_queue<typename Container::value_type, Container, Compare>; // C++17 @@ -347,7 +346,7 @@ template<class _Container, > queue(_Container) -> queue<typename _Container::value_type, _Container>; - + template<class _Container, class _Alloc, class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type, @@ -559,8 +558,8 @@ template <class _Compare, > priority_queue(_Compare, _Container) -> priority_queue<typename _Container::value_type, _Container, _Compare>; - -template<class _InputIterator, + +template<class _InputIterator, class _Compare = less<typename iterator_traits<_InputIterator>::value_type>, class _Container = vector<typename iterator_traits<_InputIterator>::value_type>, class = typename enable_if< __is_input_iterator<_InputIterator>::value, nullptr_t>::type, @@ -569,8 +568,8 @@ template<class _InputIterator, > priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container()) -> priority_queue<typename iterator_traits<_InputIterator>::value_type, _Container, _Compare>; - -template<class _Compare, + +template<class _Compare, class _Container, class _Alloc, class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type, diff --git a/include/random b/include/random index 724bd0fc2154..9fefee081702 100644 --- a/include/random +++ b/include/random @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- random -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -2227,19 +2226,19 @@ template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, _UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> - _LIBCPP_CONSTEXPR const size_t + _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, _UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> - _LIBCPP_CONSTEXPR const size_t + _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, _UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> - _LIBCPP_CONSTEXPR const size_t + _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, @@ -2251,7 +2250,7 @@ template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, _UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> - _LIBCPP_CONSTEXPR const size_t + _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, @@ -2263,7 +2262,7 @@ template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, _UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> - _LIBCPP_CONSTEXPR const size_t + _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, @@ -2275,7 +2274,7 @@ template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, _UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> - _LIBCPP_CONSTEXPR const size_t + _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, @@ -2287,7 +2286,7 @@ template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, _UIntType __a, size_t __u, _UIntType __d, size_t __s, _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> - _LIBCPP_CONSTEXPR const size_t + _LIBCPP_CONSTEXPR const size_t mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, @@ -6427,7 +6426,7 @@ public: param_type(size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw); param_type & operator=(const param_type& __rhs); - + _LIBCPP_INLINE_VISIBILITY vector<result_type> intervals() const {return __b_;} _LIBCPP_INLINE_VISIBILITY diff --git a/include/ratio b/include/ratio index 7ee5ec245174..fa7a4bbb2fac 100644 --- a/include/ratio +++ b/include/ratio @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- ratio -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/regex b/include/regex index bd83d7c10ca7..26efac1c620d 100644 --- a/include/regex +++ b/include/regex @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- regex ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -678,7 +677,7 @@ public: regex_constants::match_flag_type m = regex_constants::match_default); regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, const regex_type&& __re, - regex_constants::match_flag_type __m + regex_constants::match_flag_type __m = regex_constants::match_default) = delete; // C++14 regex_iterator(const regex_iterator&); regex_iterator& operator=(const regex_iterator&); @@ -794,7 +793,11 @@ enum syntax_option_type nosubs = 1 << 1, optimize = 1 << 2, collate = 1 << 3, +#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO + ECMAScript = 1 << 9, +#else ECMAScript = 0, +#endif basic = 1 << 4, extended = 1 << 5, awk = 1 << 6, @@ -802,6 +805,16 @@ enum syntax_option_type egrep = 1 << 8 }; +inline _LIBCPP_CONSTEXPR +syntax_option_type __get_grammar(syntax_option_type __g) +{ +#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO + return static_cast<syntax_option_type>(__g & 0x3F0); +#else + return static_cast<syntax_option_type>(__g & 0x1F0); +#endif +} + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR syntax_option_type @@ -988,16 +1001,7 @@ public: typedef locale locale_type; typedef ctype_base::mask char_class_type; -#if defined(__mips__) && defined(__GLIBC__) - static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15)); -#elif defined(__NetBSD__) - // NetBSD defines classes up to 0x2000 - // see sys/ctype_bits.h, _CTYPE_Q - static const char_class_type __regex_word = 0x8000; -#else - static const char_class_type __regex_word = 0x80; -#endif - + static const char_class_type __regex_word = ctype_base::__regex_word; private: locale __loc_; const ctype<char_type>* __ct_; @@ -2293,7 +2297,7 @@ public: else { if (__b.size() != 1 || __e.size() != 1) - __throw_regex_error<regex_constants::error_collate>(); + __throw_regex_error<regex_constants::error_range>(); if (__icase_) { __b[0] = __traits_.translate_nocase(__b[0]); @@ -2527,19 +2531,27 @@ public: // construct/copy/destroy: _LIBCPP_INLINE_VISIBILITY basic_regex() - : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), + : __flags_(regex_constants::ECMAScript), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) {} _LIBCPP_INLINE_VISIBILITY explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__p, __p + __traits_.length(__p));} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__p, __p + __traits_.length(__p)); + } + _LIBCPP_INLINE_VISIBILITY basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__p, __p + __len);} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__p, __p + __len); + } + // basic_regex(const basic_regex&) = default; // basic_regex(basic_regex&&) = default; template <class _ST, class _SA> @@ -2548,21 +2560,31 @@ public: flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__p.begin(), __p.end());} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__p.begin(), __p.end()); + } + template <class _ForwardIterator> _LIBCPP_INLINE_VISIBILITY basic_regex(_ForwardIterator __first, _ForwardIterator __last, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__first, __last);} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__first, __last); + } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_regex(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__il.begin(), __il.end());} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__il.begin(), __il.end()); + } #endif // _LIBCPP_CXX03_LANG // ~basic_regex() = default; @@ -3044,7 +3066,7 @@ basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, __h.release(); __end_ = __start_.get(); } - switch (__flags_ & 0x1F0) + switch (__get_grammar(__flags_)) { case ECMAScript: __first = __parse_ecma_exp(__first, __last); @@ -3379,7 +3401,7 @@ basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, if (__temp != __last) { if (*__first == '\\') - { + { int __val = __traits_.value(*__temp, 10); if (__val >= 1 && __val <= 9) { @@ -3513,7 +3535,7 @@ basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, __first = ++__temp; break; default: - if ((__flags_ & 0x1F0) == awk) + if (__get_grammar(__flags_) == awk) __first = __parse_awk_escape(++__first, __last); break; } @@ -3597,7 +3619,7 @@ basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, { if (__first != __last) { - unsigned __grammar = __flags_ & 0x1F0; + unsigned __grammar = __get_grammar(__flags_); switch (*__first) { case '*': @@ -3718,7 +3740,7 @@ basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __firs // __ml owned by *this if (__first == __last) __throw_regex_error<regex_constants::error_brack>(); - if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') + if (__get_grammar(__flags_) != ECMAScript && *__first == ']') { __ml->__add_char(']'); ++__first; @@ -3779,7 +3801,7 @@ basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, else if (*__temp == '.') __first = __parse_collating_symbol(++__temp, __last, __start_range); } - unsigned __grammar = __flags_ & 0x1F0; + unsigned __grammar = __get_grammar(__flags_); if (__start_range.empty()) { if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') @@ -4076,7 +4098,7 @@ basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, if ( __val != -1 ) { __c = __val; - for (++__first; + for (++__first; __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; ++__first) { @@ -4456,7 +4478,7 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, case 'c': if ((__t = _VSTD::next(__first)) != __last) { - if (('A' <= *__t && *__t <= 'Z') || + if (('A' <= *__t && *__t <= 'Z') || ('a' <= *__t && *__t <= 'z')) { if (__str) @@ -4465,7 +4487,7 @@ basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, __push_char(_CharT(*__t % 32)); __first = ++__t; } - else + else __throw_regex_error<regex_constants::error_escape>(); } else @@ -5265,21 +5287,41 @@ public: // element access: _LIBCPP_INLINE_VISIBILITY difference_type length(size_type __sub = 0) const - {return (*this)[__sub].length();} + { + _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready"); + return (*this)[__sub].length(); + } _LIBCPP_INLINE_VISIBILITY difference_type position(size_type __sub = 0) const - {return _VSTD::distance(__position_start_, (*this)[__sub].first);} + { + _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready"); + return _VSTD::distance(__position_start_, (*this)[__sub].first); + } _LIBCPP_INLINE_VISIBILITY string_type str(size_type __sub = 0) const - {return (*this)[__sub].str();} + { + _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready"); + return (*this)[__sub].str(); + } _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const - {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} + { + _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready"); + return __n < __matches_.size() ? __matches_[__n] : __unmatched_; + } _LIBCPP_INLINE_VISIBILITY - const_reference prefix() const {return __prefix_;} + const_reference prefix() const + { + _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready"); + return __prefix_; + } _LIBCPP_INLINE_VISIBILITY - const_reference suffix() const {return __suffix_;} + const_reference suffix() const + { + _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready"); + return __suffix_; + } _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} @@ -5417,6 +5459,7 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_i const char_type* __fmt_first, const char_type* __fmt_last, regex_constants::match_flag_type __flags) const { + _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready"); if (__flags & regex_constants::format_sed) { for (; __fmt_first != __fmt_last; ++__fmt_first) @@ -5849,7 +5892,7 @@ basic_regex<_CharT, _Traits>::__match_at_start( match_results<const _CharT*, _Allocator>& __m, regex_constants::match_flag_type __flags, bool __at_first) const { - if ((__flags_ & 0x1F0) == ECMAScript) + if (__get_grammar(__flags_) == ECMAScript) return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); if (mark_count() == 0) return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); @@ -5866,7 +5909,7 @@ basic_regex<_CharT, _Traits>::__search( { __m.__init(1 + mark_count(), __first, __last, __flags & regex_constants::__no_update_pos); - if (__match_at_start(__first, __last, __m, __flags, + if (__match_at_start(__first, __last, __m, __flags, !(__flags & regex_constants::__no_update_pos))) { __m.__prefix_.second = __m[0].first; @@ -6012,7 +6055,7 @@ bool regex_search(const basic_string<_Cp, _ST, _SA>&& __s, match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, const basic_regex<_Cp, _Tp>& __e, - regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; + regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; #endif // regex_match @@ -6076,7 +6119,7 @@ bool regex_match(const basic_string<_CharT, _ST, _SA>&& __s, match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, const basic_regex<_CharT, _Traits>& __e, - regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; + regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; #endif template <class _CharT, class _Traits> @@ -6129,7 +6172,7 @@ public: #if _LIBCPP_STD_VER > 11 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, const regex_type&& __re, - regex_constants::match_flag_type __m + regex_constants::match_flag_type __m = regex_constants::match_default) = delete; #endif @@ -6140,7 +6183,7 @@ public: _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __match_;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &__match_;} + pointer operator->() const {return _VSTD::addressof(__match_);} regex_iterator& operator++(); _LIBCPP_INLINE_VISIBILITY @@ -6164,7 +6207,7 @@ regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: const regex_type& __re, regex_constants::match_flag_type __m) : __begin_(__a), __end_(__b), - __pregex_(&__re), + __pregex_(_VSTD::addressof(__re)), __flags_(__m) { _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); @@ -6325,7 +6368,7 @@ private: __result_ = &__position_->prefix(); else __result_ = &(*__position_)[__subs_[__n_]]; - } + } }; template <class _BidirectionalIterator, class _CharT, class _Traits> @@ -6405,7 +6448,7 @@ regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: regex_constants::match_flag_type __m) : __position_(__a, __b, __re, __m), __n_(0), - __subs_(__submatches, __submatches + _Np) + __subs_(begin(__submatches), end(__submatches)) { __init(__a, __b); } diff --git a/include/scoped_allocator b/include/scoped_allocator index bdbb0136b5c3..237cd428d111 100644 --- a/include/scoped_allocator +++ b/include/scoped_allocator @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- scoped_allocator --------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/set b/include/set index a0155f0b2758..70ab4d37add2 100644 --- a/include/set +++ b/include/set @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- set -------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -156,9 +155,9 @@ public: template<typename K> const_iterator find(const K& x) const; // C++14 template<typename K> - size_type count(const K& x) const; // C++14 - + size_type count(const K& x) const; // C++14 size_type count(const key_type& k) const; + bool contains(const key_type& x) const; // C++20 iterator lower_bound(const key_type& k); const_iterator lower_bound(const key_type& k) const; template<typename K> @@ -355,8 +354,10 @@ public: iterator find(const K& x); template<typename K> const_iterator find(const K& x) const; // C++14 - + template<typename K> + size_type count(const K& x) const; // C++14 size_type count(const key_type& k) const; + bool contains(const key_type& x) const; // C++20 iterator lower_bound(const key_type& k); const_iterator lower_bound(const key_type& k) const; template<typename K> @@ -447,11 +448,10 @@ public: typedef key_type value_type; typedef _Compare key_compare; typedef key_compare value_compare; - typedef _Allocator allocator_type; + typedef typename __identity<_Allocator>::type allocator_type; typedef value_type& reference; typedef const value_type& const_reference; - static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); static_assert((is_same<typename allocator_type::value_type, value_type>::value), "Allocator::value_type must be same type as value_type"); @@ -598,6 +598,11 @@ public: #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY + ~set() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __tree_.begin();} @@ -784,6 +789,12 @@ public: typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type count(const _K2& __k) const {return __tree_.__count_multi(__k);} #endif + +#if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const {return find(__k) != end();} +#endif // _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) {return __tree_.lower_bound(__k);} @@ -837,6 +848,34 @@ public: #endif }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Compare = less<typename iterator_traits<_InputIterator>::value_type>, + class _Allocator = allocator<typename iterator_traits<_InputIterator>::value_type>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type, + class = typename enable_if<!__is_allocator<_Compare>::value, void>::type> +set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) + -> set<typename iterator_traits<_InputIterator>::value_type, _Compare, _Allocator>; + +template<class _Key, class _Compare = less<_Key>, + class _Allocator = allocator<_Key>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type, + class = typename enable_if<!__is_allocator<_Compare>::value, void>::type> +set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator()) + -> set<_Key, _Compare, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +set(_InputIterator, _InputIterator, _Allocator) + -> set<typename iterator_traits<_InputIterator>::value_type, + less<typename iterator_traits<_InputIterator>::value_type>, _Allocator>; + +template<class _Key, class _Allocator, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +set(initializer_list<_Key>, _Allocator) + -> set<_Key, less<_Key>, _Allocator>; +#endif + #ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Compare, class _Allocator> @@ -935,11 +974,10 @@ public: typedef key_type value_type; typedef _Compare key_compare; typedef key_compare value_compare; - typedef _Allocator allocator_type; + typedef typename __identity<_Allocator>::type allocator_type; typedef value_type& reference; typedef const value_type& const_reference; - static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); static_assert((is_same<typename allocator_type::value_type, value_type>::value), "Allocator::value_type must be same type as value_type"); @@ -1085,6 +1123,11 @@ public: #endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY + ~multiset() { + static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), ""); + } + + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __tree_.begin();} _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __tree_.begin();} @@ -1272,6 +1315,11 @@ public: count(const _K2& __k) const {return __tree_.__count_multi(__k);} #endif +#if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const {return find(__k) != end();} +#endif // _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) {return __tree_.lower_bound(__k);} @@ -1325,6 +1373,34 @@ public: #endif }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Compare = less<typename iterator_traits<_InputIterator>::value_type>, + class _Allocator = allocator<typename iterator_traits<_InputIterator>::value_type>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type, + class = typename enable_if<!__is_allocator<_Compare>::value, void>::type> +multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator()) + -> multiset<typename iterator_traits<_InputIterator>::value_type, _Compare, _Allocator>; + +template<class _Key, class _Compare = less<_Key>, + class _Allocator = allocator<_Key>, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type, + class = typename enable_if<!__is_allocator<_Compare>::value, void>::type> +multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator()) + -> multiset<_Key, _Compare, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +multiset(_InputIterator, _InputIterator, _Allocator) + -> multiset<typename iterator_traits<_InputIterator>::value_type, + less<typename iterator_traits<_InputIterator>::value_type>, _Allocator>; + +template<class _Key, class _Allocator, + class = typename enable_if<__is_allocator<_Allocator>::value, void>::type> +multiset(initializer_list<_Key>, _Allocator) + -> multiset<_Key, less<_Key>, _Allocator>; +#endif + #ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Compare, class _Allocator> diff --git a/include/setjmp.h b/include/setjmp.h index 464b4a540897..f30a8d401d1a 100644 --- a/include/setjmp.h +++ b/include/setjmp.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- setjmp.h ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/shared_mutex b/include/shared_mutex index 3daf74d26c74..fcafd8c0f44f 100644 --- a/include/shared_mutex +++ b/include/shared_mutex @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------ shared_mutex --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/span b/include/span index cebe98760f27..0694f5115df0 100644 --- a/include/span +++ b/include/span @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------------ span ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===---------------------------------------------------------------------===// @@ -17,33 +16,35 @@ namespace std { // constants -inline constexpr ptrdiff_t dynamic_extent = -1; +inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max(); // [views.span], class template span -template <class ElementType, ptrdiff_t Extent = dynamic_extent> +template <class ElementType, size_t Extent = dynamic_extent> class span; // [span.objectrep], views of object representation -template <class ElementType, ptrdiff_t Extent> +template <class ElementType, size_t Extent> span<const byte, ((Extent == dynamic_extent) ? dynamic_extent : - (static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent))> as_bytes(span<ElementType, Extent> s) noexcept; + (sizeof(ElementType) * Extent))> as_bytes(span<ElementType, Extent> s) noexcept; -template <class ElementType, ptrdiff_t Extent> +template <class ElementType, size_t Extent> span< byte, ((Extent == dynamic_extent) ? dynamic_extent : - (static_cast<ptrdiff_t>(sizeof(ElementType)) * Extent))> as_writable_bytes(span<ElementType, Extent> s) noexcept; + (sizeof(ElementType) * Extent))> as_writable_bytes(span<ElementType, Extent> s) noexcept; namespace std { -template <class ElementType, ptrdiff_t Extent = dynamic_extent> +template <class ElementType, size_t Extent = dynamic_extent> class span { public: // constants and types using element_type = ElementType; using value_type = remove_cv_t<ElementType>; - using index_type = ptrdiff_t; + using index_type = size_t; using difference_type = ptrdiff_t; using pointer = element_type*; + using const_pointer = const element_type*; using reference = element_type&; + using const_reference = const element_type&; using iterator = implementation-defined; using const_iterator = implementation-defined; using reverse_iterator = std::reverse_iterator<iterator>; @@ -65,17 +66,17 @@ public: template <class Container> constexpr span(const Container& cont); constexpr span(const span& other) noexcept = default; - template <class OtherElementType, ptrdiff_t OtherExtent> + template <class OtherElementType, size_t OtherExtent> constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept; ~span() noexcept = default; constexpr span& operator=(const span& other) noexcept = default; // [span.sub], span subviews - template <ptrdiff_t Count> + template <size_t Count> constexpr span<element_type, Count> first() const; - template <ptrdiff_t Count> + template <size_t Count> constexpr span<element_type, Count> last() const; - template <ptrdiff_t Offset, ptrdiff_t Count = dynamic_extent> + template <size_t Offset, size_t Count = dynamic_extent> constexpr span<element_type, see below> subspan() const; constexpr span<element_type, dynamic_extent> first(index_type count) const; @@ -89,7 +90,8 @@ public: // [span.elem], span element access constexpr reference operator[](index_type idx) const; - constexpr reference operator()(index_type idx) const; + constexpr reference front() const; + constexpr reference back() const; constexpr pointer data() const noexcept; // [span.iterators], span iterator support @@ -141,14 +143,14 @@ _LIBCPP_BEGIN_NAMESPACE_STD #if _LIBCPP_STD_VER > 17 -inline constexpr ptrdiff_t dynamic_extent = -1; -template <typename _Tp, ptrdiff_t _Extent = dynamic_extent> class span; +inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max(); +template <typename _Tp, size_t _Extent = dynamic_extent> class span; template <class _Tp> struct __is_span_impl : public false_type {}; -template <class _Tp, ptrdiff_t _Extent> +template <class _Tp, size_t _Extent> struct __is_span_impl<span<_Tp, _Extent>> : public true_type {}; template <class _Tp> @@ -187,25 +189,24 @@ struct __is_span_compatible_container<_Tp, _ElementType, : public true_type {}; -template <typename _Tp, ptrdiff_t _Extent> +template <typename _Tp, size_t _Extent> class _LIBCPP_TEMPLATE_VIS span { public: // constants and types using element_type = _Tp; using value_type = remove_cv_t<_Tp>; - using index_type = ptrdiff_t; + using index_type = size_t; using difference_type = ptrdiff_t; using pointer = _Tp *; - using const_pointer = const _Tp *; // not in standard + using const_pointer = const _Tp *; using reference = _Tp &; - using const_reference = const _Tp &; // not in standard + using const_reference = const _Tp &; using iterator = __wrap_iter<pointer>; using const_iterator = __wrap_iter<const_pointer>; using reverse_iterator = _VSTD::reverse_iterator<iterator>; using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>; static constexpr index_type extent = _Extent; - static_assert (_Extent >= 0, "Can't have a span with an extent < 0"); // [span.cons], span constructors, copy, assignment, and destructor _LIBCPP_INLINE_VISIBILITY constexpr span() noexcept : __data{nullptr} @@ -223,22 +224,8 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span( array<value_type, _Extent>& __arr) noexcept : __data{__arr.data()} {} _LIBCPP_INLINE_VISIBILITY constexpr span(const array<value_type, _Extent>& __arr) noexcept : __data{__arr.data()} {} - template <class _Container> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span( _Container& __c, - enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) - : __data{_VSTD::data(__c)} - { _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (container)"); } - - template <class _Container> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(const _Container& __c, - enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr) - : __data{_VSTD::data(__c)} - { _LIBCPP_ASSERT(_Extent == _VSTD::size(__c), "size mismatch in span's constructor (const container)"); } - template <class _OtherElementType> - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, _Extent>& __other, enable_if_t< is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, @@ -246,7 +233,7 @@ public: : __data{__other.data()} {} template <class _OtherElementType> - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, dynamic_extent>& __other, enable_if_t< is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, @@ -256,20 +243,18 @@ public: // ~span() noexcept = default; - template <ptrdiff_t _Count> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<element_type, _Count> first() const noexcept + template <size_t _Count> + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> first() const noexcept { - static_assert(_Count >= 0, "Count must be >= 0 in span::first()"); static_assert(_Count <= _Extent, "Count out of range in span::first()"); return {data(), _Count}; } - template <ptrdiff_t _Count> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<element_type, _Count> last() const noexcept + template <size_t _Count> + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> last() const noexcept { - static_assert(_Count >= 0, "Count must be >= 0 in span::last()"); static_assert(_Count <= _Extent, "Count out of range in span::last()"); return {data() + size() - _Count, _Count}; } @@ -277,36 +262,36 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> first(index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::first(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); return {data(), __count}; } _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> last(index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::last(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); return {data() + size() - __count, __count}; } - template <ptrdiff_t _Offset, ptrdiff_t _Count = dynamic_extent> - inline _LIBCPP_INLINE_VISIBILITY - constexpr auto subspan() const noexcept + template <size_t _Offset, size_t _Count = dynamic_extent> + _LIBCPP_INLINE_VISIBILITY + constexpr auto subspan() const noexcept -> span<element_type, _Count != dynamic_extent ? _Count : _Extent - _Offset> { - _LIBCPP_ASSERT(_Offset >= 0 && _Offset <= size(), "Offset out of range in span::subspan()"); + static_assert(_Offset <= _Extent, "Offset out of range in span::subspan()"); return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; } - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept { - _LIBCPP_ASSERT( __offset >= 0 && __offset <= size(), "Offset out of range in span::subspan(offset, count)"); - _LIBCPP_ASSERT((__count >= 0 && __count <= size()) || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "Count out of range in span::subspan(offset, count)"); if (__count == dynamic_extent) return {data() + __offset, size() - __offset}; - _LIBCPP_ASSERT(__offset + __count <= size(), "count + offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size() - __count, "count + offset out of range in span::subspan(offset, count)"); return {data() + __offset, __count}; } @@ -320,10 +305,16 @@ public: return __data[__idx]; } - _LIBCPP_INLINE_VISIBILITY constexpr reference operator()(index_type __idx) const noexcept + _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept { - _LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T,N>() index out of bounds"); - return __data[__idx]; + static_assert(_Extent > 0, "span<T,N>[].front() on empty span"); + return __data[0]; + } + + _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept + { + static_assert(_Extent > 0, "span<T,N>[].back() on empty span"); + return __data[size()-1]; } _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; } @@ -348,7 +339,7 @@ public: _LIBCPP_INLINE_VISIBILITY span<const byte, _Extent * sizeof(element_type)> __as_bytes() const noexcept { return {reinterpret_cast<const byte *>(data()), size_bytes()}; } - _LIBCPP_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)> __as_writeable_bytes() const noexcept + _LIBCPP_INLINE_VISIBILITY span<byte, _Extent * sizeof(element_type)> __as_writable_bytes() const noexcept { return {reinterpret_cast<byte *>(data()), size_bytes()}; } private: @@ -365,12 +356,12 @@ public: // constants and types using element_type = _Tp; using value_type = remove_cv_t<_Tp>; - using index_type = ptrdiff_t; + using index_type = size_t; using difference_type = ptrdiff_t; using pointer = _Tp *; - using const_pointer = const _Tp *; // not in standard + using const_pointer = const _Tp *; using reference = _Tp &; - using const_reference = const _Tp &; // not in standard + using const_reference = const _Tp &; using iterator = __wrap_iter<pointer>; using const_iterator = __wrap_iter<const_pointer>; using reverse_iterator = _VSTD::reverse_iterator<iterator>; @@ -385,35 +376,35 @@ public: constexpr span& operator=(const span&) noexcept = default; _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __ptr, index_type __count) : __data{__ptr}, __size{__count} {} - _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{distance(__f, __l)} {} + _LIBCPP_INLINE_VISIBILITY constexpr span(pointer __f, pointer __l) : __data{__f}, __size{static_cast<size_t>(distance(__f, __l))} {} template <size_t _Sz> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {} + _LIBCPP_INLINE_VISIBILITY + constexpr span(element_type (&__arr)[_Sz]) noexcept : __data{__arr}, __size{_Sz} {} template <size_t _Sz> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} + _LIBCPP_INLINE_VISIBILITY + constexpr span(array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} template <size_t _Sz> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span(const array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} + _LIBCPP_INLINE_VISIBILITY + constexpr span(const array<value_type, _Sz>& __arr) noexcept : __data{__arr.data()}, __size{_Sz} {} template <class _Container> - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span( _Container& __c, enable_if_t<__is_span_compatible_container<_Container, _Tp>::value, nullptr_t> = nullptr) : __data{_VSTD::data(__c)}, __size{(index_type) _VSTD::size(__c)} {} template <class _Container> - inline _LIBCPP_INLINE_VISIBILITY + _LIBCPP_INLINE_VISIBILITY constexpr span(const _Container& __c, enable_if_t<__is_span_compatible_container<const _Container, _Tp>::value, nullptr_t> = nullptr) : __data{_VSTD::data(__c)}, __size{(index_type) _VSTD::size(__c)} {} - template <class _OtherElementType, ptrdiff_t _OtherExtent> - inline _LIBCPP_INLINE_VISIBILITY + template <class _OtherElementType, size_t _OtherExtent> + _LIBCPP_INLINE_VISIBILITY constexpr span(const span<_OtherElementType, _OtherExtent>& __other, enable_if_t< is_convertible_v<_OtherElementType(*)[], element_type (*)[]>, @@ -422,20 +413,18 @@ public: // ~span() noexcept = default; - template <ptrdiff_t _Count> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<element_type, _Count> first() const noexcept + template <size_t _Count> + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> first() const noexcept { - static_assert(_Count >= 0, "Count must be >= 0 in span::first()"); _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::first()"); return {data(), _Count}; } - template <ptrdiff_t _Count> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<element_type, _Count> last() const noexcept + template <size_t _Count> + _LIBCPP_INLINE_VISIBILITY + constexpr span<element_type, _Count> last() const noexcept { - static_assert(_Count >= 0, "Count must be >= 0 in span::last()"); _LIBCPP_ASSERT(_Count <= size(), "Count out of range in span::last()"); return {data() + size() - _Count, _Count}; } @@ -443,35 +432,35 @@ public: _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> first(index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::first(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::first(count)"); return {data(), __count}; } _LIBCPP_INLINE_VISIBILITY constexpr span<element_type, dynamic_extent> last (index_type __count) const noexcept { - _LIBCPP_ASSERT(__count >= 0 && __count <= size(), "Count out of range in span::last(count)"); + _LIBCPP_ASSERT(__count <= size(), "Count out of range in span::last(count)"); return {data() + size() - __count, __count}; } - template <ptrdiff_t _Offset, ptrdiff_t _Count = dynamic_extent> - inline _LIBCPP_INLINE_VISIBILITY - constexpr span<_Tp, dynamic_extent> subspan() const noexcept + template <size_t _Offset, size_t _Count = dynamic_extent> + _LIBCPP_INLINE_VISIBILITY + constexpr span<_Tp, dynamic_extent> subspan() const noexcept { - _LIBCPP_ASSERT(_Offset >= 0 && _Offset <= size(), "Offset out of range in span::subspan()"); + _LIBCPP_ASSERT(_Offset <= size(), "Offset out of range in span::subspan()"); _LIBCPP_ASSERT(_Count == dynamic_extent || _Offset + _Count <= size(), "Count out of range in span::subspan()"); return {data() + _Offset, _Count == dynamic_extent ? size() - _Offset : _Count}; } constexpr span<element_type, dynamic_extent> - inline _LIBCPP_INLINE_VISIBILITY - subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept + _LIBCPP_INLINE_VISIBILITY + subspan(index_type __offset, index_type __count = dynamic_extent) const noexcept { - _LIBCPP_ASSERT( __offset >= 0 && __offset <= size(), "Offset out of range in span::subspan(offset, count)"); - _LIBCPP_ASSERT((__count >= 0 && __count <= size()) || __count == dynamic_extent, "count out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size(), "Offset out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__count <= size() || __count == dynamic_extent, "count out of range in span::subspan(offset, count)"); if (__count == dynamic_extent) return {data() + __offset, size() - __offset}; - _LIBCPP_ASSERT(__offset + __count <= size(), "Offset + count out of range in span::subspan(offset, count)"); + _LIBCPP_ASSERT(__offset <= size() - __count, "Offset + count out of range in span::subspan(offset, count)"); return {data() + __offset, __count}; } @@ -485,12 +474,19 @@ public: return __data[__idx]; } - _LIBCPP_INLINE_VISIBILITY constexpr reference operator()(index_type __idx) const noexcept + _LIBCPP_INLINE_VISIBILITY constexpr reference front() const noexcept { - _LIBCPP_ASSERT(__idx >= 0 && __idx < size(), "span<T>() index out of bounds"); - return __data[__idx]; + _LIBCPP_ASSERT(!empty(), "span<T>[].front() on empty span"); + return __data[0]; } + _LIBCPP_INLINE_VISIBILITY constexpr reference back() const noexcept + { + _LIBCPP_ASSERT(!empty(), "span<T>[].back() on empty span"); + return __data[size()-1]; + } + + _LIBCPP_INLINE_VISIBILITY constexpr pointer data() const noexcept { return __data; } // [span.iter], span iterator support @@ -517,7 +513,7 @@ public: _LIBCPP_INLINE_VISIBILITY span<const byte, dynamic_extent> __as_bytes() const noexcept { return {reinterpret_cast<const byte *>(data()), size_bytes()}; } - _LIBCPP_INLINE_VISIBILITY span<byte, dynamic_extent> __as_writeable_bytes() const noexcept + _LIBCPP_INLINE_VISIBILITY span<byte, dynamic_extent> __as_writable_bytes() const noexcept { return {reinterpret_cast<byte *>(data()), size_bytes()}; } private: @@ -525,20 +521,51 @@ private: index_type __size; }; -// as_bytes & as_writeable_bytes -template <class _Tp, ptrdiff_t _Extent> - auto as_bytes(span<_Tp, _Extent> __s) noexcept - -> decltype(__s.__as_bytes()) - { return __s.__as_bytes(); } +// tuple interface +template <class _Tp, size_t _Size> +struct _LIBCPP_TEMPLATE_VIS tuple_size<span<_Tp, _Size>> + : public integral_constant<size_t, _Size> {}; -template <class _Tp, ptrdiff_t _Extent> - auto as_writeable_bytes(span<_Tp, _Extent> __s) noexcept - -> typename enable_if<!is_const_v<_Tp>, decltype(__s.__as_writeable_bytes())>::type - { return __s.__as_writeable_bytes(); } +template <class _Tp> +struct _LIBCPP_TEMPLATE_VIS tuple_size<span<_Tp, dynamic_extent>>; // declared but not defined + + +template <size_t _Ip, class _Tp, size_t _Size> +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, span<_Tp, _Size>> +{ + static_assert( dynamic_extent != _Size, "std::tuple_element<> not supported for std::span<T, dynamic_extent>"); + static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::span)"); + typedef _Tp type; +}; -template <class _Tp, ptrdiff_t _Extent> - constexpr void swap(span<_Tp, _Extent> &__lhs, span<_Tp, _Extent> &__rhs) noexcept - { __lhs.swap(__rhs); } +template <size_t _Ip, class _Tp, size_t _Size> +_LIBCPP_INLINE_VISIBILITY constexpr +_Tp& +get(span<_Tp, _Size> __s) noexcept +{ + static_assert( dynamic_extent != _Size, "std::get<> not supported for std::span<T, dynamic_extent>"); + static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::span)"); + return __s[_Ip]; +} + + +// as_bytes & as_writable_bytes +template <class _Tp, size_t _Extent> +_LIBCPP_INLINE_VISIBILITY +auto as_bytes(span<_Tp, _Extent> __s) noexcept +-> decltype(__s.__as_bytes()) +{ return __s.__as_bytes(); } + +template <class _Tp, size_t _Extent> +_LIBCPP_INLINE_VISIBILITY +auto as_writable_bytes(span<_Tp, _Extent> __s) noexcept +-> enable_if_t<!is_const_v<_Tp>, decltype(__s.__as_writable_bytes())> +{ return __s.__as_writable_bytes(); } + +template <class _Tp, size_t _Extent> +_LIBCPP_INLINE_VISIBILITY +constexpr void swap(span<_Tp, _Extent> &__lhs, span<_Tp, _Extent> &__rhs) noexcept +{ __lhs.swap(__rhs); } // Deduction guides diff --git a/include/sstream b/include/sstream index 9c3ee13bfbad..14c91971c2f1 100644 --- a/include/sstream +++ b/include/sstream @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- sstream ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -559,7 +558,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c) char_type* __p = const_cast<char_type*>(__str_.data()); this->setg(__p, __p + __ninp, __hm_); } - return this->sputc(__c); + return this->sputc(traits_type::to_char_type(__c)); } return traits_type::not_eof(__c); } diff --git a/include/stack b/include/stack index 2b3f8aea19e6..2a2b350386e5 100644 --- a/include/stack +++ b/include/stack @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- stack -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -63,8 +62,8 @@ public: template<class Container> stack(Container) -> stack<typename Container::value_type, Container>; // C++17 - -template<class Container, class Allocator> + +template<class Container, class Allocator> stack(Container, Allocator) -> stack<typename Container::value_type, Container>; // C++17 template <class T, class Container> @@ -119,7 +118,7 @@ public: typedef typename container_type::const_reference const_reference; typedef typename container_type::size_type size_type; static_assert((is_same<_Tp, value_type>::value), "" ); - + protected: container_type c; @@ -241,12 +240,12 @@ template<class _Container, > stack(_Container) -> stack<typename _Container::value_type, _Container>; - + template<class _Container, class _Alloc, class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type, class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type - > + > stack(_Container, _Alloc) -> stack<typename _Container::value_type, _Container>; #endif diff --git a/include/stdbool.h b/include/stdbool.h index 86a127f0fd62..81a7cb3038b8 100644 --- a/include/stdbool.h +++ b/include/stdbool.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- stdbool.h --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_STDBOOL_H diff --git a/include/stddef.h b/include/stddef.h index f65065d869a8..6497dcda2af4 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- stddef.h ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/stdexcept b/include/stdexcept index 3ec79349aa92..481f9043c50d 100644 --- a/include/stdexcept +++ b/include/stdexcept @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- stdexcept --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -55,6 +54,7 @@ public: _LIBCPP_BEGIN_NAMESPACE_STD +#ifndef _LIBCPP_ABI_VCRUNTIME class _LIBCPP_HIDDEN __libcpp_refstring { const char* __imp_; @@ -68,6 +68,7 @@ public: const char* c_str() const _NOEXCEPT {return __imp_;} }; +#endif // !_LIBCPP_ABI_VCRUNTIME _LIBCPP_END_NAMESPACE_STD @@ -77,6 +78,7 @@ namespace std // purposefully not using versioning namespace class _LIBCPP_EXCEPTION_ABI logic_error : public exception { +#ifndef _LIBCPP_ABI_VCRUNTIME private: _VSTD::__libcpp_refstring __imp_; public: @@ -89,11 +91,17 @@ public: virtual ~logic_error() _NOEXCEPT; virtual const char* what() const _NOEXCEPT; +#else +public: + explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string + _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {} +#endif }; class _LIBCPP_EXCEPTION_ABI runtime_error : public exception { +#ifndef _LIBCPP_ABI_VCRUNTIME private: _VSTD::__libcpp_refstring __imp_; public: @@ -106,6 +114,11 @@ public: virtual ~runtime_error() _NOEXCEPT; virtual const char* what() const _NOEXCEPT; +#else +public: + explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string + _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {} +#endif // _LIBCPP_ABI_VCRUNTIME }; class _LIBCPP_EXCEPTION_ABI domain_error @@ -115,7 +128,9 @@ public: _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {} +#ifndef _LIBCPP_ABI_VCRUNTIME virtual ~domain_error() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI invalid_argument @@ -125,7 +140,9 @@ public: _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {} +#ifndef _LIBCPP_ABI_VCRUNTIME virtual ~invalid_argument() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI length_error @@ -134,8 +151,9 @@ class _LIBCPP_EXCEPTION_ABI length_error public: _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {} - +#ifndef _LIBCPP_ABI_VCRUNTIME virtual ~length_error() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI out_of_range @@ -145,7 +163,9 @@ public: _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {} +#ifndef _LIBCPP_ABI_VCRUNTIME virtual ~out_of_range() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI range_error @@ -155,7 +175,9 @@ public: _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {} +#ifndef _LIBCPP_ABI_VCRUNTIME virtual ~range_error() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI overflow_error @@ -165,7 +187,9 @@ public: _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {} +#ifndef _LIBCPP_ABI_VCRUNTIME virtual ~overflow_error() _NOEXCEPT; +#endif }; class _LIBCPP_EXCEPTION_ABI underflow_error @@ -175,7 +199,9 @@ public: _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {} _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {} +#ifndef _LIBCPP_ABI_VCRUNTIME virtual ~underflow_error() _NOEXCEPT; +#endif }; } // std diff --git a/include/stdint.h b/include/stdint.h index 468f6cd97c23..d7b6902518ae 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -1,15 +1,19 @@ // -*- C++ -*- //===---------------------------- stdint.h --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_STDINT_H +// AIX system headers need stdint.h to be re-enterable while _STD_TYPES_T +// is defined until an inclusion of it without _STD_TYPES_T occurs, in which +// case the header guard macro is defined. +#if !defined(_AIX) || !defined(_STD_TYPES_T) #define _LIBCPP_STDINT_H +#endif // _STD_TYPES_T /* stdint.h synopsis diff --git a/include/stdio.h b/include/stdio.h index 77a314bf3836..e08e6bc9b698 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- stdio.h ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/stdlib.h b/include/stdlib.h index f11c5e76226e..1d6827587037 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -1,19 +1,22 @@ // -*- C++ -*- //===--------------------------- stdlib.h ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// -#if defined(__need_malloc_and_calloc) +#if defined(__need_malloc_and_calloc) || defined(_LIBCPP_STDLIB_INCLUDE_NEXT) #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +#if defined(_LIBCPP_STDLIB_INCLUDE_NEXT) +#undef _LIBCPP_STDLIB_INCLUDE_NEXT +#endif + #include_next <stdlib.h> #elif !defined(_LIBCPP_STDLIB_H) @@ -94,33 +97,7 @@ void *aligned_alloc(size_t alignment, size_t size); // C11 #include_next <stdlib.h> #ifdef __cplusplus - -extern "C++" { - -#undef abs -#undef div -#undef labs -#undef ldiv -#ifndef _LIBCPP_HAS_NO_LONG_LONG -#undef llabs -#undef lldiv -#endif - -// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined -#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) -inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);} -#ifndef _LIBCPP_HAS_NO_LONG_LONG -inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);} -#endif // _LIBCPP_HAS_NO_LONG_LONG - -inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);} -#ifndef _LIBCPP_HAS_NO_LONG_LONG -inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);} -#endif // _LIBCPP_HAS_NO_LONG_LONG -#endif // _LIBCPP_MSVCRT / __sun__ / _AIX - -} // extern "C++" - +#include <math.h> #endif // __cplusplus #endif // _LIBCPP_STDLIB_H diff --git a/include/streambuf b/include/streambuf index dd293dc639b9..48c07d5e1f42 100644 --- a/include/streambuf +++ b/include/streambuf @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------- streambuf ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/string b/include/string index fb838d1e5dd2..1e5b09800c61 100644 --- a/include/string +++ b/include/string @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- string -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -628,13 +627,13 @@ struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {}; #else template <class _Iter, bool = __is_forward_iterator<_Iter>::value> struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT(( - noexcept(++(declval<_Iter&>())) && - is_nothrow_assignable<_Iter&, _Iter>::value && - noexcept(declval<_Iter>() == declval<_Iter>()) && + noexcept(++(declval<_Iter&>())) && + is_nothrow_assignable<_Iter&, _Iter>::value && + noexcept(declval<_Iter>() == declval<_Iter>()) && noexcept(*declval<_Iter>()) )) {}; -template <class _Iter> +template <class _Iter> struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {}; #endif @@ -863,10 +862,10 @@ public: _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS explicit basic_string(const _Tp& __t, const allocator_type& __a); - template<class _InputIterator> + template<class _InputIterator, class = typename enable_if<__is_input_iterator<_InputIterator>::value>::type> _LIBCPP_INLINE_VISIBILITY basic_string(_InputIterator __first, _InputIterator __last); - template<class _InputIterator> + template<class _InputIterator, class = typename enable_if<__is_input_iterator<_InputIterator>::value>::type> _LIBCPP_INLINE_VISIBILITY basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); #ifndef _LIBCPP_CXX03_LANG @@ -1061,10 +1060,10 @@ public: void push_back(value_type __c); _LIBCPP_INLINE_VISIBILITY void pop_back(); - _LIBCPP_INLINE_VISIBILITY reference front(); - _LIBCPP_INLINE_VISIBILITY const_reference front() const; - _LIBCPP_INLINE_VISIBILITY reference back(); - _LIBCPP_INLINE_VISIBILITY const_reference back() const; + _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT; template <class _Tp> _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS @@ -1237,9 +1236,9 @@ public: _LIBCPP_INLINE_VISIBILITY void swap(basic_string& __str) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT_DEBUG; + _NOEXCEPT; #else - _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); #endif @@ -1421,7 +1420,7 @@ public: _LIBCPP_INLINE_VISIBILITY bool __invariants() const; _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT; - + _LIBCPP_INLINE_VISIBILITY bool __is_long() const _NOEXCEPT {return bool(__r_.first().__s.__size_ & __short_mask);} @@ -1683,7 +1682,7 @@ basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _ -> basic_string<_CharT, _Traits, _Allocator>; #endif - + template <class _CharT, class _Traits, class _Allocator> inline void @@ -2078,7 +2077,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _For } template <class _CharT, class _Traits, class _Allocator> -template<class _InputIterator> +template<class _InputIterator, class> inline basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) { @@ -2089,7 +2088,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, } template <class _CharT, class _Traits, class _Allocator> -template<class _InputIterator> +template<class _InputIterator, class> inline basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) @@ -2526,7 +2525,7 @@ basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe( const basic_string __temp (__first, __last, __alloc()); append(__temp.data(), __temp.size()); } - else + else { if (__cap - __sz < __n) __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); @@ -3238,7 +3237,7 @@ basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) template <class _CharT, class _Traits, class _Allocator> inline typename basic_string<_CharT, _Traits, _Allocator>::reference -basic_string<_CharT, _Traits, _Allocator>::front() +basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); return *__get_pointer(); @@ -3247,7 +3246,7 @@ basic_string<_CharT, _Traits, _Allocator>::front() template <class _CharT, class _Traits, class _Allocator> inline typename basic_string<_CharT, _Traits, _Allocator>::const_reference -basic_string<_CharT, _Traits, _Allocator>::front() const +basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); return *data(); @@ -3256,7 +3255,7 @@ basic_string<_CharT, _Traits, _Allocator>::front() const template <class _CharT, class _Traits, class _Allocator> inline typename basic_string<_CharT, _Traits, _Allocator>::reference -basic_string<_CharT, _Traits, _Allocator>::back() +basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); return *(__get_pointer() + size() - 1); @@ -3265,7 +3264,7 @@ basic_string<_CharT, _Traits, _Allocator>::back() template <class _CharT, class _Traits, class _Allocator> inline typename basic_string<_CharT, _Traits, _Allocator>::const_reference -basic_string<_CharT, _Traits, _Allocator>::back() const +basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); return *(data() + size() - 1); @@ -3296,9 +3295,9 @@ inline void basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT_DEBUG + _NOEXCEPT #else - _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) #endif { @@ -3825,7 +3824,7 @@ basic_string<_CharT, _Traits, _Allocator>::__invariants() const template<class _CharT, class _Traits, class _Allocator> inline -void +void basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT { clear(); @@ -3835,7 +3834,7 @@ basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT __set_long_cap(0); __set_short_size(0); } -} +} // operator== @@ -4228,21 +4227,17 @@ template<class _CharT, class _Traits, class _Allocator> const typename basic_string<_CharT, _Traits, _Allocator>::size_type basic_string<_CharT, _Traits, _Allocator>::npos; -template<class _CharT, class _Traits, class _Allocator> -struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> > - : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t> +template <class _CharT, class _Allocator> +struct _LIBCPP_TEMPLATE_VIS + hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> > + : public unary_function< + basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t> { size_t - operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT; + operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT + { return __do_string_hash(__val.data(), __val.data() + __val.size()); } }; -template<class _CharT, class _Traits, class _Allocator> -size_t -hash<basic_string<_CharT, _Traits, _Allocator> >::operator()( - const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT -{ - return __do_string_hash(__val.data(), __val.data() + __val.size()); -} template<class _CharT, class _Traits, class _Allocator> basic_ostream<_CharT, _Traits>& @@ -4332,7 +4327,7 @@ basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>) _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>) -#if _LIBCPP_STD_VER > 11 +#if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] inline namespace literals { diff --git a/include/string.h b/include/string.h index a1ce56cbcd6d..e09251d06405 100644 --- a/include/string.h +++ b/include/string.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- string.h ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/string_view b/include/string_view index 7d783122f123..04448312ff33 100644 --- a/include/string_view +++ b/include/string_view @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------ string_view ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -229,9 +228,9 @@ public: basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT : __data(__s), __size(__len) { -// #if _LIBCPP_STD_VER > 11 -// _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); -// #endif +#if _LIBCPP_STD_VER > 11 + _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); +#endif } _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY @@ -289,13 +288,13 @@ public: } _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_reference front() const + const_reference front() const _NOEXCEPT { return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0]; } _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY - const_reference back() const + const_reference back() const _NOEXCEPT { return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1]; } @@ -365,7 +364,7 @@ public: } _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY - int compare( size_type __pos1, size_type __n1, + int compare( size_type __pos1, size_type __n1, basic_string_view __sv, size_type __pos2, size_type __n2) const { return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); @@ -629,7 +628,7 @@ bool operator==(basic_string_view<_CharT, _Traits> __lhs, template<class _CharT, class _Traits> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, +bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { if ( __lhs.size() != __rhs.size()) return false; @@ -659,7 +658,7 @@ bool operator!=(basic_string_view<_CharT, _Traits> __lhs, template<class _CharT, class _Traits> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, +bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { if ( __lhs.size() != __rhs.size()) @@ -686,7 +685,7 @@ bool operator<(basic_string_view<_CharT, _Traits> __lhs, template<class _CharT, class _Traits> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, +bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { return __lhs.compare(__rhs) < 0; @@ -711,7 +710,7 @@ bool operator>(basic_string_view<_CharT, _Traits> __lhs, template<class _CharT, class _Traits> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, +bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { return __lhs.compare(__rhs) > 0; @@ -736,7 +735,7 @@ bool operator<=(basic_string_view<_CharT, _Traits> __lhs, template<class _CharT, class _Traits> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, +bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { return __lhs.compare(__rhs) <= 0; @@ -762,7 +761,7 @@ bool operator>=(basic_string_view<_CharT, _Traits> __lhs, template<class _CharT, class _Traits> _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY -bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, +bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT { return __lhs.compare(__rhs) >= 0; @@ -777,18 +776,18 @@ typedef basic_string_view<char32_t> u32string_view; typedef basic_string_view<wchar_t> wstring_view; // [string.view.hash] -template<class _CharT, class _Traits> -struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, _Traits> > - : public unary_function<basic_string_view<_CharT, _Traits>, size_t> +template<class _CharT> +struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > > + : public unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t> { _LIBCPP_INLINE_VISIBILITY - size_t operator()(const basic_string_view<_CharT, _Traits> __val) const _NOEXCEPT { + size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT { return __do_string_hash(__val.data(), __val.data() + __val.size()); } }; -#if _LIBCPP_STD_VER > 11 +#if _LIBCPP_STD_VER > 11 inline namespace literals { inline namespace string_view_literals diff --git a/include/strstream b/include/strstream index b00b9d830dff..31999bbae14b 100644 --- a/include/strstream +++ b/include/strstream @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- strstream --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/system_error b/include/system_error index 6e2c8388f17e..05ef07950d05 100644 --- a/include/system_error +++ b/include/system_error @@ -1,10 +1,9 @@ // -*- C++ -*- //===---------------------------- system_error ----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/tgmath.h b/include/tgmath.h index aba87499c294..2dc1f771d91c 100644 --- a/include/tgmath.h +++ b/include/tgmath.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- tgmath.h ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/thread b/include/thread index 8c0115f8708d..3d8d2ac9ce50 100644 --- a/include/thread +++ b/include/thread @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- thread -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -435,7 +434,12 @@ sleep_for(const chrono::duration<_Rep, _Period>& __d) using namespace chrono; if (__d > duration<_Rep, _Period>::zero()) { +#if defined(_LIBCPP_COMPILER_GCC) && (__powerpc__ || __POWERPC__) + // GCC's long double const folding is incomplete for IBM128 long doubles. _LIBCPP_CONSTEXPR duration<long double> _Max = nanoseconds::max(); +#else + _LIBCPP_CONSTEXPR duration<long double> _Max = duration<long double>(ULLONG_MAX/1000000000ULL) ; +#endif nanoseconds __ns; if (__d < _Max) { diff --git a/include/tuple b/include/tuple index 4cc69030b9ab..031d25a9854f 100644 --- a/include/tuple +++ b/include/tuple @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- tuple ------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -88,8 +87,8 @@ template <class T> struct tuple_size; // undefined template <class... T> struct tuple_size<tuple<T...>>; template <class T> inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17 -template <size_t I, class T> class tuple_element; // undefined -template <size_t I, class... T> class tuple_element<I, tuple<T...>>; +template <size_t I, class T> struct tuple_element; // undefined +template <size_t I, class... T> struct tuple_element<I, tuple<T...>>; template <size_t I, class T> using tuple_element_t = typename tuple_element <I, T>::type; // C++14 @@ -210,12 +209,12 @@ public: "Attempted to default construct a reference element in a tuple");} template <class _Tp, - class = typename enable_if< - __lazy_and< - __lazy_not<is_same<typename __uncvref<_Tp>::type, __tuple_leaf>> - , is_constructible<_Hp, _Tp> + class = _EnableIf< + _And< + _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>, + is_constructible<_Hp, _Tp> >::value - >::type + > > _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) @@ -292,12 +291,12 @@ public: : _Hp(__a) {} template <class _Tp, - class = typename enable_if< - __lazy_and< - __lazy_not<is_same<typename __uncvref<_Tp>::type, __tuple_leaf>> - , is_constructible<_Hp, _Tp> - >::value - >::type + class = _EnableIf< + _And< + _IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>, + is_constructible<_Hp, _Tp> + >::value + > > _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) @@ -346,9 +345,6 @@ template <class ..._Tp> _LIBCPP_INLINE_VISIBILITY void __swallow(_Tp&&...) _NOEXCEPT {} -template <class ..._Tp> -struct __lazy_all : __all<_Tp::value...> {}; - template <class _Tp> struct __all_default_constructible; @@ -525,6 +521,13 @@ class _LIBCPP_TEMPLATE_VIS tuple template <class ..._Args> static constexpr bool __enable_implicit() { return + __tuple_constructible< + tuple<_Args...>, + typename __make_tuple_types<tuple, + sizeof...(_Args) < sizeof...(_Tp) ? + sizeof...(_Args) : + sizeof...(_Tp)>::type + >::value && __tuple_convertible< tuple<_Args...>, typename __make_tuple_types<tuple, @@ -551,7 +554,8 @@ class _LIBCPP_TEMPLATE_VIS tuple { template <class _Tuple> static constexpr bool __enable_implicit() { - return __tuple_convertible<_Tuple, tuple>::value; + return __tuple_constructible<_Tuple, tuple>::value + && __tuple_convertible<_Tuple, tuple>::value; } template <class _Tuple> @@ -568,19 +572,20 @@ class _LIBCPP_TEMPLATE_VIS tuple // the UTypes... constructor should be selected instead. // See LWG issue #2549. template <class _Tuple> - using _PreferTupleLikeConstructor = __lazy_or< + using _PreferTupleLikeConstructor = _Or< // Don't attempt the two checks below if the tuple we are given // has the same type as this tuple. - is_same<typename __uncvref<_Tuple>::type, tuple>, - __lazy_and< - __lazy_not<is_constructible<_Tp..., _Tuple>>, - __lazy_not<is_convertible<_Tuple, _Tp...>> + _IsSame<__uncvref_t<_Tuple>, tuple>, + _Lazy<_And, + _Not<is_constructible<_Tp..., _Tuple>>, + _Not<is_convertible<_Tuple, _Tp...>> > >; template <class _Tuple> static constexpr bool __enable_implicit() { - return __lazy_and< + return _And< + __tuple_constructible<_Tuple, tuple>, __tuple_convertible<_Tuple, tuple>, _PreferTupleLikeConstructor<_Tuple> >::value; @@ -588,14 +593,33 @@ class _LIBCPP_TEMPLATE_VIS tuple template <class _Tuple> static constexpr bool __enable_explicit() { - return __lazy_and< + return _And< __tuple_constructible<_Tuple, tuple>, _PreferTupleLikeConstructor<_Tuple>, - __lazy_not<__tuple_convertible<_Tuple, tuple>> + _Not<__tuple_convertible<_Tuple, tuple>> >::value; } }; + template <class _Tuple, bool _DisableIfLValue> + using _EnableImplicitTupleLikeConstructor = _EnableIf< + _CheckTupleLikeConstructor< + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + && !_PackExpandsToThisTuple<_Tuple>::value + && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue) + >::template __enable_implicit<_Tuple>(), + bool + >; + + template <class _Tuple, bool _DisableIfLValue> + using _EnableExplicitTupleLikeConstructor = _EnableIf< + _CheckTupleLikeConstructor< + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + && !_PackExpandsToThisTuple<_Tuple>::value + && (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue) + >::template __enable_explicit<_Tuple>(), + bool + >; template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT; template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -616,12 +640,13 @@ public: tuple(tuple const&) = default; tuple(tuple&&) = default; - template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = typename enable_if< - __lazy_and< - is_same<allocator_arg_t, _AllocArgT>, - __lazy_all<__dependent_type<is_default_constructible<_Tp>, _Dummy>...> + template <class _AllocArgT, class _Alloc, bool _Dummy = true, class = _EnableIf< + _And< + _IsSame<allocator_arg_t, _AllocArgT>, + __dependent_type<is_default_constructible<_Tp>, _Dummy>... >::value - >::type> + > + > _LIBCPP_INLINE_VISIBILITY tuple(_AllocArgT, _Alloc const& __a) : __base_(allocator_arg_t(), __a, @@ -809,35 +834,27 @@ public: typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), _VSTD::forward<_Up>(__u)...) {} - template <class _Tuple, - typename enable_if - < - _CheckTupleLikeConstructor< - __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value - && !_PackExpandsToThisTuple<_Tuple>::value - >::template __enable_implicit<_Tuple>(), - bool - >::type = false - > + template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value)) : __base_(_VSTD::forward<_Tuple>(__t)) {} - template <class _Tuple, - typename enable_if - < - _CheckTupleLikeConstructor< - __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value - && !_PackExpandsToThisTuple<_Tuple>::value - >::template __enable_explicit<_Tuple>(), - bool - >::type = false - > + template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value)) + : __base_(__t) {} + template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value)) : __base_(_VSTD::forward<_Tuple>(__t)) {} + template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false> + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit + tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value)) + : __base_(__t) {} + template <class _Alloc, class _Tuple, typename enable_if < @@ -908,7 +925,7 @@ class _LIBCPP_TEMPLATE_VIS tuple<> { public: _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {} + _LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default; template <class _Alloc> _LIBCPP_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {} @@ -953,7 +970,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, tuple<_Tp...> >::type& get(tuple<_Tp...>& __t) _NOEXCEPT { - typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type; return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get(); } @@ -962,7 +979,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const typename tuple_element<_Ip, tuple<_Tp...> >::type& get(const tuple<_Tp...>& __t) _NOEXCEPT { - typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type; return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get(); } @@ -971,7 +988,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, tuple<_Tp...> >::type&& get(tuple<_Tp...>&& __t) _NOEXCEPT { - typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type; return static_cast<type&&>( static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get()); } @@ -981,7 +998,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const typename tuple_element<_Ip, tuple<_Tp...> >::type&& get(const tuple<_Tp...>&& __t) _NOEXCEPT { - typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type; return static_cast<const type&&>( static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get()); } @@ -1121,6 +1138,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { + static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); return __tuple_equal<sizeof...(_Tp)>()(__x, __y); } @@ -1164,6 +1182,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { + static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); return __tuple_less<sizeof...(_Tp)>()(__x, __y); } @@ -1198,7 +1217,7 @@ template <class _Tp, class _Up> struct __tuple_cat_type; template <class ..._Ttypes, class ..._Utypes> struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> > { - typedef tuple<_Ttypes..., _Utypes...> type; + typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type; }; template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples> @@ -1209,8 +1228,8 @@ struct __tuple_cat_return_1 template <class ..._Types, class _Tuple0> struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0> { - typedef typename __tuple_cat_type<tuple<_Types...>, - typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type>::type + typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>, + typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type type; }; @@ -1219,7 +1238,7 @@ struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples... : public __tuple_cat_return_1< typename __tuple_cat_type< tuple<_Types...>, - typename __make_tuple_types<typename remove_reference<_Tuple0>::type>::type + typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type >::type, __tuple_like<typename remove_reference<_Tuple1>::type>::value, _Tuple1, _Tuples...> @@ -1239,7 +1258,7 @@ struct __tuple_cat_return<_Tuple0, _Tuples...> template <> struct __tuple_cat_return<> { - typedef tuple<> type; + typedef _LIBCPP_NODEBUG_TYPE tuple<> type; }; inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 @@ -1255,7 +1274,7 @@ struct __tuple_cat_return_ref_imp; template <class ..._Types, size_t ..._I0, class _Tuple0> struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0> { - typedef typename remove_reference<_Tuple0>::type _T0; + typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0; typedef tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_I0, _T0>::type>::type&&...> type; }; @@ -1302,8 +1321,8 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls) { - typedef typename remove_reference<_Tuple0>::type _T0; - typedef typename remove_reference<_Tuple1>::type _T1; + typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0; + typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1; return __tuple_cat< tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>, typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type, @@ -1322,7 +1341,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename __tuple_cat_return<_Tuple0, _Tuples...>::type tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) { - typedef typename remove_reference<_Tuple0>::type _T0; + typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0; return __tuple_cat<tuple<>, __tuple_indices<>, typename __make_tuple_indices<tuple_size<_T0>::value>::type>() (tuple<>(), _VSTD::forward<_Tuple0>(__t0), diff --git a/include/type_traits b/include/type_traits index 8b30511a4ecb..5ccafec01f0b 100644 --- a/include/type_traits +++ b/include/type_traits @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------ type_traits ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -91,6 +90,9 @@ namespace std template <class T> struct remove_extent; template <class T> struct remove_all_extents; + template <class T> struct is_bounded_array; // C++20 + template <class T> struct is_unbounded_array; // C++20 + // Member introspection: template <class T> struct is_pod; template <class T> struct is_trivial; @@ -141,7 +143,10 @@ namespace std // Relationships between types: template <class T, class U> struct is_same; template <class Base, class Derived> struct is_base_of; + template <class From, class To> struct is_convertible; + template <typename From, typename To> struct is_nothrow_convertible; // C++20 + template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20 template <class Fn, class... ArgTypes> struct is_invocable; template <class R, class Fn, class... ArgTypes> struct is_invocable_r; @@ -197,6 +202,12 @@ namespace std template <class T> using remove_all_extents_t = typename remove_all_extents<T>::type; // C++14 + template <class T> + inline constexpr bool is_bounded_array_v + = is_bounded_array<T>::value; // C++20 + inline constexpr bool is_unbounded_array_v + = is_unbounded_array<T>::value; // C++20 + // pointer modifications: template <class T> using remove_pointer_t = typename remove_pointer<T>::type; // C++14 @@ -416,6 +427,96 @@ template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS pair; template <class _Tp> class _LIBCPP_TEMPLATE_VIS reference_wrapper; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash; + +template <class _Tp, _Tp __v> +struct _LIBCPP_TEMPLATE_VIS integral_constant +{ + static _LIBCPP_CONSTEXPR const _Tp value = __v; + typedef _Tp value_type; + typedef integral_constant type; + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;} +#if _LIBCPP_STD_VER > 11 + _LIBCPP_INLINE_VISIBILITY + constexpr value_type operator ()() const _NOEXCEPT {return value;} +#endif +}; + +template <class _Tp, _Tp __v> +_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value; + +#if _LIBCPP_STD_VER > 14 +template <bool __b> +using bool_constant = integral_constant<bool, __b>; +#define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)> +#else +#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)> +#endif + +typedef _LIBCPP_BOOL_CONSTANT(true) true_type; +typedef _LIBCPP_BOOL_CONSTANT(false) false_type; + +template <bool _Val> +using _BoolConstant _LIBCPP_NODEBUG_TYPE = integral_constant<bool, _Val>; + +template <bool> struct _MetaBase; +template <> +struct _MetaBase<true> { + template <class _Tp, class _Up> + using _SelectImpl _LIBCPP_NODEBUG_TYPE = _Tp; + template <template <class...> class _FirstFn, template <class...> class, class ..._Args> + using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE = _FirstFn<_Args...>; + template <class _First, class...> + using _FirstImpl _LIBCPP_NODEBUG_TYPE = _First; + template <class, class _Second, class...> + using _SecondImpl _LIBCPP_NODEBUG_TYPE = _Second; + template <class _Tp = void> + using _EnableIfImpl _LIBCPP_NODEBUG_TYPE = _Tp; + template <class _Result, class _First, class ..._Rest> + using _OrImpl _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>; + template <class _Result, class _First, class ..._Rest> + using _AndImpl _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_First::value == true && sizeof...(_Rest) != 0>::template _AndImpl<_First, _Rest...>; +}; + +template <> +struct _MetaBase<false> { + template <class _Tp, class _Up> + using _SelectImpl _LIBCPP_NODEBUG_TYPE = _Up; + template <template <class...> class, template <class...> class _SecondFn, class ..._Args> + using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE = _SecondFn<_Args...>; + template <class _Result, class ...> + using _OrImpl _LIBCPP_NODEBUG_TYPE = _Result; + template <class _Result, class ...> + using _AndImpl _LIBCPP_NODEBUG_TYPE = _Result; +}; +template <bool _Cond, class _Ret = void> +using _EnableIf _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_Cond>::template _EnableIfImpl<_Ret>; +template <bool _Cond, class _IfRes, class _ElseRes> +using _If _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>; +template <class ..._Rest> +using _Or _LIBCPP_NODEBUG_TYPE = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>; +template <class ..._Rest> +using _And _LIBCPP_NODEBUG_TYPE = typename _MetaBase< sizeof...(_Rest) != 0 >::template _AndImpl<true_type, _Rest...>; +template <class _Pred> +struct _Not : _BoolConstant<!_Pred::value> {}; +template <class ..._Args> +using _FirstType _LIBCPP_NODEBUG_TYPE = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>; +template <class ..._Args> +using _SecondType _LIBCPP_NODEBUG_TYPE = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>; + +template <template <class...> class _Func, class ..._Args> +struct _Lazy : _Func<_Args...> {}; + +// Member detector base + +template <template <class...> class _Templ, class ..._Args> +true_type __sfinae_test_impl(_FirstType<int, _Templ<_Args...> >); +template <template <class...> class, class ...> +false_type __sfinae_test_impl(...); + +template <template <class ...> class _Templ, class ..._Args> +using _IsValidExpansion _LIBCPP_NODEBUG_TYPE = decltype(std::__sfinae_test_impl<_Templ, _Args...>(0)); + template <class> struct __void_t { typedef void type; }; @@ -434,9 +535,6 @@ template <class _If, class _Then> template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type; #endif -template <bool, class _Tp> struct _LIBCPP_TEMPLATE_VIS __lazy_enable_if {}; -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __lazy_enable_if<true, _Tp> {typedef typename _Tp::type type;}; - template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {}; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;}; @@ -444,6 +542,34 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _ template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type; #endif +// is_same + +template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {}; + +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp, class _Up> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v + = is_same<_Tp, _Up>::value; +#endif + +template <class _Tp, class _Up> +using _IsSame = _BoolConstant< +#ifdef __clang__ + __is_same(_Tp, _Up) +#else + _VSTD::is_same<_Tp, _Up>::value +#endif +>; + +template <class _Tp, class _Up> +using _IsNotSame = _BoolConstant< +#ifdef __clang__ + !__is_same(_Tp, _Up) +#else + !_VSTD::is_same<_Tp, _Up>::value +#endif +>; // addressof #ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF @@ -517,111 +643,6 @@ struct __two {char __lx[2];}; // helper class: -template <class _Tp, _Tp __v> -struct _LIBCPP_TEMPLATE_VIS integral_constant -{ - static _LIBCPP_CONSTEXPR const _Tp value = __v; - typedef _Tp value_type; - typedef integral_constant type; - _LIBCPP_INLINE_VISIBILITY - _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;} -#if _LIBCPP_STD_VER > 11 - _LIBCPP_INLINE_VISIBILITY - constexpr value_type operator ()() const _NOEXCEPT {return value;} -#endif -}; - -template <class _Tp, _Tp __v> -_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value; - -#if _LIBCPP_STD_VER > 14 -template <bool __b> -using bool_constant = integral_constant<bool, __b>; -#define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)> -#else -#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)> -#endif - -typedef _LIBCPP_BOOL_CONSTANT(true) true_type; -typedef _LIBCPP_BOOL_CONSTANT(false) false_type; - -#if !defined(_LIBCPP_CXX03_LANG) - -// __lazy_and - -template <bool _Last, class ..._Preds> -struct __lazy_and_impl; - -template <class ..._Preds> -struct __lazy_and_impl<false, _Preds...> : false_type {}; - -template <> -struct __lazy_and_impl<true> : true_type {}; - -template <class _Pred> -struct __lazy_and_impl<true, _Pred> : integral_constant<bool, _Pred::type::value> {}; - -template <class _Hp, class ..._Tp> -struct __lazy_and_impl<true, _Hp, _Tp...> : __lazy_and_impl<_Hp::type::value, _Tp...> {}; - -template <class _P1, class ..._Pr> -struct __lazy_and : __lazy_and_impl<_P1::type::value, _Pr...> {}; - -// __lazy_or - -template <bool _List, class ..._Preds> -struct __lazy_or_impl; - -template <class ..._Preds> -struct __lazy_or_impl<true, _Preds...> : true_type {}; - -template <> -struct __lazy_or_impl<false> : false_type {}; - -template <class _Hp, class ..._Tp> -struct __lazy_or_impl<false, _Hp, _Tp...> - : __lazy_or_impl<_Hp::type::value, _Tp...> {}; - -template <class _P1, class ..._Pr> -struct __lazy_or : __lazy_or_impl<_P1::type::value, _Pr...> {}; - -// __lazy_not - -template <class _Pred> -struct __lazy_not : integral_constant<bool, !_Pred::type::value> {}; - -// __and_ -template<class...> struct __and_; -template<> struct __and_<> : true_type {}; - -template<class _B0> struct __and_<_B0> : _B0 {}; - -template<class _B0, class _B1> -struct __and_<_B0, _B1> : conditional<_B0::value, _B1, _B0>::type {}; - -template<class _B0, class _B1, class _B2, class... _Bn> -struct __and_<_B0, _B1, _B2, _Bn...> - : conditional<_B0::value, __and_<_B1, _B2, _Bn...>, _B0>::type {}; - -// __or_ -template<class...> struct __or_; -template<> struct __or_<> : false_type {}; - -template<class _B0> struct __or_<_B0> : _B0 {}; - -template<class _B0, class _B1> -struct __or_<_B0, _B1> : conditional<_B0::value, _B0, _B1>::type {}; - -template<class _B0, class _B1, class _B2, class... _Bn> -struct __or_<_B0, _B1, _B2, _Bn...> - : conditional<_B0::value, _B0, __or_<_B1, _B2, _Bn...> >::type {}; - -// __not_ -template<class _Tp> -struct __not_ : conditional<_Tp::value, false_type, true_type>::type {}; - -#endif // !defined(_LIBCPP_CXX03_LANG) - // is_const template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {}; @@ -774,8 +795,16 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v template <class _Tp> struct __libcpp_is_pointer : public false_type {}; template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {}; +template <class _Tp> struct __libcpp_remove_objc_qualifiers { typedef _Tp type; }; +#if defined(_LIBCPP_HAS_OBJC_ARC) +template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; }; +template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; }; +template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; }; +template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; }; +#endif + template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer - : public __libcpp_is_pointer<typename remove_cv<_Tp>::type> {}; + : public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<typename remove_cv<_Tp>::type>::type> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template <class _Tp> @@ -789,15 +818,11 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : pub template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {}; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : public false_type {}; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference<_Tp&&> : public true_type {}; -#endif template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference : public false_type {}; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&> : public true_type {}; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {}; -#endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template <class _Tp> @@ -814,7 +839,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v #endif // is_union -#if __has_feature(is_union) || (_GNUC_VER >= 403) +#if __has_feature(is_union) || defined(_LIBCPP_COMPILER_GCC) template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union : public integral_constant<bool, __is_union(_Tp)> {}; @@ -835,7 +860,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_union_v // is_class -#if __has_feature(is_class) || (_GNUC_VER >= 403) +#if __has_feature(is_class) || defined(_LIBCPP_COMPILER_GCC) template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class : public integral_constant<bool, __is_class(_Tp)> {}; @@ -859,17 +884,6 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_class_v = is_class<_Tp>::value; #endif -// is_same - -template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {}; -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {}; - -#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) -template <class _Tp, class _Up> -_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v - = is_same<_Tp, _Up>::value; -#endif - // is_function namespace __libcpp_is_function_imp @@ -957,7 +971,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v // is_enum -#if __has_feature(is_enum) || (_GNUC_VER >= 403) +#if __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC) template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum : public integral_constant<bool, __is_enum(_Tp)> {}; @@ -1061,7 +1075,7 @@ struct __is_referenceable_impl { template <class _Tp> struct __is_referenceable : integral_constant<bool, - !is_same<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {}; + _IsNotSame<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {}; // add_const @@ -1069,13 +1083,13 @@ struct __is_referenceable : integral_constant<bool, template <class _Tp, bool = is_reference<_Tp>::value || is_function<_Tp>::value || is_const<_Tp>::value > -struct __add_const {typedef _Tp type;}; +struct __add_const {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; template <class _Tp> -struct __add_const<_Tp, false> {typedef const _Tp type;}; +struct __add_const<_Tp, false> {typedef _LIBCPP_NODEBUG_TYPE const _Tp type;}; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const - {typedef typename __add_const<_Tp>::type type;}; + {typedef _LIBCPP_NODEBUG_TYPE typename __add_const<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 template <class _Tp> using add_const_t = typename add_const<_Tp>::type; @@ -1092,7 +1106,7 @@ template <class _Tp> struct __add_volatile<_Tp, false> {typedef volatile _Tp type;}; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile - {typedef typename __add_volatile<_Tp>::type type;}; + {typedef _LIBCPP_NODEBUG_TYPE typename __add_volatile<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type; @@ -1101,7 +1115,7 @@ template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type; // add_cv template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv - {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;}; + {typedef _LIBCPP_NODEBUG_TYPE typename add_const<typename add_volatile<_Tp>::type>::type type;}; #if _LIBCPP_STD_VER > 11 template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type; @@ -1109,11 +1123,9 @@ template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type; // remove_reference -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _Tp type;}; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _Tp type;}; -#endif +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; #if _LIBCPP_STD_VER > 11 template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type; @@ -1121,32 +1133,26 @@ template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>:: // add_lvalue_reference -template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _Tp type; }; -template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _Tp& type; }; +template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE _Tp type; }; +template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; }; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference -{typedef typename __add_lvalue_reference_impl<_Tp>::type type;}; +{typedef _LIBCPP_NODEBUG_TYPE typename __add_lvalue_reference_impl<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type; #endif -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - -template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _Tp type; }; -template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _Tp&& type; }; +template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE _Tp type; }; +template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE _Tp&& type; }; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference -{typedef typename __add_rvalue_reference_impl<_Tp>::type type;}; +{typedef _LIBCPP_NODEBUG_TYPE typename __add_rvalue_reference_impl<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type; #endif -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp> _Tp&& __declval(int); template <class _Tp> _Tp __declval(long); @@ -1154,35 +1160,27 @@ template <class _Tp> decltype(_VSTD::__declval<_Tp>(0)) declval() _NOEXCEPT; -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -template <class _Tp> -typename add_lvalue_reference<_Tp>::type -declval(); - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - // __uncvref template <class _Tp> struct __uncvref { - typedef typename remove_cv<typename remove_reference<_Tp>::type>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename remove_cv<typename remove_reference<_Tp>::type>::type type; }; template <class _Tp> struct __unconstref { - typedef typename remove_const<typename remove_reference<_Tp>::type>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename remove_const<typename remove_reference<_Tp>::type>::type type; }; #ifndef _LIBCPP_CXX03_LANG template <class _Tp> -using __uncvref_t = typename __uncvref<_Tp>::type; +using __uncvref_t _LIBCPP_NODEBUG_TYPE = typename __uncvref<_Tp>::type; #endif // __is_same_uncvref template <class _Tp, class _Up> -struct __is_same_uncvref : is_same<typename __uncvref<_Tp>::type, +struct __is_same_uncvref : _IsSame<typename __uncvref<_Tp>::type, typename __uncvref<_Up>::type> {}; #if _LIBCPP_STD_VER > 17 @@ -1201,11 +1199,11 @@ struct __any // remove_pointer -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {typedef _Tp type;}; -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; #if _LIBCPP_STD_VER > 11 template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type; @@ -1215,14 +1213,14 @@ template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type template <class _Tp, bool = __is_referenceable<_Tp>::value || - is_same<typename remove_cv<_Tp>::type, void>::value> + _IsSame<typename remove_cv<_Tp>::type, void>::value> struct __add_pointer_impl - {typedef typename remove_reference<_Tp>::type* type;}; + {typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type* type;}; template <class _Tp> struct __add_pointer_impl<_Tp, false> - {typedef _Tp type;}; + {typedef _LIBCPP_NODEBUG_TYPE _Tp type;}; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer - {typedef typename __add_pointer_impl<_Tp>::type type;}; + {typedef _LIBCPP_NODEBUG_TYPE typename __add_pointer_impl<_Tp>::type type;}; #if _LIBCPP_STD_VER > 11 template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type; @@ -1336,17 +1334,37 @@ template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_all_extents< template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type; #endif +#if _LIBCPP_STD_VER > 17 +// is_bounded_array + +template <class> struct _LIBCPP_TEMPLATE_VIS is_bounded_array : false_type {}; +template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {}; + +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR +bool is_bounded_array_v = is_bounded_array<_Tp>::value; + +// is_unbounded_array + +template <class> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array : false_type {}; +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {}; + +template <class _Tp> +_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR +bool is_unbounded_array_v = is_unbounded_array<_Tp>::value; +#endif + // decay template <class _Up, bool> struct __decay { - typedef typename remove_cv<_Up>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename remove_cv<_Up>::type type; }; template <class _Up> struct __decay<_Up, true> { public: - typedef typename conditional + typedef _LIBCPP_NODEBUG_TYPE typename conditional < is_array<_Up>::value, typename remove_extent<_Up>::type*, @@ -1363,9 +1381,9 @@ template <class _Tp> struct _LIBCPP_TEMPLATE_VIS decay { private: - typedef typename remove_reference<_Tp>::type _Up; + typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up; public: - typedef typename __decay<_Up, __is_referenceable<_Up>::value>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename __decay<_Up, __is_referenceable<_Up>::value>::type type; }; #if _LIBCPP_STD_VER > 11 @@ -1385,15 +1403,10 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_abstract_v // is_final -#if defined(_LIBCPP_HAS_IS_FINAL) template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {}; -#else -template <class _Tp> struct _LIBCPP_TEMPLATE_VIS -__libcpp_is_final : public false_type {}; -#endif -#if defined(_LIBCPP_HAS_IS_FINAL) && _LIBCPP_STD_VER > 11 +#if _LIBCPP_STD_VER > 11 template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_final : public integral_constant<bool, __is_final(_Tp)> {}; #endif @@ -1420,39 +1433,10 @@ _LIBCPP_INLINE_VAR constexpr bool is_aggregate_v // is_base_of -#ifdef _LIBCPP_HAS_IS_BASE_OF - template <class _Bp, class _Dp> struct _LIBCPP_TEMPLATE_VIS is_base_of : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {}; -#else // _LIBCPP_HAS_IS_BASE_OF - -namespace __is_base_of_imp -{ -template <class _Tp> -struct _Dst -{ - _Dst(const volatile _Tp &); -}; -template <class _Tp> -struct _Src -{ - operator const volatile _Tp &(); - template <class _Up> operator const _Dst<_Up> &(); -}; -template <size_t> struct __one { typedef char type; }; -template <class _Bp, class _Dp> typename __one<sizeof(_Dst<_Bp>(declval<_Src<_Dp> >()))>::type __test(int); -template <class _Bp, class _Dp> __two __test(...); -} - -template <class _Bp, class _Dp> -struct _LIBCPP_TEMPLATE_VIS is_base_of - : public integral_constant<bool, is_class<_Bp>::value && - sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {}; - -#endif // _LIBCPP_HAS_IS_BASE_OF - #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template <class _Bp, class _Dp> _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_base_of_v @@ -1509,14 +1493,6 @@ template <class _T1, class _T2, struct __is_convertible : public integral_constant<bool, __is_convertible_imp::__is_convertible_test<_T1, _T2>::value -#if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) - && !(!is_function<_T1>::value && !is_reference<_T1>::value && is_reference<_T2>::value - && (!is_const<typename remove_reference<_T2>::type>::value - || is_volatile<typename remove_reference<_T2>::type>::value) - && (is_same<typename remove_cv<_T1>::type, - typename remove_cv<typename remove_reference<_T2>::type>::type>::value - || is_base_of<typename remove_reference<_T2>::type, _T1>::value)) -#endif > {}; @@ -1550,9 +1526,35 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_convertible_v = is_convertible<_From, _To>::value; #endif +// is_nothrow_convertible + +#if _LIBCPP_STD_VER > 17 + +template <typename _Tp> +static void __test_noexcept(_Tp) noexcept; + +template<typename _Fm, typename _To> +static bool_constant<noexcept(__test_noexcept<_To>(declval<_Fm>()))> +__is_nothrow_convertible_test(); + +template <typename _Fm, typename _To> +struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>()) +{ }; + +template <typename _Fm, typename _To> +struct is_nothrow_convertible : _Or< + _And<is_void<_To>, is_void<_Fm>>, + _Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>> +>::type { }; + +template <typename _Fm, typename _To> +inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value; + +#endif // _LIBCPP_STD_VER > 17 + // is_empty -#if __has_feature(is_empty) || (_GNUC_VER >= 407) +#if __has_feature(is_empty) || defined(_LIBCPP_COMPILER_GCC) template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_empty @@ -1615,7 +1617,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_polymorphic_v // has_virtual_destructor -#if __has_feature(has_virtual_destructor) || (_GNUC_VER >= 403) +#if __has_feature(has_virtual_destructor) || defined(_LIBCPP_COMPILER_GCC) template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor : public integral_constant<bool, __has_virtual_destructor(_Tp)> {}; @@ -1703,6 +1705,9 @@ typedef __nat > > > > > > > > > > __all_types; +template <size_t _Align> +struct _ALIGNAS(_Align) __fallback_overaligned {}; + template <class _TL, size_t _Align> struct __find_pod; template <class _Hp, size_t _Align> @@ -1711,7 +1716,7 @@ struct __find_pod<__type_list<_Hp, __nat>, _Align> typedef typename conditional< _Align == _Hp::value, typename _Hp::type, - void + __fallback_overaligned<_Align> >::type type; }; @@ -1748,7 +1753,6 @@ template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::valu struct _LIBCPP_TEMPLATE_VIS aligned_storage { typedef typename __find_pod<__all_types, _Align>::type _Aligner; - static_assert(!is_void<_Aligner>::value, ""); union type { _Aligner __align; @@ -1792,7 +1796,6 @@ _CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000); #undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION -#ifndef _LIBCPP_HAS_NO_VARIADICS // aligned_union @@ -1826,8 +1829,6 @@ struct aligned_union template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type; #endif -#endif // _LIBCPP_HAS_NO_VARIADICS - template <class _Tp> struct __numeric_type { @@ -1844,7 +1845,7 @@ struct __numeric_type static long double __test(long double); typedef decltype(__test(declval<_Tp>())) type; - static const bool value = !is_same<type, void>::value; + static const bool value = _IsNotSame<type, void>::value; }; template <> @@ -1936,26 +1937,26 @@ template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeLi template <class _Hp, class _Tp, size_t _Size> struct __find_first<__type_list<_Hp, _Tp>, _Size, true> { - typedef _Hp type; + typedef _LIBCPP_NODEBUG_TYPE _Hp type; }; template <class _Hp, class _Tp, size_t _Size> struct __find_first<__type_list<_Hp, _Tp>, _Size, false> { - typedef typename __find_first<_Tp, _Size>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename __find_first<_Tp, _Size>::type type; }; template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value, bool = is_volatile<typename remove_reference<_Tp>::type>::value> struct __apply_cv { - typedef _Up type; + typedef _LIBCPP_NODEBUG_TYPE _Up type; }; template <class _Tp, class _Up> struct __apply_cv<_Tp, _Up, true, false> { - typedef const _Up type; + typedef _LIBCPP_NODEBUG_TYPE const _Up type; }; template <class _Tp, class _Up> @@ -2060,43 +2061,63 @@ struct _LIBCPP_TEMPLATE_VIS make_unsigned template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type; #endif -#ifdef _LIBCPP_HAS_NO_VARIADICS +template <class _Tp, class _Up, class = void> +struct __common_type2_imp {}; -template <class _Tp, class _Up = void, class _Vp = void> -struct _LIBCPP_TEMPLATE_VIS common_type +template <class _Tp, class _Up> +struct __common_type2_imp<_Tp, _Up, + typename __void_t<decltype( + true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>() + )>::type> { -public: - typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp>::type type; + typedef _LIBCPP_NODEBUG_TYPE typename decay<decltype( + true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>() + )>::type type; }; -template <> -struct _LIBCPP_TEMPLATE_VIS common_type<void, void, void> -{ -public: - typedef void type; -}; +template <class, class = void> +struct __common_type_impl {}; -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, void, void> -{ -public: - typedef typename common_type<_Tp, _Tp>::type type; -}; +// Clang provides variadic templates in C++03 as an extension. +#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__) +# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__ +template <class... Tp> +struct __common_types; +template <class... _Tp> +struct _LIBCPP_TEMPLATE_VIS common_type; +#else +# define _LIBCPP_OPTIONAL_PACK(...) +struct __no_arg; +template <class _Tp, class _Up, class = __no_arg> +struct __common_types; +template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg, + class _Unused = __no_arg> +struct common_type { + static_assert(sizeof(_Unused) == 0, + "common_type accepts at most 3 arguments in C++03"); +}; +#endif // _LIBCPP_CXX03_LANG template <class _Tp, class _Up> -struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up, void> +struct __common_type_impl< + __common_types<_Tp, _Up>, + typename __void_t<typename common_type<_Tp, _Up>::type>::type> { - typedef typename decay<decltype( - true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>() - )>::type type; + typedef typename common_type<_Tp, _Up>::type type; }; -#else // _LIBCPP_HAS_NO_VARIADICS +template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)> +struct __common_type_impl< + __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>, + typename __void_t<typename common_type<_Tp, _Up>::type>::type> + : __common_type_impl<__common_types<typename common_type<_Tp, _Up>::type, + _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > { +}; // bullet 1 - sizeof...(Tp) == 0 -template <class ..._Tp> -struct _LIBCPP_TEMPLATE_VIS common_type {}; +template <> +struct _LIBCPP_TEMPLATE_VIS common_type<> {}; // bullet 2 - sizeof...(Tp) == 1 @@ -2106,71 +2127,32 @@ struct _LIBCPP_TEMPLATE_VIS common_type<_Tp> // bullet 3 - sizeof...(Tp) == 2 -template <class _Tp, class _Up, class = void> -struct __common_type2_imp {}; - -template <class _Tp, class _Up> -struct __common_type2_imp<_Tp, _Up, - typename __void_t<decltype( - true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>() - )>::type> -{ - typedef typename decay<decltype( - true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>() - )>::type type; -}; - -template <class _Tp, class _Up, - class _DTp = typename decay<_Tp>::type, - class _DUp = typename decay<_Up>::type> -using __common_type2 = - typename conditional< - is_same<_Tp, _DTp>::value && is_same<_Up, _DUp>::value, - __common_type2_imp<_Tp, _Up>, - common_type<_DTp, _DUp> - >::type; - template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up> - : __common_type2<_Tp, _Up> {}; + : conditional< + _IsSame<_Tp, typename decay<_Tp>::type>::value && _IsSame<_Up, typename decay<_Up>::type>::value, + __common_type2_imp<_Tp, _Up>, + common_type<typename decay<_Tp>::type, typename decay<_Up>::type> + >::type +{}; // bullet 4 - sizeof...(Tp) > 2 -template <class ...Tp> struct __common_types; +template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)> +struct _LIBCPP_TEMPLATE_VIS + common_type<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> + : __common_type_impl< + __common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {}; -template <class, class = void> -struct __common_type_impl {}; - -template <class _Tp, class _Up> -struct __common_type_impl< - __common_types<_Tp, _Up>, - typename __void_t<typename common_type<_Tp, _Up>::type>::type> -{ - typedef typename common_type<_Tp, _Up>::type type; -}; - -template <class _Tp, class _Up, class ..._Vp> -struct __common_type_impl<__common_types<_Tp, _Up, _Vp...>, - typename __void_t<typename common_type<_Tp, _Up>::type>::type> - : __common_type_impl< - __common_types<typename common_type<_Tp, _Up>::type, _Vp...> > -{ - -}; - -template <class _Tp, class _Up, class ..._Vp> -struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up, _Vp...> - : __common_type_impl<__common_types<_Tp, _Up, _Vp...> > {}; +#undef _LIBCPP_OPTIONAL_PACK #if _LIBCPP_STD_VER > 11 template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type; #endif -#endif // _LIBCPP_HAS_NO_VARIADICS - // is_assignable -template<typename, typename _Tp> struct __select_2nd { typedef _Tp type; }; +template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG_TYPE _Tp type; }; template <class _Tp, class _Arg> typename __select_2nd<decltype((_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>())), true_type>::type @@ -2215,12 +2197,8 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_assignable_v // is_move_assignable template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES : public is_assignable<typename add_lvalue_reference<_Tp>::type, typename add_rvalue_reference<_Tp>::type> {}; -#else - : public is_copy_assignable<_Tp> {}; -#endif #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template <class _Tp> @@ -2294,14 +2272,12 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v // move -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename remove_reference<_Tp>::type&& move(_Tp&& __t) _NOEXCEPT { - typedef typename remove_reference<_Tp>::type _Up; + typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up; return static_cast<_Up&&>(__t); } @@ -2323,49 +2299,6 @@ forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT return static_cast<_Tp&&>(__t); } -#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_Tp& -move(_Tp& __t) -{ - return __t; -} - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -const _Tp& -move(const _Tp& __t) -{ - return __t; -} - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_Tp& -forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT -{ - return __t; -} - - -template <class _Tp> -class __rv -{ - typedef typename remove_reference<_Tp>::type _Trr; - _Trr& t_; -public: - _LIBCPP_INLINE_VISIBILITY - _Trr* operator->() {return &t_;} - _LIBCPP_INLINE_VISIBILITY - explicit __rv(_Trr& __t) : t_(__t) {} -}; - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY typename decay<_Tp>::type @@ -2374,20 +2307,6 @@ __decay_copy(_Tp&& __t) return _VSTD::forward<_Tp>(__t); } -#else - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -typename decay<_Tp>::type -__decay_copy(const _Tp& __t) -{ - return _VSTD::forward<_Tp>(__t); -} - -#endif - -#ifndef _LIBCPP_HAS_NO_VARIADICS - template <class _Rp, class _Class, class ..._Param> struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false> { @@ -2452,8 +2371,7 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatil typedef _Rp (_FnType) (_Param..., ...); }; -#if __has_feature(cxx_reference_qualified_functions) || \ - (defined(_GNUC_VER) && _GNUC_VER >= 409) +#if __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC) template <class _Rp, class _Class, class ..._Param> struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false> @@ -2583,267 +2501,8 @@ struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatil typedef _Rp (_FnType) (_Param..., ...); }; -#endif // __has_feature(cxx_reference_qualified_functions) || _GNUC_VER >= 409 - -#else // _LIBCPP_HAS_NO_VARIADICS - -template <class _Rp, class _Class> -struct __member_pointer_traits_imp<_Rp (_Class::*)(), true, false> -{ - typedef _Class _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (); -}; - -template <class _Rp, class _Class> -struct __member_pointer_traits_imp<_Rp (_Class::*)(...), true, false> -{ - typedef _Class _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (...); -}; - -template <class _Rp, class _Class, class _P0> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0), true, false> -{ - typedef _Class _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0); -}; - -template <class _Rp, class _Class, class _P0> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...), true, false> -{ - typedef _Class _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, ...); -}; - -template <class _Rp, class _Class, class _P0, class _P1> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1), true, false> -{ - typedef _Class _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1); -}; - -template <class _Rp, class _Class, class _P0, class _P1> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...), true, false> -{ - typedef _Class _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, ...); -}; - -template <class _Rp, class _Class, class _P0, class _P1, class _P2> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2), true, false> -{ - typedef _Class _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, _P2); -}; - -template <class _Rp, class _Class, class _P0, class _P1, class _P2> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...), true, false> -{ - typedef _Class _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, _P2, ...); -}; - -template <class _Rp, class _Class> -struct __member_pointer_traits_imp<_Rp (_Class::*)() const, true, false> -{ - typedef _Class const _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (); -}; - -template <class _Rp, class _Class> -struct __member_pointer_traits_imp<_Rp (_Class::*)(...) const, true, false> -{ - typedef _Class const _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (...); -}; - -template <class _Rp, class _Class, class _P0> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const, true, false> -{ - typedef _Class const _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0); -}; - -template <class _Rp, class _Class, class _P0> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const, true, false> -{ - typedef _Class const _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, ...); -}; - -template <class _Rp, class _Class, class _P0, class _P1> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const, true, false> -{ - typedef _Class const _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1); -}; - -template <class _Rp, class _Class, class _P0, class _P1> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const, true, false> -{ - typedef _Class const _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, ...); -}; - -template <class _Rp, class _Class, class _P0, class _P1, class _P2> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const, true, false> -{ - typedef _Class const _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, _P2); -}; - -template <class _Rp, class _Class, class _P0, class _P1, class _P2> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const, true, false> -{ - typedef _Class const _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, _P2, ...); -}; - -template <class _Rp, class _Class> -struct __member_pointer_traits_imp<_Rp (_Class::*)() volatile, true, false> -{ - typedef _Class volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (); -}; - -template <class _Rp, class _Class> -struct __member_pointer_traits_imp<_Rp (_Class::*)(...) volatile, true, false> -{ - typedef _Class volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (...); -}; - -template <class _Rp, class _Class, class _P0> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) volatile, true, false> -{ - typedef _Class volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0); -}; - -template <class _Rp, class _Class, class _P0> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) volatile, true, false> -{ - typedef _Class volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, ...); -}; - -template <class _Rp, class _Class, class _P0, class _P1> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) volatile, true, false> -{ - typedef _Class volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1); -}; - -template <class _Rp, class _Class, class _P0, class _P1> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) volatile, true, false> -{ - typedef _Class volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, ...); -}; - -template <class _Rp, class _Class, class _P0, class _P1, class _P2> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) volatile, true, false> -{ - typedef _Class volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, _P2); -}; - -template <class _Rp, class _Class, class _P0, class _P1, class _P2> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) volatile, true, false> -{ - typedef _Class volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, _P2, ...); -}; - -template <class _Rp, class _Class> -struct __member_pointer_traits_imp<_Rp (_Class::*)() const volatile, true, false> -{ - typedef _Class const volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (); -}; - -template <class _Rp, class _Class> -struct __member_pointer_traits_imp<_Rp (_Class::*)(...) const volatile, true, false> -{ - typedef _Class const volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (...); -}; - -template <class _Rp, class _Class, class _P0> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const volatile, true, false> -{ - typedef _Class const volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0); -}; - -template <class _Rp, class _Class, class _P0> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const volatile, true, false> -{ - typedef _Class const volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, ...); -}; - -template <class _Rp, class _Class, class _P0, class _P1> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const volatile, true, false> -{ - typedef _Class const volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1); -}; - -template <class _Rp, class _Class, class _P0, class _P1> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const volatile, true, false> -{ - typedef _Class const volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, ...); -}; - -template <class _Rp, class _Class, class _P0, class _P1, class _P2> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const volatile, true, false> -{ - typedef _Class const volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, _P2); -}; - -template <class _Rp, class _Class, class _P0, class _P1, class _P2> -struct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const volatile, true, false> -{ - typedef _Class const volatile _ClassType; - typedef _Rp _ReturnType; - typedef _Rp (_FnType) (_P0, _P1, _P2, ...); -}; +#endif // __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC) -#endif // _LIBCPP_HAS_NO_VARIADICS template <class _Rp, class _Class> struct __member_pointer_traits_imp<_Rp _Class::*, false, true> @@ -3042,10 +2701,10 @@ struct __is_invalid_base_to_derived_cast { static_assert(is_reference<_To>::value, "Wrong specialization"); using _RawFrom = __uncvref_t<_From>; using _RawTo = __uncvref_t<_To>; - static const bool value = __lazy_and< - __lazy_not<is_same<_RawFrom, _RawTo>>, + static const bool value = _And< + _IsNotSame<_RawFrom, _RawTo>, is_base_of<_RawFrom, _RawTo>, - __lazy_not<__libcpp_is_constructible<_RawTo, _From>> + _Not<__libcpp_is_constructible<_RawTo, _From>> >::value; }; @@ -3058,10 +2717,10 @@ template <class _ToRef, class _FromRef> struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> { using _RawFrom = __uncvref_t<_FromRef>; using _RawTo = __uncvref_t<_ToRef>; - static const bool value = __lazy_and< - __lazy_not<is_function<_RawTo>>, - __lazy_or< - is_same<_RawFrom, _RawTo>, + static const bool value = _And< + _Not<is_function<_RawTo>>, + _Or< + _IsSame<_RawFrom, _RawTo>, is_base_of<_RawTo, _RawFrom>> >::value; }; @@ -3152,241 +2811,13 @@ template <class _Tp, class ..._Args> struct _LIBCPP_TEMPLATE_VIS is_constructible : public integral_constant<bool, __is_constructible(_Tp, _Args...)> {}; -#elif !defined(_LIBCPP_CXX03_LANG) +#else template <class _Tp, class... _Args> struct _LIBCPP_TEMPLATE_VIS is_constructible : public __libcpp_is_constructible<_Tp, _Args...>::type {}; -#else -// template <class T> struct is_constructible0; - -// main is_constructible0 test - -template <class _Tp> -decltype((_Tp(), true_type())) -__is_constructible0_test(_Tp&); - -false_type -__is_constructible0_test(__any); - -template <class _Tp, class _A0> -decltype((_Tp(_VSTD::declval<_A0>()), true_type())) -__is_constructible1_test(_Tp&, _A0&); - -template <class _A0> -false_type -__is_constructible1_test(__any, _A0&); - -template <class _Tp, class _A0, class _A1> -decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>()), true_type())) -__is_constructible2_test(_Tp&, _A0&, _A1&); - -template <class _A0, class _A1> -false_type -__is_constructible2_test(__any, _A0&, _A1&); - -template <class _Tp, class _A0, class _A1, class _A2> -decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>(), _VSTD::declval<_A2>()), true_type())) -__is_constructible3_test(_Tp&, _A0&, _A1&, _A2&); - -template <class _A0, class _A1, class _A2> -false_type -__is_constructible3_test(__any, _A0&, _A1&, _A2&); - -template <bool, class _Tp> -struct __is_constructible0_imp // false, _Tp is not a scalar - : public common_type - < - decltype(__is_constructible0_test(declval<_Tp&>())) - >::type - {}; - -template <bool, class _Tp, class _A0> -struct __is_constructible1_imp // false, _Tp is not a scalar - : public common_type - < - decltype(__is_constructible1_test(declval<_Tp&>(), declval<_A0&>())) - >::type - {}; - -template <bool, class _Tp, class _A0, class _A1> -struct __is_constructible2_imp // false, _Tp is not a scalar - : public common_type - < - decltype(__is_constructible2_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>())) - >::type - {}; - -template <bool, class _Tp, class _A0, class _A1, class _A2> -struct __is_constructible3_imp // false, _Tp is not a scalar - : public common_type - < - decltype(__is_constructible3_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>(), declval<_A2>())) - >::type - {}; - -// handle scalars and reference types - -// Scalars are default constructible, references are not - -template <class _Tp> -struct __is_constructible0_imp<true, _Tp> - : public is_scalar<_Tp> - {}; - -template <class _Tp, class _A0> -struct __is_constructible1_imp<true, _Tp, _A0> - : public is_convertible<_A0, _Tp> - {}; - -template <class _Tp, class _A0, class _A1> -struct __is_constructible2_imp<true, _Tp, _A0, _A1> - : public false_type - {}; - -template <class _Tp, class _A0, class _A1, class _A2> -struct __is_constructible3_imp<true, _Tp, _A0, _A1, _A2> - : public false_type - {}; - -// Treat scalars and reference types separately - -template <bool, class _Tp> -struct __is_constructible0_void_check - : public __is_constructible0_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, - _Tp> - {}; - -template <bool, class _Tp, class _A0> -struct __is_constructible1_void_check - : public __is_constructible1_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, - _Tp, _A0> - {}; - -template <bool, class _Tp, class _A0, class _A1> -struct __is_constructible2_void_check - : public __is_constructible2_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, - _Tp, _A0, _A1> - {}; - -template <bool, class _Tp, class _A0, class _A1, class _A2> -struct __is_constructible3_void_check - : public __is_constructible3_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value, - _Tp, _A0, _A1, _A2> - {}; - -// If any of T or Args is void, is_constructible should be false - -template <class _Tp> -struct __is_constructible0_void_check<true, _Tp> - : public false_type - {}; - -template <class _Tp, class _A0> -struct __is_constructible1_void_check<true, _Tp, _A0> - : public false_type - {}; - -template <class _Tp, class _A0, class _A1> -struct __is_constructible2_void_check<true, _Tp, _A0, _A1> - : public false_type - {}; - -template <class _Tp, class _A0, class _A1, class _A2> -struct __is_constructible3_void_check<true, _Tp, _A0, _A1, _A2> - : public false_type - {}; - -// is_constructible entry point - -template <class _Tp, class _A0 = __is_construct::__nat, - class _A1 = __is_construct::__nat, - class _A2 = __is_construct::__nat> -struct _LIBCPP_TEMPLATE_VIS is_constructible - : public __is_constructible3_void_check<is_void<_Tp>::value - || is_abstract<_Tp>::value - || is_function<_Tp>::value - || is_void<_A0>::value - || is_void<_A1>::value - || is_void<_A2>::value, - _Tp, _A0, _A1, _A2> - {}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat> - : public __is_constructible0_void_check<is_void<_Tp>::value - || is_abstract<_Tp>::value - || is_function<_Tp>::value, - _Tp> - {}; - -template <class _Tp, class _A0> -struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, _A0, __is_construct::__nat> - : public __is_constructible1_void_check<is_void<_Tp>::value - || is_abstract<_Tp>::value - || is_function<_Tp>::value - || is_void<_A0>::value, - _Tp, _A0> - {}; - -template <class _Tp, class _A0, class _A1> -struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, _A0, _A1, __is_construct::__nat> - : public __is_constructible2_void_check<is_void<_Tp>::value - || is_abstract<_Tp>::value - || is_function<_Tp>::value - || is_void<_A0>::value - || is_void<_A1>::value, - _Tp, _A0, _A1> - {}; - -// Array types are default constructible if their element type -// is default constructible - -template <class _Ap, size_t _Np> -struct __is_constructible0_imp<false, _Ap[_Np]> - : public is_constructible<typename remove_all_extents<_Ap>::type> - {}; - -template <class _Ap, size_t _Np, class _A0> -struct __is_constructible1_imp<false, _Ap[_Np], _A0> - : public false_type - {}; - -template <class _Ap, size_t _Np, class _A0, class _A1> -struct __is_constructible2_imp<false, _Ap[_Np], _A0, _A1> - : public false_type - {}; - -template <class _Ap, size_t _Np, class _A0, class _A1, class _A2> -struct __is_constructible3_imp<false, _Ap[_Np], _A0, _A1, _A2> - : public false_type - {}; - -// Incomplete array types are not constructible - -template <class _Ap> -struct __is_constructible0_imp<false, _Ap[]> - : public false_type - {}; - -template <class _Ap, class _A0> -struct __is_constructible1_imp<false, _Ap[], _A0> - : public false_type - {}; - -template <class _Ap, class _A0, class _A1> -struct __is_constructible2_imp<false, _Ap[], _A0, _A1> - : public false_type - {}; - -template <class _Ap, class _A0, class _A1, class _A2> -struct __is_constructible3_imp<false, _Ap[], _A0, _A1, _A2> - : public false_type - {}; - -#endif // __has_feature(is_constructible) - +#endif -#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template <class _Tp, class ..._Args> _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_constructible_v = is_constructible<_Tp, _Args...>::value; @@ -3422,11 +2853,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_constructible_v template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_constructible -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type> -#else - : public is_copy_constructible<_Tp> -#endif {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) @@ -3437,8 +2864,6 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_constructible_v // is_trivially_constructible -#ifndef _LIBCPP_HAS_NO_VARIADICS - #if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501 template <class _Tp, class... _Args> @@ -3457,7 +2882,7 @@ struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp> -#if __has_feature(has_trivial_constructor) || (_GNUC_VER >= 403) +#if __has_feature(has_trivial_constructor) || defined(_LIBCPP_COMPILER_GCC) : integral_constant<bool, __has_trivial_constructor(_Tp)> #else : integral_constant<bool, is_scalar<_Tp>::value> @@ -3466,11 +2891,7 @@ struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp> }; template <class _Tp> -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&&> -#else -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp> -#endif : integral_constant<bool, is_scalar<_Tp>::value> { }; @@ -3489,80 +2910,8 @@ struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&> #endif // !__has_feature(is_trivially_constructible) -#else // _LIBCPP_HAS_NO_VARIADICS - -template <class _Tp, class _A0 = __is_construct::__nat, - class _A1 = __is_construct::__nat> -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible - : false_type -{ -}; - -#if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501 - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, __is_construct::__nat, - __is_construct::__nat> - : integral_constant<bool, __is_trivially_constructible(_Tp)> -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp, - __is_construct::__nat> - : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)> -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&, - __is_construct::__nat> - : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)> -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&, - __is_construct::__nat> - : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)> -{ -}; - -#else // !__has_feature(is_trivially_constructible) - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, __is_construct::__nat, - __is_construct::__nat> - : integral_constant<bool, is_scalar<_Tp>::value> -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp, - __is_construct::__nat> - : integral_constant<bool, is_scalar<_Tp>::value> -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&, - __is_construct::__nat> - : integral_constant<bool, is_scalar<_Tp>::value> -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&, - __is_construct::__nat> - : integral_constant<bool, is_scalar<_Tp>::value> -{ -}; - -#endif // !__has_feature(is_trivially_constructible) - -#endif // _LIBCPP_HAS_NO_VARIADICS -#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template <class _Tp, class... _Args> _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_constructible_v = is_trivially_constructible<_Tp, _Args...>::value; @@ -3595,11 +2944,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v // is_trivially_move_constructible template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type> -#else - : public is_trivially_copy_constructible<_Tp> -#endif {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) @@ -3636,14 +2981,10 @@ template <class _Tp> struct is_trivially_assignable<_Tp&, const _Tp&> : integral_constant<bool, is_scalar<_Tp>::value> {}; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp> struct is_trivially_assignable<_Tp&, _Tp&&> : integral_constant<bool, is_scalar<_Tp>::value> {}; -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - #endif // !__has_feature(is_trivially_assignable) #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) @@ -3668,11 +3009,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type, -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES typename add_rvalue_reference<_Tp>::type> -#else - typename add_lvalue_reference<_Tp>::type> -#endif {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) @@ -3683,7 +3020,12 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v // is_trivially_destructible -#if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403) +#if __has_keyword(__is_trivially_destructible) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible + : public integral_constant<bool, __is_trivially_destructible(_Tp)> {}; + +#elif __has_feature(has_trivial_destructor) || defined(_LIBCPP_COMPILER_GCC) template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {}; @@ -3710,19 +3052,14 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_destructible_v // is_nothrow_constructible -#if 0 +#if __has_keyword(__is_nothrow_constructible) + template <class _Tp, class... _Args> struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible - : public integral_constant<bool, __is_nothrow_constructible(_Tp(_Args...))> -{ -}; + : public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {}; #else -#ifndef _LIBCPP_HAS_NO_VARIADICS - -#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) - template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible; template <class _Tp, class... _Args> @@ -3758,117 +3095,10 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]> { }; -#else // __has_feature(cxx_noexcept) +#endif // _LIBCPP_HAS_NO_NOEXCEPT -template <class _Tp, class... _Args> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible - : false_type -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp> -#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_constructor(_Tp)> -#else - : integral_constant<bool, is_scalar<_Tp>::value> -#endif -{ -}; -template <class _Tp> -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&&> -#else -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp> -#endif -#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_copy(_Tp)> -#else - : integral_constant<bool, is_scalar<_Tp>::value> -#endif -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, const _Tp&> -#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_copy(_Tp)> -#else - : integral_constant<bool, is_scalar<_Tp>::value> -#endif -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&> -#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_copy(_Tp)> -#else - : integral_constant<bool, is_scalar<_Tp>::value> -#endif -{ -}; - -#endif // __has_feature(cxx_noexcept) - -#else // _LIBCPP_HAS_NO_VARIADICS - -template <class _Tp, class _A0 = __is_construct::__nat, - class _A1 = __is_construct::__nat> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible - : false_type -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, __is_construct::__nat, - __is_construct::__nat> -#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_constructor(_Tp)> -#else - : integral_constant<bool, is_scalar<_Tp>::value> -#endif -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp, - __is_construct::__nat> -#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_copy(_Tp)> -#else - : integral_constant<bool, is_scalar<_Tp>::value> -#endif -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, const _Tp&, - __is_construct::__nat> -#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_copy(_Tp)> -#else - : integral_constant<bool, is_scalar<_Tp>::value> -#endif -{ -}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp, _Tp&, - __is_construct::__nat> -#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_copy(_Tp)> -#else - : integral_constant<bool, is_scalar<_Tp>::value> -#endif -{ -}; - -#endif // _LIBCPP_HAS_NO_VARIADICS -#endif // __has_feature(is_nothrow_constructible) - -#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) && !defined(_LIBCPP_HAS_NO_VARIADICS) +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template <class _Tp, class ..._Args> _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp, _Args...>::value; @@ -3901,11 +3131,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v // is_nothrow_move_constructible template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type> -#else - : public is_nothrow_copy_constructible<_Tp> -#endif {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) @@ -3916,7 +3142,13 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_constructible_v // is_nothrow_assignable -#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) +#if __has_keyword(__is_nothrow_assignable) + +template <class _Tp, class _Arg> +struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable + : public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {}; + +#else template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable; @@ -3938,49 +3170,7 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable { }; -#else // __has_feature(cxx_noexcept) - -template <class _Tp, class _Arg> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable - : public false_type {}; - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, _Tp> -#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; -#else - : integral_constant<bool, is_scalar<_Tp>::value> {}; -#endif - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, _Tp&> -#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; -#else - : integral_constant<bool, is_scalar<_Tp>::value> {}; -#endif - -template <class _Tp> -struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable<_Tp&, const _Tp&> -#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; -#else - : integral_constant<bool, is_scalar<_Tp>::value> {}; -#endif - -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - -template <class _Tp> -struct is_nothrow_assignable<_Tp&, _Tp&&> -#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403) - : integral_constant<bool, __has_nothrow_assign(_Tp)> {}; -#else - : integral_constant<bool, is_scalar<_Tp>::value> {}; -#endif - -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - -#endif // __has_feature(cxx_noexcept) +#endif // _LIBCPP_HAS_NO_NOEXCEPT #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) template <class _Tp, class _Arg> @@ -4004,11 +3194,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type, -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES typename add_rvalue_reference<_Tp>::type> -#else - typename add_lvalue_reference<_Tp>::type> -#endif {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) @@ -4019,7 +3205,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v // is_nothrow_destructible -#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L) +#if !defined(_LIBCPP_CXX03_LANG) template <bool, class _Tp> struct __libcpp_is_nothrow_destructible; @@ -4053,16 +3239,12 @@ struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&> { }; -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&> : public true_type { }; -#endif - #else template <class _Tp> struct __libcpp_nothrow_destructor @@ -4086,7 +3268,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v // is_pod -#if __has_feature(is_pod) || (_GNUC_VER >= 403) +#if __has_feature(is_pod) || defined(_LIBCPP_COMPILER_GCC) template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod : public integral_constant<bool, __is_pod(_Tp)> {}; @@ -4110,12 +3292,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pod_v // is_literal_type; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_literal_type -#ifdef _LIBCPP_IS_LITERAL - : public integral_constant<bool, _LIBCPP_IS_LITERAL(_Tp)> -#else - : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value || - is_reference<typename remove_all_extents<_Tp>::type>::value> -#endif + : public integral_constant<bool, __is_literal_type(_Tp)> {}; #if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) @@ -4127,7 +3304,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_literal_type_v // is_standard_layout; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout -#if __has_feature(is_standard_layout) || (_GNUC_VER >= 407) +#if __has_feature(is_standard_layout) || defined(_LIBCPP_COMPILER_GCC) : public integral_constant<bool, __is_standard_layout(_Tp)> #else : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value> @@ -4161,7 +3338,7 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copyable_v // is_trivial; template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial -#if __has_feature(is_trivial) || _GNUC_VER >= 407 +#if __has_feature(is_trivial) || defined(_LIBCPP_COMPILER_GCC) : public integral_constant<bool, __is_trivial(_Tp)> #else : integral_constant<bool, is_trivially_copyable<_Tp>::value && @@ -4361,28 +3538,31 @@ _LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...) #undef _LIBCPP_INVOKE_RETURN // __invokable - template <class _Ret, class _Fp, class ..._Args> struct __invokable_r { - // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void, - // or incomplete array types as required by the standard. - using _Result = decltype( - _VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)); + template <class _XFp, class ..._XArgs> + static auto __try_call(int) -> decltype( + _VSTD::__invoke(_VSTD::declval<_XFp>(), _VSTD::declval<_XArgs>()...)); + template <class _XFp, class ..._XArgs> + static __nat __try_call(...); - using type = - typename conditional< - !is_same<_Result, __nat>::value, - typename conditional< - is_void<_Ret>::value, - true_type, - is_convertible<_Result, _Ret> - >::type, - false_type - >::type; - static const bool value = type::value; -}; + // FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void, + // or incomplete array types as required by the standard. + using _Result = decltype(__try_call<_Fp, _Args...>(0)); + using type = + typename conditional< + _IsNotSame<_Result, __nat>::value, + typename conditional< + is_void<_Ret>::value, + true_type, + is_convertible<_Result, _Ret> + >::type, + false_type + >::type; + static const bool value = type::value; +}; template <class _Fp, class ..._Args> using __invokable = __invokable_r<void, _Fp, _Args...>; @@ -4512,6 +3692,7 @@ typename enable_if #else void #endif +_LIBCPP_CONSTEXPR_AFTER_CXX17 swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value && is_nothrow_move_assignable<_Tp>::value) { @@ -4521,14 +3702,14 @@ swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value && } template<class _Tp, size_t _Np> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if< __is_swappable<_Tp>::value >::type swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value); template <class _ForwardIterator1, class _ForwardIterator2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) // _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b))) @@ -4558,8 +3739,8 @@ struct __swappable_with typedef decltype((__test_swap<_Tp, _Up>(0))) __swap1; typedef decltype((__test_swap<_Up, _Tp>(0))) __swap2; - static const bool value = !is_same<__swap1, __nat>::value - && !is_same<__swap2, __nat>::value; + static const bool value = _IsNotSame<__swap1, __nat>::value + && _IsNotSame<__swap2, __nat>::value; }; template <class _Tp, class _Up> @@ -4649,30 +3830,24 @@ _LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_v #endif // _LIBCPP_STD_VER > 14 -#ifdef _LIBCPP_UNDERLYING_TYPE +template <class _Tp, bool = is_enum<_Tp>::value> struct __underlying_type_impl; template <class _Tp> -struct underlying_type +struct __underlying_type_impl<_Tp, false> {}; + +template <class _Tp> +struct __underlying_type_impl<_Tp, true> { - typedef _LIBCPP_UNDERLYING_TYPE(_Tp) type; + typedef __underlying_type(_Tp) type; }; +template <class _Tp> +struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {}; + #if _LIBCPP_STD_VER > 11 template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type; #endif -#else // _LIBCPP_UNDERLYING_TYPE - -template <class _Tp, bool _Support = false> -struct underlying_type -{ - static_assert(_Support, "The underyling_type trait requires compiler " - "support. Either no such support exists or " - "libc++ does not know how to use it."); -}; - -#endif // _LIBCPP_UNDERLYING_TYPE - template <class _Tp, bool = is_enum<_Tp>::value> struct __sfinae_underlying_type @@ -4758,25 +3933,23 @@ struct __has_operator_addressof template <class...> using void_t = void; -# ifndef _LIBCPP_HAS_NO_VARIADICS template <class... _Args> -struct conjunction : __and_<_Args...> {}; +struct conjunction : _And<_Args...> {}; template<class... _Args> _LIBCPP_INLINE_VAR constexpr bool conjunction_v = conjunction<_Args...>::value; template <class... _Args> -struct disjunction : __or_<_Args...> {}; +struct disjunction : _Or<_Args...> {}; template<class... _Args> _LIBCPP_INLINE_VAR constexpr bool disjunction_v = disjunction<_Args...>::value; template <class _Tp> -struct negation : __not_<_Tp> {}; +struct negation : _Not<_Tp> {}; template<class _Tp> _LIBCPP_INLINE_VAR constexpr bool negation_v = negation<_Tp>::value; -# endif // _LIBCPP_HAS_NO_VARIADICS #endif // _LIBCPP_STD_VER > 14 // These traits are used in __tree and __hash_table @@ -4788,12 +3961,12 @@ struct __extract_key_first_tag {}; template <class _ValTy, class _Key, class _RawValTy = typename __unconstref<_ValTy>::type> struct __can_extract_key - : conditional<is_same<_RawValTy, _Key>::value, __extract_key_self_tag, + : conditional<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag, __extract_key_fail_tag>::type {}; template <class _Pair, class _Key, class _First, class _Second> struct __can_extract_key<_Pair, _Key, pair<_First, _Second>> - : conditional<is_same<typename remove_const<_First>::type, _Key>::value, + : conditional<_IsSame<typename remove_const<_First>::type, _Key>::value, __extract_key_first_tag, __extract_key_fail_tag>::type {}; // __can_extract_map_key uses true_type/false_type instead of the tags. @@ -4802,7 +3975,7 @@ struct __can_extract_key<_Pair, _Key, pair<_First, _Second>> template <class _ValTy, class _Key, class _ContainerValueTy, class _RawValTy = typename __unconstref<_ValTy>::type> struct __can_extract_map_key - : integral_constant<bool, is_same<_RawValTy, _Key>::value> {}; + : integral_constant<bool, _IsSame<_RawValTy, _Key>::value> {}; // This specialization returns __extract_key_fail_tag for non-map containers // because _Key == _ContainerValueTy @@ -4827,6 +4000,24 @@ enum class endian }; #endif +#ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED +#if _LIBCPP_STD_VER > 17 +_LIBCPP_INLINE_VISIBILITY +inline constexpr bool is_constant_evaluated() noexcept { + return __builtin_is_constant_evaluated(); +} +#endif + +inline _LIBCPP_CONSTEXPR +bool __libcpp_is_constant_evaluated() _NOEXCEPT { return __builtin_is_constant_evaluated(); } +#else +inline _LIBCPP_CONSTEXPR +bool __libcpp_is_constant_evaluated() _NOEXCEPT { return false; } +#endif + +template <class _CharT> +using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >; + _LIBCPP_END_NAMESPACE_STD #if _LIBCPP_STD_VER > 14 diff --git a/include/typeindex b/include/typeindex index 0565ca913e33..bff1e65af944 100644 --- a/include/typeindex +++ b/include/typeindex @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- typeindex ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/typeinfo b/include/typeinfo index 8411532860bd..27601769a83b 100644 --- a/include/typeinfo +++ b/include/typeinfo @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- typeinfo ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -69,59 +68,32 @@ public: #pragma GCC system_header #endif -#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +#if defined(_LIBCPP_ABI_VCRUNTIME) #include <vcruntime_typeinfo.h> #else -#if defined(_LIBCPP_NONUNIQUE_RTTI_BIT) && !defined(_LIBCPP_ABI_MICROSOFT) -# define _LIBCPP_HAS_NONUNIQUE_TYPEINFO -#endif - namespace std // purposefully not using versioning namespace { + +#if defined(_LIBCPP_ABI_MICROSOFT) + class _LIBCPP_EXCEPTION_ABI type_info { type_info& operator=(const type_info&); type_info(const type_info&); -#if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO) - _LIBCPP_INLINE_VISIBILITY - int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT - { return __builtin_strcmp(name(), __arg.name()); } -#endif - -#if defined(_LIBCPP_ABI_MICROSOFT) mutable struct { const char *__undecorated_name; const char __decorated_name[1]; } __data; int __compare(const type_info &__rhs) const _NOEXCEPT; -#endif // _LIBCPP_ABI_MICROSOFT - -protected: -#if !defined(_LIBCPP_ABI_MICROSOFT) -#if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO) - // A const char* with the non-unique RTTI bit possibly set. - uintptr_t __type_name; - - _LIBCPP_INLINE_VISIBILITY - explicit type_info(const char* __n) - : __type_name(reinterpret_cast<uintptr_t>(__n)) {} -#else - const char *__type_name; - - _LIBCPP_INLINE_VISIBILITY - explicit type_info(const char* __n) : __type_name(__n) {} -#endif -#endif // ! _LIBCPP_ABI_MICROSOFT public: _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE virtual ~type_info(); -#if defined(_LIBCPP_ABI_MICROSOFT) const char *name() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY @@ -135,91 +107,233 @@ public: bool operator==(const type_info& __arg) const _NOEXCEPT { return __compare(__arg) == 0; } -#else -#if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO) - _LIBCPP_INLINE_VISIBILITY - const char* name() const _NOEXCEPT - { - return reinterpret_cast<const char*>(__type_name & - ~_LIBCPP_NONUNIQUE_RTTI_BIT); - } _LIBCPP_INLINE_VISIBILITY - bool before(const type_info& __arg) const _NOEXCEPT - { - if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT)) - return __type_name < __arg.__type_name; - return __compare_nonunique_names(__arg) < 0; + bool operator!=(const type_info& __arg) const _NOEXCEPT + { return !operator==(__arg); } +}; + +#else // !defined(_LIBCPP_ABI_MICROSOFT) + +// ========================================================================== // +// Implementations +// ========================================================================== // +// ------------------------------------------------------------------------- // +// Unique +// ------------------------------------------------------------------------- // +// This implementation of type_info assumes a unique copy of the RTTI for a +// given type inside a program. This is a valid assumption when abiding to +// Itanium ABI (http://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-components). +// Under this assumption, we can always compare the addresses of the type names +// to implement equality-comparison of type_infos instead of having to perform +// a deep string comparison. +// -------------------------------------------------------------------------- // +// NonUnique +// -------------------------------------------------------------------------- // +// This implementation of type_info does not assume there is always a unique +// copy of the RTTI for a given type inside a program. For various reasons +// the linker may have failed to merge every copy of a types RTTI +// (For example: -Bsymbolic or llvm.org/PR37398). Under this assumption, two +// type_infos are equal if their addresses are equal or if a deep string +// comparison is equal. +// -------------------------------------------------------------------------- // +// NonUniqueARMRTTIBit +// -------------------------------------------------------------------------- // +// This implementation of type_info does not assume always a unique copy of +// the RTTI for a given type inside a program. It packs the pointer to the +// type name into a uintptr_t and reserves the high bit of that pointer (which +// is assumed to be free for use under the ABI in use) to represent whether +// that specific copy of the RTTI can be assumed unique inside the program. +// To implement equality-comparison of type_infos, we check whether BOTH +// type_infos are guaranteed unique, and if so, we simply compare the addresses +// of their type names instead of doing a deep string comparison, which is +// faster. If at least one of the type_infos can't guarantee uniqueness, we +// have no choice but to fall back to a deep string comparison. +// +// This implementation is specific to ARM64 on Apple platforms. +// +// Note that the compiler is the one setting (or unsetting) the high bit of +// the pointer when it constructs the type_info, depending on whether it can +// guarantee uniqueness for that specific type_info. + +struct __type_info_implementations { + struct __string_impl_base { + typedef const char* __type_name_t; + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + _LIBCPP_CONSTEXPR static const char* __type_name_to_string(__type_name_t __v) _NOEXCEPT { + return __v; } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + _LIBCPP_CONSTEXPR static __type_name_t __string_to_type_name(const char* __v) _NOEXCEPT { + return __v; + } + }; - _LIBCPP_INLINE_VISIBILITY - size_t hash_code() const _NOEXCEPT - { - if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT)) - return __type_name; + struct __unique_impl : __string_impl_base { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static size_t __hash(__type_name_t __v) _NOEXCEPT { + return reinterpret_cast<size_t>(__v); + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static bool __eq(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT { + return __lhs == __rhs; + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static bool __lt(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT { + return __lhs < __rhs; + } + }; - const char* __ptr = name(); + struct __non_unique_impl : __string_impl_base { + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static size_t __hash(__type_name_t __ptr) _NOEXCEPT { size_t __hash = 5381; while (unsigned char __c = static_cast<unsigned char>(*__ptr++)) __hash = (__hash * 33) ^ __c; return __hash; } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static bool __eq(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT { + return __lhs == __rhs || __builtin_strcmp(__lhs, __rhs) == 0; + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static bool __lt(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT { + return __builtin_strcmp(__lhs, __rhs) < 0; + } + }; - _LIBCPP_INLINE_VISIBILITY - bool operator==(const type_info& __arg) const _NOEXCEPT - { - if (__type_name == __arg.__type_name) - return true; + struct __non_unique_arm_rtti_bit_impl { + typedef uintptr_t __type_name_t; + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static const char* __type_name_to_string(__type_name_t __v) _NOEXCEPT { + return reinterpret_cast<const char*>(__v & + ~__non_unique_rtti_bit::value); + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static __type_name_t __string_to_type_name(const char* __v) _NOEXCEPT { + return reinterpret_cast<__type_name_t>(__v); + } - if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT)) + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static size_t __hash(__type_name_t __v) _NOEXCEPT { + if (__is_type_name_unique(__v)) + return reinterpret_cast<size_t>(__v); + return __non_unique_impl::__hash(__type_name_to_string(__v)); + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static bool __eq(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT { + if (__lhs == __rhs) + return true; + if (__is_type_name_unique(__lhs, __rhs)) return false; - return __compare_nonunique_names(__arg) == 0; + return __builtin_strcmp(__type_name_to_string(__lhs), __type_name_to_string(__rhs)) == 0; + } + _LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE + static bool __lt(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT { + if (__is_type_name_unique(__lhs, __rhs)) + return __lhs < __rhs; + return __builtin_strcmp(__type_name_to_string(__lhs), __type_name_to_string(__rhs)) < 0; } + + private: + // The unique bit is the top bit. It is expected that __type_name_t is 64 bits when + // this implementation is actually used. + typedef std::integral_constant<__type_name_t, + (1ULL << ((__CHAR_BIT__ * sizeof(__type_name_t)) - 1))> __non_unique_rtti_bit; + + _LIBCPP_INLINE_VISIBILITY + static bool __is_type_name_unique(__type_name_t __lhs) _NOEXCEPT { + return !(__lhs & __non_unique_rtti_bit::value); + } + _LIBCPP_INLINE_VISIBILITY + static bool __is_type_name_unique(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT { + return !((__lhs & __rhs) & __non_unique_rtti_bit::value); + } + }; + + typedef +#if defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__) + __non_unique_arm_rtti_bit_impl +#elif _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT == 0 + __non_unique_impl +#elif _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT == 1 + __unique_impl #else +# error invalid configuration for _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT +#endif + __impl; +}; + +class _LIBCPP_EXCEPTION_ABI type_info +{ + type_info& operator=(const type_info&); + type_info(const type_info&); + + protected: + typedef __type_info_implementations::__impl __impl; + + __impl::__type_name_t __type_name; + + _LIBCPP_INLINE_VISIBILITY + explicit type_info(const char* __n) + : __type_name(__impl::__string_to_type_name(__n)) {} + +public: + _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE + virtual ~type_info(); + _LIBCPP_INLINE_VISIBILITY const char* name() const _NOEXCEPT - { return __type_name; } + { + return __impl::__type_name_to_string(__type_name); + } _LIBCPP_INLINE_VISIBILITY bool before(const type_info& __arg) const _NOEXCEPT - { return __type_name < __arg.__type_name; } + { + return __impl::__lt(__type_name, __arg.__type_name); + } _LIBCPP_INLINE_VISIBILITY size_t hash_code() const _NOEXCEPT - { return reinterpret_cast<size_t>(__type_name); } + { + return __impl::__hash(__type_name); + } _LIBCPP_INLINE_VISIBILITY bool operator==(const type_info& __arg) const _NOEXCEPT - { return __type_name == __arg.__type_name; } -#endif -#endif // _LIBCPP_ABI_MICROSOFT + { + return __impl::__eq(__type_name, __arg.__type_name); + } _LIBCPP_INLINE_VISIBILITY bool operator!=(const type_info& __arg) const _NOEXCEPT { return !operator==(__arg); } }; +#endif // defined(_LIBCPP_ABI_MICROSOFT) class _LIBCPP_EXCEPTION_ABI bad_cast : public exception { -public: - bad_cast() _NOEXCEPT; - virtual ~bad_cast() _NOEXCEPT; - virtual const char* what() const _NOEXCEPT; + public: + bad_cast() _NOEXCEPT; + virtual ~bad_cast() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; }; class _LIBCPP_EXCEPTION_ABI bad_typeid : public exception { -public: - bad_typeid() _NOEXCEPT; - virtual ~bad_typeid() _NOEXCEPT; - virtual const char* what() const _NOEXCEPT; + public: + bad_typeid() _NOEXCEPT; + virtual ~bad_typeid() _NOEXCEPT; + virtual const char* what() const _NOEXCEPT; }; } // std -#endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME) +#endif // defined(_LIBCPP_ABI_VCRUNTIME) _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY diff --git a/include/unordered_map b/include/unordered_map index 6035b05dc61c..ad17f776c938 100644 --- a/include/unordered_map +++ b/include/unordered_map @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- unordered_map -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -80,12 +79,12 @@ public: unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a) : unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14 template <class InputIterator> - unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf, + unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf, const allocator_type& a) : unordered_map(f, l, n, hf, key_equal(), a) {} // C++14 unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a) : unordered_map(il, n, hasher(), key_equal(), a) {} // C++14 - unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf, + unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf, const allocator_type& a) : unordered_map(il, n, hf, key_equal(), a) {} // C++14 ~unordered_map(); @@ -175,6 +174,7 @@ public: iterator find(const key_type& k); const_iterator find(const key_type& k) const; size_type count(const key_type& k) const; + bool contains(const key_type& k) const; // C++20 pair<iterator, iterator> equal_range(const key_type& k); pair<const_iterator, const_iterator> equal_range(const key_type& k) const; @@ -278,12 +278,12 @@ public: unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a) : unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14 template <class InputIterator> - unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf, + unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf, const allocator_type& a) : unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14 unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a) : unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14 - unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf, + unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf, const allocator_type& a) : unordered_multimap(il, n, hf, key_equal(), a) {} // C++14 ~unordered_multimap(); @@ -356,6 +356,7 @@ public: iterator find(const key_type& k); const_iterator find(const key_type& k) const; size_type count(const key_type& k) const; + bool contains(const key_type& k) const; // C++20 pair<iterator, iterator> equal_range(const key_type& k); pair<const_iterator, const_iterator> equal_range(const key_type& k) const; @@ -845,15 +846,14 @@ public: // types typedef _Key key_type; typedef _Tp mapped_type; - typedef _Hash hasher; - typedef _Pred key_equal; - typedef _Alloc allocator_type; + typedef typename __identity<_Hash>::type hasher; + typedef typename __identity<_Pred>::type key_equal; + typedef typename __identity<_Alloc>::type allocator_type; typedef pair<const key_type, mapped_type> value_type; typedef value_type& reference; typedef const value_type& const_reference; static_assert((is_same<value_type, typename allocator_type::value_type>::value), "Invalid allocator::value_type"); - static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); private: typedef __hash_value_type<key_type, mapped_type> __value_type; @@ -953,18 +953,22 @@ public: : unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {} template <class _InputIterator> _LIBCPP_INLINE_VISIBILITY - unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, + unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const allocator_type& __a) : unordered_map(__first, __last, __n, __hf, key_equal(), __a) {} _LIBCPP_INLINE_VISIBILITY unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) : unordered_map(__il, __n, hasher(), key_equal(), __a) {} _LIBCPP_INLINE_VISIBILITY - unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf, + unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a) : unordered_map(__il, __n, __hf, key_equal(), __a) {} #endif - // ~unordered_map() = default; + _LIBCPP_INLINE_VISIBILITY + ~unordered_map() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); + } + _LIBCPP_INLINE_VISIBILITY unordered_map& operator=(const unordered_map& __u) { @@ -1276,6 +1280,10 @@ public: const_iterator find(const key_type& __k) const {return __table_.find(__k);} _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} + #if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const {return find(__k) != end();} + #endif // _LIBCPP_STD_VER > 17 _LIBCPP_INLINE_VISIBILITY pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_unique(__k);} @@ -1346,6 +1354,73 @@ private: #endif }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Hash = hash<__iter_key_type<_InputIterator>>, + class _Pred = equal_to<__iter_key_type<_InputIterator>>, + class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<!__is_allocator<_Pred>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>; + +template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>, + class _Pred = equal_to<remove_const_t<_Key>>, + class _Allocator = allocator<pair<const _Key, _Tp>>, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<!__is_allocator<_Pred>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_map(_InputIterator, _InputIterator, _Allocator) + -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template<class _InputIterator, class _Hash, class _Allocator, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template<class _Key, class _Tp, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_map<remove_const_t<_Key>, _Tp, + hash<remove_const_t<_Key>>, + equal_to<remove_const_t<_Key>>, _Allocator>; + +template<class _Key, class _Tp, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_map(initializer_list<pair<_Key, _Tp>>, _Allocator) + -> unordered_map<remove_const_t<_Key>, _Tp, + hash<remove_const_t<_Key>>, + equal_to<remove_const_t<_Key>>, _Allocator>; + +template<class _Key, class _Tp, class _Hash, class _Allocator, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_map<remove_const_t<_Key>, _Tp, _Hash, + equal_to<remove_const_t<_Key>>, _Allocator>; +#endif + template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map( size_type __n, const hasher& __hf, const key_equal& __eql) @@ -1603,10 +1678,8 @@ _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) { iterator __i = find(__k); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__i == end()) - throw out_of_range("unordered_map::at: key not found"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_out_of_range("unordered_map::at: key not found"); return __i->second; } @@ -1615,10 +1688,8 @@ const _Tp& unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const { const_iterator __i = find(__k); -#ifndef _LIBCPP_NO_EXCEPTIONS if (__i == end()) - throw out_of_range("unordered_map::at: key not found"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_out_of_range("unordered_map::at: key not found"); return __i->second; } @@ -1675,15 +1746,14 @@ public: // types typedef _Key key_type; typedef _Tp mapped_type; - typedef _Hash hasher; - typedef _Pred key_equal; - typedef _Alloc allocator_type; + typedef typename __identity<_Hash>::type hasher; + typedef typename __identity<_Pred>::type key_equal; + typedef typename __identity<_Alloc>::type allocator_type; typedef pair<const key_type, mapped_type> value_type; typedef value_type& reference; typedef const value_type& const_reference; static_assert((is_same<value_type, typename allocator_type::value_type>::value), "Invalid allocator::value_type"); - static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); private: typedef __hash_value_type<key_type, mapped_type> __value_type; @@ -1781,18 +1851,22 @@ public: : unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {} template <class _InputIterator> _LIBCPP_INLINE_VISIBILITY - unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, + unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const allocator_type& __a) : unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {} _LIBCPP_INLINE_VISIBILITY unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a) : unordered_multimap(__il, __n, hasher(), key_equal(), __a) {} _LIBCPP_INLINE_VISIBILITY - unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf, + unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a) : unordered_multimap(__il, __n, __hf, key_equal(), __a) {} #endif - // ~unordered_multimap() = default; + _LIBCPP_INLINE_VISIBILITY + ~unordered_multimap() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), ""); + } + _LIBCPP_INLINE_VISIBILITY unordered_multimap& operator=(const unordered_multimap& __u) { @@ -1981,6 +2055,10 @@ public: const_iterator find(const key_type& __k) const {return __table_.find(__k);} _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} + #if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const {return find(__k) != end();} + #endif // _LIBCPP_STD_VER > 17 _LIBCPP_INLINE_VISIBILITY pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_multi(__k);} @@ -2040,6 +2118,73 @@ public: }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Hash = hash<__iter_key_type<_InputIterator>>, + class _Pred = equal_to<__iter_key_type<_InputIterator>>, + class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<!__is_allocator<_Pred>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>; + +template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>, + class _Pred = equal_to<remove_const_t<_Key>>, + class _Allocator = allocator<pair<const _Key, _Tp>>, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<!__is_allocator<_Pred>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multimap(_InputIterator, _InputIterator, _Allocator) + -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template<class _InputIterator, class _Hash, class _Allocator, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, + _Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>; + +template<class _Key, class _Tp, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_multimap<remove_const_t<_Key>, _Tp, + hash<remove_const_t<_Key>>, + equal_to<remove_const_t<_Key>>, _Allocator>; + +template<class _Key, class _Tp, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multimap(initializer_list<pair<_Key, _Tp>>, _Allocator) + -> unordered_multimap<remove_const_t<_Key>, _Tp, + hash<remove_const_t<_Key>>, + equal_to<remove_const_t<_Key>>, _Allocator>; + +template<class _Key, class _Tp, class _Hash, class _Allocator, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, + equal_to<remove_const_t<_Key>>, _Allocator>; +#endif + template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap( size_type __n, const hasher& __hf, const key_equal& __eql) diff --git a/include/unordered_set b/include/unordered_set index b4e61da89eec..68f777a4ea3e 100644 --- a/include/unordered_set +++ b/include/unordered_set @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- unordered_set -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -76,7 +75,7 @@ public: template <class InputIterator> unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14 template <class InputIterator> - unordered_set(InputIterator f, InputIterator l, size_type n, + unordered_set(InputIterator f, InputIterator l, size_type n, const hasher& hf, const allocator_type& a); // C++14 unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14 unordered_set(initializer_list<value_type> il, size_type n, @@ -147,6 +146,7 @@ public: iterator find(const key_type& k); const_iterator find(const key_type& k) const; size_type count(const key_type& k) const; + bool contains(const key_type& k) const; // C++20 pair<iterator, iterator> equal_range(const key_type& k); pair<const_iterator, const_iterator> equal_range(const key_type& k) const; @@ -243,7 +243,7 @@ public: unordered_multiset(InputIterator f, InputIterator l, size_type n, const hasher& hf, const allocator_type& a); // C++14 unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14 - unordered_multiset(initializer_list<value_type> il, size_type n, + unordered_multiset(initializer_list<value_type> il, size_type n, const hasher& hf, const allocator_type& a); // C++14 ~unordered_multiset(); unordered_multiset& operator=(const unordered_multiset&); @@ -311,6 +311,7 @@ public: iterator find(const key_type& k); const_iterator find(const key_type& k) const; size_type count(const key_type& k) const; + bool contains(const key_type& k) const; // C++20 pair<iterator, iterator> equal_range(const key_type& k); pair<const_iterator, const_iterator> equal_range(const key_type& k) const; @@ -384,14 +385,13 @@ public: // types typedef _Value key_type; typedef key_type value_type; - typedef _Hash hasher; - typedef _Pred key_equal; - typedef _Alloc allocator_type; + typedef typename __identity<_Hash>::type hasher; + typedef typename __identity<_Pred>::type key_equal; + typedef typename __identity<_Alloc>::type allocator_type; typedef value_type& reference; typedef const value_type& const_reference; static_assert((is_same<value_type, typename allocator_type::value_type>::value), "Invalid allocator::value_type"); - static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); private: typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; @@ -452,11 +452,11 @@ public: #if _LIBCPP_STD_VER > 11 template <class _InputIterator> inline _LIBCPP_INLINE_VISIBILITY - unordered_set(_InputIterator __first, _InputIterator __last, + unordered_set(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) : unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {} template <class _InputIterator> - unordered_set(_InputIterator __first, _InputIterator __last, + unordered_set(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf, const allocator_type& __a) : unordered_set(__first, __last, __n, __hf, key_equal(), __a) {} #endif @@ -482,12 +482,16 @@ public: const allocator_type& __a) : unordered_set(__il, __n, hasher(), key_equal(), __a) {} inline _LIBCPP_INLINE_VISIBILITY - unordered_set(initializer_list<value_type> __il, size_type __n, + unordered_set(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a) : unordered_set(__il, __n, __hf, key_equal(), __a) {} #endif #endif // _LIBCPP_CXX03_LANG - // ~unordered_set() = default; + _LIBCPP_INLINE_VISIBILITY + ~unordered_set() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); + } + _LIBCPP_INLINE_VISIBILITY unordered_set& operator=(const unordered_set& __u) { @@ -675,6 +679,10 @@ public: const_iterator find(const key_type& __k) const {return __table_.find(__k);} _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_unique(__k);} + #if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const {return find(__k) != end();} + #endif // _LIBCPP_STD_VER > 17 _LIBCPP_INLINE_VISIBILITY pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_unique(__k);} @@ -731,6 +739,62 @@ public: }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Hash = hash<__iter_value_type<_InputIterator>>, + class _Pred = equal_to<__iter_value_type<_InputIterator>>, + class _Allocator = allocator<__iter_value_type<_InputIterator>>, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<!__is_allocator<_Pred>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>; + +template<class _Tp, class _Hash = hash<_Tp>, + class _Pred = equal_to<_Tp>, + class _Allocator = allocator<_Tp>, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<!__is_allocator<_Pred>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_set<_Tp, _Hash, _Pred, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_set(_InputIterator, _InputIterator, + typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_set<__iter_value_type<_InputIterator>, + hash<__iter_value_type<_InputIterator>>, + equal_to<__iter_value_type<_InputIterator>>, + _Allocator>; + +template<class _InputIterator, class _Hash, class _Allocator, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_set(_InputIterator, _InputIterator, + typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_set<__iter_value_type<_InputIterator>, _Hash, + equal_to<__iter_value_type<_InputIterator>>, + _Allocator>; + +template<class _Tp, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>; + +template<class _Tp, class _Hash, class _Allocator, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>; +#endif + template <class _Value, class _Hash, class _Pred, class _Alloc> unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql) @@ -984,14 +1048,13 @@ public: // types typedef _Value key_type; typedef key_type value_type; - typedef _Hash hasher; - typedef _Pred key_equal; - typedef _Alloc allocator_type; + typedef typename __identity<_Hash>::type hasher; + typedef typename __identity<_Pred>::type key_equal; + typedef typename __identity<_Alloc>::type allocator_type; typedef value_type& reference; typedef const value_type& const_reference; static_assert((is_same<value_type, typename allocator_type::value_type>::value), "Invalid allocator::value_type"); - static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); private: typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table; @@ -1051,7 +1114,7 @@ public: #if _LIBCPP_STD_VER > 11 template <class _InputIterator> inline _LIBCPP_INLINE_VISIBILITY - unordered_multiset(_InputIterator __first, _InputIterator __last, + unordered_multiset(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a) : unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {} template <class _InputIterator> @@ -1085,7 +1148,11 @@ public: : unordered_multiset(__il, __n, __hf, key_equal(), __a) {} #endif #endif // _LIBCPP_CXX03_LANG - // ~unordered_multiset() = default; + _LIBCPP_INLINE_VISIBILITY + ~unordered_multiset() { + static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), ""); + } + _LIBCPP_INLINE_VISIBILITY unordered_multiset& operator=(const unordered_multiset& __u) { @@ -1243,6 +1310,10 @@ public: const_iterator find(const key_type& __k) const {return __table_.find(__k);} _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const {return __table_.__count_multi(__k);} + #if _LIBCPP_STD_VER > 17 + _LIBCPP_INLINE_VISIBILITY + bool contains(const key_type& __k) const {return find(__k) != end();} + #endif // _LIBCPP_STD_VER > 17 _LIBCPP_INLINE_VISIBILITY pair<iterator, iterator> equal_range(const key_type& __k) {return __table_.__equal_range_multi(__k);} @@ -1299,6 +1370,60 @@ public: }; +#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES +template<class _InputIterator, + class _Hash = hash<__iter_value_type<_InputIterator>>, + class _Pred = equal_to<__iter_value_type<_InputIterator>>, + class _Allocator = allocator<__iter_value_type<_InputIterator>>, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<!__is_allocator<_Pred>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>; + +template<class _Tp, class _Hash = hash<_Tp>, + class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<!__is_allocator<_Pred>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0, + _Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator()) + -> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>; + +template<class _InputIterator, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_multiset<__iter_value_type<_InputIterator>, + hash<__iter_value_type<_InputIterator>>, + equal_to<__iter_value_type<_InputIterator>>, + _Allocator>; + +template<class _InputIterator, class _Hash, class _Allocator, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, + _Hash, _Allocator) + -> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, + equal_to<__iter_value_type<_InputIterator>>, + _Allocator>; + +template<class _Tp, class _Allocator, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator) + -> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>; + +template<class _Tp, class _Hash, class _Allocator, + class = _EnableIf<!__is_allocator<_Hash>::value>, + class = _EnableIf<!is_integral<_Hash>::value>, + class = _EnableIf<__is_allocator<_Allocator>::value>> +unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator) + -> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>; +#endif + template <class _Value, class _Hash, class _Pred, class _Alloc> unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset( size_type __n, const hasher& __hf, const key_equal& __eql) diff --git a/include/utility b/include/utility index 74bbc5cf34f9..3961370dd833 100644 --- a/include/utility +++ b/include/utility @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- utility -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -104,7 +103,7 @@ struct piecewise_construct_t { }; inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); template <class T> struct tuple_size; -template <size_t I, class T> class tuple_element; +template <size_t I, class T> struct tuple_element; template <class T1, class T2> struct tuple_size<pair<T1, T2> >; template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >; @@ -253,7 +252,7 @@ operator>=(const _Tp& __x, const _Tp& __y) template <class _ForwardIterator1, class _ForwardIterator2> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator2 swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2) { @@ -264,7 +263,7 @@ swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardItera // forward declared in <type_traits> template<class _Tp, size_t _Np> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename enable_if< __is_swappable<_Tp>::value >::type @@ -350,7 +349,7 @@ struct _LIBCPP_TEMPLATE_VIS pair } #else template <bool _Val> - using _EnableB = typename enable_if<_Val, bool>::type; + using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type; struct _CheckArgs { template <class _U1, class _U2> @@ -377,7 +376,7 @@ struct _LIBCPP_TEMPLATE_VIS pair }; template <bool _MaybeEnable> - using _CheckArgsDep = typename conditional< + using _CheckArgsDep _LIBCPP_NODEBUG_TYPE = typename conditional< _MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type; struct _CheckTupleLikeConstructor { @@ -399,7 +398,7 @@ struct _LIBCPP_TEMPLATE_VIS pair }; template <class _Tuple> - using _CheckTLC = typename conditional< + using _CheckTLC _LIBCPP_NODEBUG_TYPE = typename conditional< __tuple_like_with_size<_Tuple, 2>::value && !is_same<typename decay<_Tuple>::type, pair>::value, _CheckTupleLikeConstructor, @@ -638,10 +637,10 @@ swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y) } template <class _Tp> -struct __unwrap_reference { typedef _Tp type; }; +struct __unwrap_reference { typedef _LIBCPP_NODEBUG_TYPE _Tp type; }; template <class _Tp> -struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _Tp& type; }; +struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; }; #if _LIBCPP_STD_VER > 17 template <class _Tp> @@ -688,23 +687,21 @@ template <class _T1, class _T2> : public integral_constant<size_t, 2> {}; template <size_t _Ip, class _T1, class _T2> -class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> > { static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>"); }; template <class _T1, class _T2> -class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> > { -public: - typedef _T1 type; + typedef _LIBCPP_NODEBUG_TYPE _T1 type; }; template <class _T1, class _T2> -class _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > +struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> > { -public: - typedef _T2 type; + typedef _LIBCPP_NODEBUG_TYPE _T2 type; }; template <size_t _Ip> struct __get_pair; @@ -883,11 +880,11 @@ template<size_t... _Ip> #if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) template <class _Tp, _Tp _Ep> -using __make_integer_sequence = __make_integer_seq<integer_sequence, _Tp, _Ep>; +using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = __make_integer_seq<integer_sequence, _Tp, _Ep>; #else -template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked = +template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG_TYPE = typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>; template <class _Tp, _Tp _Ep> @@ -898,11 +895,11 @@ struct __make_integer_sequence_checked static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length"); // Workaround GCC bug by preventing bad installations when 0 <= _Ep // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929 - typedef __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; + typedef _LIBCPP_NODEBUG_TYPE __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; }; template <class _Tp, _Tp _Ep> -using __make_integer_sequence = typename __make_integer_sequence_checked<_Tp, _Ep>::type; +using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = typename __make_integer_sequence_checked<_Tp, _Ep>::type; #endif @@ -1482,7 +1479,7 @@ struct _LIBCPP_TEMPLATE_VIS hash<float> size_t operator()(float __v) const _NOEXCEPT { // -0.0 and 0.0 should return same hash - if (__v == 0.0) + if (__v == 0.0f) return 0; return __scalar_hash<float>::operator()(__v); } @@ -1510,7 +1507,7 @@ struct _LIBCPP_TEMPLATE_VIS hash<long double> size_t operator()(long double __v) const _NOEXCEPT { // -0.0 and 0.0 should return same hash - if (__v == 0.0) + if (__v == 0.0L) return 0; #if defined(__i386__) // Zero out padding bits @@ -1593,29 +1590,29 @@ struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t> #ifndef _LIBCPP_CXX03_LANG template <class _Key, class _Hash> -using __check_hash_requirements = integral_constant<bool, +using __check_hash_requirements _LIBCPP_NODEBUG_TYPE = integral_constant<bool, is_copy_constructible<_Hash>::value && is_move_constructible<_Hash>::value && __invokable_r<size_t, _Hash, _Key const&>::value >; template <class _Key, class _Hash = std::hash<_Key> > -using __has_enabled_hash = integral_constant<bool, +using __has_enabled_hash _LIBCPP_NODEBUG_TYPE = integral_constant<bool, __check_hash_requirements<_Key, _Hash>::value && is_default_constructible<_Hash>::value >; #if _LIBCPP_STD_VER > 14 template <class _Type, class> -using __enable_hash_helper_imp = _Type; +using __enable_hash_helper_imp _LIBCPP_NODEBUG_TYPE = _Type; template <class _Type, class ..._Keys> -using __enable_hash_helper = __enable_hash_helper_imp<_Type, +using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = __enable_hash_helper_imp<_Type, typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type >; #else template <class _Type, class ...> -using __enable_hash_helper = _Type; +using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = _Type; #endif #endif // !_LIBCPP_CXX03_LANG diff --git a/include/valarray b/include/valarray index 07f38c811509..8f6221ab3f39 100644 --- a/include/valarray +++ b/include/valarray @@ -1,10 +1,9 @@ // -*- C++ -*- //===-------------------------- valarray ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -674,6 +673,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;} + template <class> friend class __val_expr; template <class> friend class _LIBCPP_TEMPLATE_VIS valarray; }; @@ -1059,8 +1059,6 @@ private: valarray& __assign_range(const value_type* __f, const value_type* __l); }; -_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t)) -_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS valarray<size_t>::~valarray()) _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t)) template <class _Op, class _Tp> @@ -2222,6 +2220,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_t size() const {return __1d_.size();} + template <class> friend class __val_expr; template <class> friend class valarray; }; @@ -2592,6 +2591,7 @@ public: _LIBCPP_INLINE_VISIBILITY size_t size() const {return __1d_.size();} + template <class> friend class __val_expr; template <class> friend class _LIBCPP_TEMPLATE_VIS valarray; }; @@ -2614,19 +2614,31 @@ public: _LIBCPP_INLINE_VISIBILITY __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const - {return __val_expr<__slice_expr<_ValExpr> >(__expr_, __s);} + { + typedef __slice_expr<_ValExpr> _NewExpr; + return __val_expr< _NewExpr >(_NewExpr(__s, __expr_)); + } _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const - {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __gs.__1d_);} + { + typedef __indirect_expr<_ValExpr> _NewExpr; + return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_)); + } _LIBCPP_INLINE_VISIBILITY __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const - {return __val_expr<__mask_expr<_ValExpr> >(__expr_, __vb);} + { + typedef __mask_expr<_ValExpr> _NewExpr; + return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_)); + } _LIBCPP_INLINE_VISIBILITY __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const - {return __val_expr<__indirect_expr<_ValExpr> >(__expr_, __vs);} + { + typedef __indirect_expr<_ValExpr> _NewExpr; + return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_)); + } _LIBCPP_INLINE_VISIBILITY __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> > diff --git a/include/variant b/include/variant index a4339de6cde4..98a62c992fa1 100644 --- a/include/variant +++ b/include/variant @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------------ variant -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -1090,20 +1089,73 @@ private: } }; -template <class... _Types> -struct __overload; +struct __no_narrowing_check { + template <class _Dest, class _Source> + using _Apply = __identity<_Dest>; +}; -template <> -struct __overload<> { void operator()() const; }; +struct __narrowing_check { + template <class _Dest> + static auto __test_impl(_Dest (&&)[1]) -> __identity<_Dest>; + template <class _Dest, class _Source> + using _Apply _LIBCPP_NODEBUG_TYPE = decltype(__test_impl<_Dest>({std::declval<_Source>()})); +}; -template <class _Tp, class... _Types> -struct __overload<_Tp, _Types...> : __overload<_Types...> { - using __overload<_Types...>::operator(); - __identity<_Tp> operator()(_Tp) const; +template <class _Dest, class _Source> +using __check_for_narrowing _LIBCPP_NODEBUG_TYPE = + typename _If< +#ifdef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT + false && +#endif + is_arithmetic<_Dest>::value, + __narrowing_check, + __no_narrowing_check + >::template _Apply<_Dest, _Source>; + +template <class _Tp, size_t _Idx> +struct __overload { + template <class _Up> + auto operator()(_Tp, _Up&&) const -> __check_for_narrowing<_Tp, _Up>; }; +template <class _Tp, size_t> +struct __overload_bool { + template <class _Up, class _Ap = __uncvref_t<_Up>> + auto operator()(bool, _Up&&) const + -> enable_if_t<is_same_v<_Ap, bool>, __identity<_Tp>>; +}; + +template <size_t _Idx> +struct __overload<bool, _Idx> : __overload_bool<bool, _Idx> {}; +template <size_t _Idx> +struct __overload<bool const, _Idx> : __overload_bool<bool const, _Idx> {}; +template <size_t _Idx> +struct __overload<bool volatile, _Idx> : __overload_bool<bool volatile, _Idx> {}; +template <size_t _Idx> +struct __overload<bool const volatile, _Idx> : __overload_bool<bool const volatile, _Idx> {}; + +template <class ..._Bases> +struct __all_overloads : _Bases... { + void operator()() const; + using _Bases::operator()...; +}; + +template <class IdxSeq> +struct __make_overloads_imp; + +template <size_t ..._Idx> +struct __make_overloads_imp<__tuple_indices<_Idx...> > { + template <class ..._Types> + using _Apply _LIBCPP_NODEBUG_TYPE = __all_overloads<__overload<_Types, _Idx>...>; +}; + +template <class ..._Types> +using _MakeOverloads _LIBCPP_NODEBUG_TYPE = typename __make_overloads_imp< + __make_indices_imp<sizeof...(_Types), 0> >::template _Apply<_Types...>; + template <class _Tp, class... _Types> -using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type; +using __best_match_t = + typename invoke_result_t<_MakeOverloads<_Types...>, _Tp, _Tp>::type; } // __variant_detail diff --git a/include/vector b/include/vector index edb6d3e09f5f..82bf6e0038d9 100644 --- a/include/vector +++ b/include/vector @@ -1,10 +1,9 @@ // -*- C++ -*- //===------------------------------ vector --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -665,27 +664,27 @@ public: void reserve(size_type __n); void shrink_to_fit() _NOEXCEPT; - _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n); - _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const; + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT; reference at(size_type __n); const_reference at(size_type __n) const; - _LIBCPP_INLINE_VISIBILITY reference front() + _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); return *this->__begin_; } - _LIBCPP_INLINE_VISIBILITY const_reference front() const + _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "front() called for empty vector"); return *this->__begin_; } - _LIBCPP_INLINE_VISIBILITY reference back() + _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); return *(this->__end_ - 1); } - _LIBCPP_INLINE_VISIBILITY const_reference back() const + _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT { _LIBCPP_ASSERT(!empty(), "back() called for empty vector"); return *(this->__end_ - 1); @@ -780,9 +779,9 @@ public: void swap(vector&) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT_DEBUG; + _NOEXCEPT; #else - _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); #endif @@ -836,12 +835,17 @@ private: } #ifndef _LIBCPP_CXX03_LANG - template <class _Up> void __push_back_slow_path(_Up&& __x); + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + inline void __push_back_slow_path(_Up&& __x); template <class... _Args> - void __emplace_back_slow_path(_Args&&... __args); + _LIBCPP_INLINE_VISIBILITY + inline void __emplace_back_slow_path(_Args&&... __args); #else - template <class _Up> void __push_back_slow_path(_Up& __x); + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + inline void __push_back_slow_path(_Up& __x); #endif // The following functions are no-ops outside of AddressSanitizer mode. @@ -1538,7 +1542,7 @@ vector<_Tp, _Allocator>::end() const _NOEXCEPT template <class _Tp, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::reference -vector<_Tp, _Allocator>::operator[](size_type __n) +vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT { _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); return this->__begin_[__n]; @@ -1547,7 +1551,7 @@ vector<_Tp, _Allocator>::operator[](size_type __n) template <class _Tp, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::const_reference -vector<_Tp, _Allocator>::operator[](size_type __n) const +vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT { _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); return this->__begin_[__n]; @@ -2065,9 +2069,9 @@ template <class _Tp, class _Allocator> void vector<_Tp, _Allocator>::swap(vector& __x) #if _LIBCPP_STD_VER >= 14 - _NOEXCEPT_DEBUG + _NOEXCEPT #else - _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value || + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value) #endif { diff --git a/include/version b/include/version index e37afc448601..fe9cfed876b0 100644 --- a/include/version +++ b/include/version @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- version ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -59,6 +58,7 @@ __cpp_lib_hypot 201603L <cmath> __cpp_lib_incomplete_container_elements 201505L <forward_list> <list> <vector> __cpp_lib_integer_sequence 201304L <utility> __cpp_lib_integral_constant_callable 201304L <type_traits> +__cpp_lib_interpolate 201902L <numeric> __cpp_lib_invoke 201411L <functional> __cpp_lib_is_aggregate 201703L <type_traits> __cpp_lib_is_constant_evaluated 201811L <type_traits> @@ -220,10 +220,15 @@ __cpp_lib_void_t 201411L <type_traits> // # define __cpp_lib_concepts 201806L // # define __cpp_lib_constexpr_misc 201811L // # define __cpp_lib_constexpr_swap_algorithms 201806L -// # define __cpp_lib_destroying_delete 201806L +# if _LIBCPP_STD_VER > 17 && defined(__cpp_impl_destroying_delete) && __cpp_impl_destroying_delete >= 201806L +# define __cpp_lib_destroying_delete 201806L +# endif # define __cpp_lib_erase_if 201811L // # define __cpp_lib_generic_unordered_lookup 201811L -// # define __cpp_lib_is_constant_evaluated 201811L +# define __cpp_lib_interpolate 201902L +# if !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED) +# define __cpp_lib_is_constant_evaluated 201811L +# endif // # define __cpp_lib_list_remove_return_type 201806L // # define __cpp_lib_ranges 201811L // # define __cpp_lib_three_way_comparison 201711L diff --git a/include/wchar.h b/include/wchar.h index f74fe6ddcff4..353c979d2072 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- wchar.h ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/include/wctype.h b/include/wctype.h index f9c5a47754bb..bdcf37234cc3 100644 --- a/include/wctype.h +++ b/include/wctype.h @@ -1,10 +1,9 @@ // -*- C++ -*- //===--------------------------- wctype.h ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000000..31cd24333a5e --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,495 @@ +set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" PARENT_SCOPE) + +# Get sources +set(LIBCXX_SOURCES + algorithm.cpp + any.cpp + bind.cpp + charconv.cpp + chrono.cpp + condition_variable.cpp + condition_variable_destructor.cpp + debug.cpp + exception.cpp + functional.cpp + future.cpp + hash.cpp + include/apple_availability.h + include/atomic_support.h + include/config_elast.h + include/refstring.h + ios.cpp + iostream.cpp + locale.cpp + memory.cpp + mutex.cpp + mutex_destructor.cpp + new.cpp + optional.cpp + random.cpp + regex.cpp + shared_mutex.cpp + stdexcept.cpp + string.cpp + strstream.cpp + support/runtime/exception_fallback.ipp + support/runtime/exception_glibcxx.ipp + support/runtime/exception_libcxxabi.ipp + support/runtime/exception_libcxxrt.ipp + support/runtime/exception_msvc.ipp + support/runtime/exception_pointer_cxxabi.ipp + support/runtime/exception_pointer_glibcxx.ipp + support/runtime/exception_pointer_msvc.ipp + support/runtime/exception_pointer_unimplemented.ipp + support/runtime/new_handler_fallback.ipp + support/runtime/stdexcept_default.ipp + support/runtime/stdexcept_vcruntime.ipp + system_error.cpp + thread.cpp + typeinfo.cpp + utility.cpp + valarray.cpp + variant.cpp + vector.cpp + ) + +if(WIN32) + list(APPEND LIBCXX_SOURCES + support/win32/locale_win32.cpp + support/win32/support.cpp + support/win32/thread_win32.cpp + ) +elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS") + list(APPEND LIBCXX_SOURCES + support/solaris/mbsnrtowcs.inc + support/solaris/wcsnrtombs.inc + support/solaris/xlocale.cpp + ) +endif() + +if (LIBCXX_ENABLE_FILESYSTEM) + list(APPEND LIBCXX_SOURCES + filesystem/filesystem_common.h + filesystem/operations.cpp + filesystem/directory_iterator.cpp + ) + # Filesystem uses __int128_t, which requires a definition of __muloi4 when + # compiled with UBSAN. This definition is not provided by libgcc_s, but is + # provided by compiler-rt. So we need to disable it to avoid having multiple + # definitions. See filesystem/int128_builtins.cpp. + if (NOT LIBCXX_USE_COMPILER_RT) + list(APPEND LIBCXX_SOURCES + filesystem/int128_builtins.cpp + ) + endif() +endif() + +# Add all the headers to the project for IDEs. +if (LIBCXX_CONFIGURE_IDE) + file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*) + if(WIN32) + file( GLOB LIBCXX_WIN32_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/support/win32/*.h) + list(APPEND LIBCXX_HEADERS ${LIBCXX_WIN32_HEADERS}) + endif() + # Force them all into the headers dir on MSVC, otherwise they end up at + # project scope because they don't have extensions. + if (MSVC_IDE) + source_group("Header Files" FILES ${LIBCXX_HEADERS}) + endif() +endif() + +if(NOT LIBCXX_INSTALL_LIBRARY) + set(exclude_from_all EXCLUDE_FROM_ALL) +endif() + +# If LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. +add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH + "${CMAKE_LIBRARY_PATH_FLAG}${LIBCXX_CXX_ABI_LIBRARY_PATH}") + + +if (LIBCXX_GENERATE_COVERAGE AND NOT LIBCXX_COVERAGE_LIBRARY) + find_compiler_rt_library(profile LIBCXX_COVERAGE_LIBRARY) +endif() +add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}") + +if (APPLE AND LLVM_USE_SANITIZER) + if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR + ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR + ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address")) + set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib") + elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined") + set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib") + elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread") + set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib") + else() + message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X") + endif() + if (LIBFILE) + find_compiler_rt_dir(LIBDIR) + if (NOT IS_DIRECTORY "${LIBDIR}") + message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER") + endif() + set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}") + set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE) + message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}") + add_library_flags("${LIBCXX_SANITIZER_LIBRARY}") + add_link_flags("-Wl,-rpath,${LIBDIR}") + endif() +endif() + +function(cxx_link_system_libraries target) + target_add_link_flags_if_supported(${target} PRIVATE "-nodefaultlibs") + target_add_compile_flags_if_supported(${target} PRIVATE "/Zl") + target_add_link_flags_if_supported(${target} PRIVATE "/nodefaultlib") + + if (LIBCXX_HAS_SYSTEM_LIB) + target_link_libraries(${target} PUBLIC System) + endif() + + if (LIBCXX_HAS_PTHREAD_LIB) + target_link_libraries(${target} PUBLIC pthread) + endif() + + if (LIBCXX_HAS_C_LIB) + target_link_libraries(${target} PUBLIC c) + endif() + + if (LIBCXX_HAS_M_LIB) + target_link_libraries(${target} PUBLIC m) + endif() + + if (LIBCXX_HAS_RT_LIB) + target_link_libraries(${target} PUBLIC rt) + endif() + + if (LIBCXX_USE_COMPILER_RT) + find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY) + if (LIBCXX_BUILTINS_LIBRARY) + target_link_libraries(${target} PUBLIC "${LIBCXX_BUILTINS_LIBRARY}") + endif() + elseif (LIBCXX_HAS_GCC_S_LIB) + target_link_libraries(${target} PUBLIC gcc_s) + endif() + + if (LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB) + target_link_libraries(${target} PUBLIC atomic) + endif() + + if (MINGW) + target_link_libraries(${target} PUBLIC "${MINGW_LIBRARIES}") + endif() + + if (LIBCXX_TARGETING_MSVC) + if (LIBCXX_DEBUG_BUILD) + set(LIB_SUFFIX "d") + else() + set(LIB_SUFFIX "") + endif() + + target_link_libraries(${target} PUBLIC ucrt${LIB_SUFFIX}) # Universal C runtime + target_link_libraries(${target} PUBLIC vcruntime${LIB_SUFFIX}) # C++ runtime + target_link_libraries(${target} PUBLIC msvcrt${LIB_SUFFIX}) # C runtime startup files + target_link_libraries(${target} PUBLIC msvcprt${LIB_SUFFIX}) # C++ standard library. Required for exception_ptr internals. + # Required for standards-complaint wide character formatting functions + # (e.g. `printfw`/`scanfw`) + target_link_libraries(${target} PUBLIC iso_stdio_wide_specifiers) + endif() +endfunction() + +function(cxx_set_common_defines name) + if(LIBCXX_CXX_ABI_HEADER_TARGET) + add_dependencies(${name} ${LIBCXX_CXX_ABI_HEADER_TARGET}) + endif() + if(WIN32 AND NOT MINGW) + target_compile_definitions(${name} + PRIVATE + # Ignore the -MSC_VER mismatch, as we may build + # with a different compatibility version. + _ALLOW_MSC_VER_MISMATCH + # Don't check the msvcprt iterator debug levels + # as we will define the iterator types; libc++ + # uses a different macro to identify the debug + # level. + _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH + # We are building the c++ runtime, don't pull in + # msvcprt. + _CRTBLD + # Don't warn on the use of "deprecated" + # "insecure" functions which are standards + # specified. + _CRT_SECURE_NO_WARNINGS + # Use the ISO conforming behaviour for conversion + # in printf, scanf. + _CRT_STDIO_ISO_WIDE_SPECIFIERS) + endif() +endfunction() + +split_list(LIBCXX_COMPILE_FLAGS) +split_list(LIBCXX_LINK_FLAGS) + +# Build the shared library. +if (LIBCXX_ENABLE_SHARED) + add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) + if(COMMAND llvm_setup_rpath) + llvm_setup_rpath(cxx_shared) + endif() + cxx_link_system_libraries(cxx_shared) + target_link_libraries(cxx_shared PRIVATE ${LIBCXX_LIBRARIES}) + set_target_properties(cxx_shared + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" + LINK_FLAGS "${LIBCXX_LINK_FLAGS}" + OUTPUT_NAME "c++" + VERSION "${LIBCXX_ABI_VERSION}.0" + SOVERSION "${LIBCXX_ABI_VERSION}" + DEFINE_SYMBOL "" + ) + cxx_set_common_defines(cxx_shared) + + # Link against LLVM libunwind + if (LIBCXXABI_USE_LLVM_UNWINDER) + if (NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) + target_link_libraries(cxx_shared PUBLIC unwind_shared) + list(APPEND LIBCXX_INTERFACE_LIBRARIES unwind_shared) # For the linker script + elseif (LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY AND (TARGET unwind_static OR HAVE_LIBUNWIND)) + # libunwind is already included in libc++abi + else() + target_link_libraries(cxx_shared PRIVATE unwind) + list(APPEND LIBCXX_INTERFACE_LIBRARIES unwind) # For the linker script + endif() + endif() + + # Link against libc++abi + if (LIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY) + if (APPLE) + target_link_libraries(cxx_shared PRIVATE "-Wl,-force_load" "${LIBCXX_CXX_STATIC_ABI_LIBRARY}") + else() + target_link_libraries(cxx_shared PRIVATE "-Wl,--whole-archive,-Bstatic" "${LIBCXX_CXX_STATIC_ABI_LIBRARY}" "-Wl,-Bdynamic,--no-whole-archive") + endif() + else() + target_link_libraries(cxx_shared PUBLIC "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") + list(APPEND LIBCXX_INTERFACE_LIBRARIES "${LIBCXX_CXX_SHARED_ABI_LIBRARY}") # For the linker script + endif() + + # Maybe re-export symbols from libc++abi + if (APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR + LIBCXX_CXX_ABI_LIBNAME STREQUAL "default") + AND NOT DEFINED LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) + set(LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS ON) + endif() + + if (LIBCXX_OSX_REEXPORT_LIBCXXABI_SYMBOLS) + if ("${CMAKE_OSX_ARCHITECTURES}" MATCHES "^(armv6|armv7|armv7s)$") + set(RE_EXPORT_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++sjlj-abi.v${LIBCXX_LIBCPPABI_VERSION}.exp") + else() + set(RE_EXPORT_LIST "${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi.v${LIBCXX_LIBCPPABI_VERSION}.exp") + endif() + target_link_libraries(cxx_shared PRIVATE + "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++unexp.exp" + "-Wl,-reexported_symbols_list,${RE_EXPORT_LIST}" + "-Wl,-force_symbols_not_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/notweak.exp" + "-Wl,-force_symbols_weak_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/weak.exp") + + if (NOT LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) + target_link_libraries(cxx_shared PRIVATE "-Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/../lib/libc++abi-new-delete.exp") + endif() + endif() + + # Generate a linker script in place of a libc++.so symlink. Rerun this command + # after cxx builds. + if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + # Get the name of the ABI library and handle the case where CXXABI_LIBNAME + # is a target name and not a library. Ex cxxabi_shared. + set(LIBCXX_INTERFACE_LIBRARY_NAMES) + foreach(lib ${LIBCXX_INTERFACE_LIBRARIES}) + # FIXME: Handle cxxabi_static and unwind_static. + if (TARGET ${lib} OR + (${lib} MATCHES "cxxabi(_static|_shared)?" AND HAVE_LIBCXXABI) OR + (${lib} MATCHES "unwind(_static|_shared)?" AND HAVE_LIBUNWIND)) + list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "$<TARGET_PROPERTY:${lib},OUTPUT_NAME>") + else() + list(APPEND LIBCXX_INTERFACE_LIBRARY_NAMES "${lib}") + endif() + endforeach() + add_custom_command(TARGET cxx_shared POST_BUILD + COMMAND + ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/gen_link_script.py + ARGS + --input "$<TARGET_SONAME_FILE:cxx_shared>" + --output "$<TARGET_LINKER_FILE:cxx_shared>" + ${LIBCXX_INTERFACE_LIBRARY_NAMES} + WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} + ) + endif() + + list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared") + if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") + # Since we most likely do not have a mt.exe replacement, disable the + # manifest bundling. This allows a normal cmake invocation to pass which + # will attempt to use the manifest tool to generate the bundled manifest + set_target_properties(cxx_shared PROPERTIES + APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO") + endif() +endif() + +# Build the static library. +if (LIBCXX_ENABLE_STATIC) + add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) + cxx_link_system_libraries(cxx_static) + target_link_libraries(cxx_static PRIVATE ${LIBCXX_LIBRARIES}) + set(CMAKE_STATIC_LIBRARY_PREFIX "lib") + set_target_properties(cxx_static + PROPERTIES + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" + LINK_FLAGS "${LIBCXX_LINK_FLAGS}" + OUTPUT_NAME "c++" + ) + cxx_set_common_defines(cxx_static) + + if (LIBCXX_HERMETIC_STATIC_LIBRARY) + append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility=hidden) + # If the hermetic library doesn't define the operator new/delete functions + # then its code shouldn't declare them with hidden visibility. They might + # actually be provided by a shared library at link time. + if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS) + append_flags_if_supported(CXX_STATIC_LIBRARY_FLAGS -fvisibility-global-new-delete-hidden) + endif() + target_compile_options(cxx_static PRIVATE ${CXX_STATIC_LIBRARY_FLAGS}) + target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) + endif() + + list(APPEND LIBCXX_BUILD_TARGETS "cxx_static") + # Attempt to merge the libc++.a archive and the ABI library archive into one. + if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY) + set(MERGE_ARCHIVES_SEARCH_PATHS "") + if (LIBCXX_CXX_ABI_LIBRARY_PATH) + set(MERGE_ARCHIVES_SEARCH_PATHS "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") + endif() + if (TARGET "${LIBCXX_CXX_STATIC_ABI_LIBRARY}" OR HAVE_LIBCXXABI) + set(MERGE_ARCHIVES_ABI_TARGET "$<TARGET_LINKER_FILE:${LIBCXX_CXX_STATIC_ABI_LIBRARY}>") + else() + set(MERGE_ARCHIVES_ABI_TARGET + "${CMAKE_STATIC_LIBRARY_PREFIX}${LIBCXX_CXX_STATIC_ABI_LIBRARY}${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() + if (APPLE) + set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}") + endif() + add_custom_command(TARGET cxx_static POST_BUILD + COMMAND + ${PYTHON_EXECUTABLE} ${LIBCXX_SOURCE_DIR}/utils/merge_archives.py + ARGS + -o $<TARGET_LINKER_FILE:cxx_static> + --ar "${CMAKE_AR}" + ${MERGE_ARCHIVES_LIBTOOL} + "$<TARGET_LINKER_FILE:cxx_static>" + "${MERGE_ARCHIVES_ABI_TARGET}" + "${MERGE_ARCHIVES_SEARCH_PATHS}" + WORKING_DIRECTORY ${LIBCXX_BUILD_DIR} + ) + endif() +endif() + +# Add a meta-target for both libraries. +add_custom_target(cxx DEPENDS cxx-headers ${LIBCXX_BUILD_TARGETS}) + +if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY) + set(LIBCXX_EXPERIMENTAL_SOURCES + experimental/memory_resource.cpp + ) + add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES}) + if (LIBCXX_ENABLE_SHARED) + target_link_libraries(cxx_experimental cxx_shared) + else() + target_link_libraries(cxx_experimental cxx_static) + endif() + + set(experimental_flags "${LIBCXX_COMPILE_FLAGS}") + check_flag_supported(-std=c++14) + if (NOT MSVC AND LIBCXX_SUPPORTS_STD_EQ_CXX14_FLAG) + string(REPLACE "-std=c++11" "-std=c++14" experimental_flags "${LIBCXX_COMPILE_FLAGS}") + endif() + set_target_properties(cxx_experimental + PROPERTIES + COMPILE_FLAGS "${experimental_flags}" + OUTPUT_NAME "c++experimental" + ) +endif() + +if (LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY) + file(GLOB LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES ../test/support/external_threads.cpp) + + if (LIBCXX_ENABLE_SHARED) + add_library(cxx_external_threads SHARED ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) + else() + add_library(cxx_external_threads STATIC ${LIBCXX_EXTERNAL_THREADING_SUPPORT_SOURCES}) + endif() + + set_target_properties(cxx_external_threads + PROPERTIES + LINK_FLAGS "${LIBCXX_LINK_FLAGS}" + COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}" + OUTPUT_NAME "c++external_threads" + ) +endif() + +if (LIBCXX_INSTALL_LIBRARY) + if (LIBCXX_INSTALL_SHARED_LIBRARY) + install(TARGETS cxx_shared + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) + endif() + + if (LIBCXX_INSTALL_STATIC_LIBRARY) + install(TARGETS cxx_static + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) + endif() + + if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) + install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${experimental_lib} + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) + endif() + + # NOTE: This install command must go after the cxx install command otherwise + # it will not be executed after the library symlinks are installed. + if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + # Replace the libc++ filename with $<TARGET_LINKER_FILE:cxx> + # after we required CMake 3.0. + install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" + DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} + COMPONENT libcxx) + endif() +endif() + +if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR + LIBCXX_INSTALL_HEADERS)) + if(LIBCXX_INSTALL_LIBRARY) + set(lib_install_target cxx) + endif() + if (LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) + set(experimental_lib_install_target cxx_experimental) + endif() + if(LIBCXX_INSTALL_HEADERS) + set(header_install_target install-cxx-headers) + endif() + add_custom_target(install-cxx + DEPENDS ${lib_install_target} + ${experimental_lib_install_target} + ${header_install_target} + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxx + -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") + add_custom_target(install-cxx-stripped + DEPENDS ${lib_install_target} + ${experimental_lib_install_target} + ${header_install_target} + COMMAND "${CMAKE_COMMAND}" + -DCMAKE_INSTALL_COMPONENT=cxx + -DCMAKE_INSTALL_DO_STRIP=1 + -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake") + add_custom_target(install-libcxx DEPENDS install-cxx) +endif() diff --git a/src/algorithm.cpp b/src/algorithm.cpp index f036eb7abe1c..a110ae8b1a6e 100644 --- a/src/algorithm.cpp +++ b/src/algorithm.cpp @@ -1,15 +1,19 @@ //===----------------------- algorithm.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "algorithm" #include "random" +#ifndef _LIBCPP_HAS_NO_THREADS #include "mutex" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif +#endif _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/src/any.cpp b/src/any.cpp index 3795258bb061..0cf09068837d 100644 --- a/src/any.cpp +++ b/src/any.cpp @@ -1,9 +1,8 @@ //===---------------------------- any.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/bind.cpp b/src/bind.cpp index b4c76ffe6a4d..53efdf9df375 100644 --- a/src/bind.cpp +++ b/src/bind.cpp @@ -1,9 +1,8 @@ //===-------------------------- bind.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/charconv.cpp b/src/charconv.cpp index ec241db74471..d3035883a78f 100644 --- a/src/charconv.cpp +++ b/src/charconv.cpp @@ -1,9 +1,8 @@ //===------------------------- charconv.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -61,48 +60,50 @@ append4(char* buffer, T i) return append2(append2(buffer, (i) / 100), (i) % 100); } -char* -__u32toa(uint32_t value, char* buffer) +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append2_no_zeros(char* buffer, T v) +{ + if (v < 10) + return append1(buffer, v); + else + return append2(buffer, v); +} + +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append4_no_zeros(char* buffer, T v) +{ + if (v < 100) + return append2_no_zeros(buffer, v); + else if (v < 1000) + return append3(buffer, v); + else + return append4(buffer, v); +} + +template <typename T> +inline _LIBCPP_INLINE_VISIBILITY char* +append8_no_zeros(char* buffer, T v) { - if (value < 10000) + if (v < 10000) { - if (value < 100) - { - if (value < 10) - buffer = append1(buffer, value); - else - buffer = append2(buffer, value); - } - else - { - if (value < 1000) - buffer = append3(buffer, value); - else - buffer = append4(buffer, value); - } + buffer = append4_no_zeros(buffer, v); } - else if (value < 100000000) + else + { + buffer = append4_no_zeros(buffer, v / 10000); + buffer = append4(buffer, v % 10000); + } + return buffer; +} + +char* +__u32toa(uint32_t value, char* buffer) +{ + if (value < 100000000) { - // value = bbbbcccc - const uint32_t b = value / 10000; - const uint32_t c = value % 10000; - - if (value < 1000000) - { - if (value < 100000) - buffer = append1(buffer, b); - else - buffer = append2(buffer, b); - } - else - { - if (value < 10000000) - buffer = append3(buffer, b); - else - buffer = append4(buffer, b); - } - - buffer = append4(buffer, c); + buffer = append8_no_zeros(buffer, value); } else { @@ -110,11 +111,7 @@ __u32toa(uint32_t value, char* buffer) const uint32_t a = value / 100000000; // 1 to 42 value %= 100000000; - if (a < 10) - buffer = append1(buffer, a); - else - buffer = append2(buffer, a); - + buffer = append2_no_zeros(buffer, a); buffer = append4(buffer, value / 10000); buffer = append4(buffer, value % 10000); } @@ -128,71 +125,14 @@ __u64toa(uint64_t value, char* buffer) if (value < 100000000) { uint32_t v = static_cast<uint32_t>(value); - if (v < 10000) - { - if (v < 100) - { - if (v < 10) - buffer = append1(buffer, v); - else - buffer = append2(buffer, v); - } - else - { - if (v < 1000) - buffer = append3(buffer, v); - else - buffer = append4(buffer, v); - } - } - else - { - // value = bbbbcccc - const uint32_t b = v / 10000; - const uint32_t c = v % 10000; - - if (v < 1000000) - { - if (v < 100000) - buffer = append1(buffer, b); - else - buffer = append2(buffer, b); - } - else - { - if (v < 10000000) - buffer = append3(buffer, b); - else - buffer = append4(buffer, b); - } - - buffer = append4(buffer, c); - } + buffer = append8_no_zeros(buffer, v); } else if (value < 10000000000000000) { const uint32_t v0 = static_cast<uint32_t>(value / 100000000); const uint32_t v1 = static_cast<uint32_t>(value % 100000000); - const uint32_t b0 = v0 / 10000; - const uint32_t c0 = v0 % 10000; - - if (v0 < 1000000) - { - if (v0 < 100000) - buffer = append1(buffer, b0); - else - buffer = append2(buffer, b0); - } - else - { - if (v0 < 10000000) - buffer = append3(buffer, b0); - else - buffer = append4(buffer, b0); - } - - buffer = append4(buffer, c0); + buffer = append8_no_zeros(buffer, v0); buffer = append4(buffer, v1 / 10000); buffer = append4(buffer, v1 % 10000); } @@ -202,20 +142,7 @@ __u64toa(uint64_t value, char* buffer) static_cast<uint32_t>(value / 10000000000000000); // 1 to 1844 value %= 10000000000000000; - if (a < 100) - { - if (a < 10) - buffer = append1(buffer, a); - else - buffer = append2(buffer, a); - } - else - { - if (a < 1000) - buffer = append3(buffer, a); - else - buffer = append4(buffer, a); - } + buffer = append4_no_zeros(buffer, a); const uint32_t v0 = static_cast<uint32_t>(value / 100000000); const uint32_t v1 = static_cast<uint32_t>(value % 100000000); diff --git a/src/chrono.cpp b/src/chrono.cpp index 882d50b9d731..8f533f1059ed 100644 --- a/src/chrono.cpp +++ b/src/chrono.cpp @@ -1,9 +1,8 @@ //===------------------------- chrono.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -38,6 +37,10 @@ #endif #endif +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "rt") +#endif + _LIBCPP_BEGIN_NAMESPACE_STD namespace chrono @@ -178,16 +181,26 @@ steady_clock::now() _NOEXCEPT #elif defined(_LIBCPP_WIN32API) +// https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx says: +// If the function fails, the return value is zero. <snip> +// On systems that run Windows XP or later, the function will always succeed +// and will thus never return zero. + +static LARGE_INTEGER +__QueryPerformanceFrequency() +{ + LARGE_INTEGER val; + (void) QueryPerformanceFrequency(&val); + return val; +} + steady_clock::time_point steady_clock::now() _NOEXCEPT { - static LARGE_INTEGER freq; - static BOOL initialized = FALSE; - if (!initialized) - initialized = QueryPerformanceFrequency(&freq); // always succceeds + static const LARGE_INTEGER freq = __QueryPerformanceFrequency(); LARGE_INTEGER counter; - QueryPerformanceCounter(&counter); + (void) QueryPerformanceCounter(&counter); return time_point(duration(counter.QuadPart * nano::den / freq.QuadPart)); } diff --git a/src/condition_variable.cpp b/src/condition_variable.cpp index 2200aefb804d..b8426c66fde6 100644 --- a/src/condition_variable.cpp +++ b/src/condition_variable.cpp @@ -1,9 +1,8 @@ //===-------------------- condition_variable.cpp --------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -16,12 +15,13 @@ #include "system_error" #include "__undef_macros" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif + _LIBCPP_BEGIN_NAMESPACE_STD -condition_variable::~condition_variable() -{ - __libcpp_condvar_destroy(&__cv_); -} +// ~condition_variable is defined elsewhere. void condition_variable::notify_one() _NOEXCEPT @@ -57,7 +57,7 @@ condition_variable::__do_timed_wait(unique_lock<mutex>& lk, nanoseconds d = tp.time_since_epoch(); if (d > nanoseconds(0x59682F000000E941)) d = nanoseconds(0x59682F000000E941); - timespec ts; + __libcpp_timespec_t ts; seconds s = duration_cast<seconds>(d); typedef decltype(ts.tv_sec) ts_sec; _LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max(); diff --git a/src/condition_variable_destructor.cpp b/src/condition_variable_destructor.cpp new file mode 100644 index 000000000000..44fa240ba78b --- /dev/null +++ b/src/condition_variable_destructor.cpp @@ -0,0 +1,46 @@ +//===---------------- condition_variable_destructor.cpp ------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Define ~condition_variable. +// +// On some platforms ~condition_variable has been made trivial and the +// definition is only provided for ABI compatibility. + +#include "__config" +#include "__threading_support" + +#if !defined(_LIBCPP_HAS_NO_THREADS) +# if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION) +# define NEEDS_CONDVAR_DESTRUCTOR +# endif +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef NEEDS_CONDVAR_DESTRUCTOR + +class _LIBCPP_TYPE_VIS condition_variable +{ + __libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER; +public: + _LIBCPP_INLINE_VISIBILITY + constexpr condition_variable() noexcept = default; + + ~condition_variable(); + + condition_variable(const condition_variable&) = delete; + condition_variable& operator=(const condition_variable&) = delete; +}; + +condition_variable::~condition_variable() +{ + __libcpp_condvar_destroy(&__cv_); +} +#endif + +_LIBCPP_END_NAMESPACE_STD diff --git a/src/debug.cpp b/src/debug.cpp index f2fc1ceb495a..c4cc281d586b 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -1,9 +1,8 @@ //===-------------------------- debug.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -14,18 +13,27 @@ #include "string" #include "cstdio" #include "__hash_table" +#ifndef _LIBCPP_HAS_NO_THREADS #include "mutex" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif +#endif _LIBCPP_BEGIN_NAMESPACE_STD -static std::string make_what_str(__libcpp_debug_info const& info) { - string msg = info.__file_; - msg += ":" + to_string(info.__line_) + ": _LIBCPP_ASSERT '"; - msg += info.__pred_; +std::string __libcpp_debug_info::what() const { + string msg = __file_; + msg += ":" + to_string(__line_) + ": _LIBCPP_ASSERT '"; + msg += __pred_; msg += "' failed. "; - msg += info.__msg_; + msg += __msg_; return msg; } +_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) { + std::fprintf(stderr, "%s\n", info.what().c_str()); + std::abort(); +} _LIBCPP_SAFE_STATIC __libcpp_debug_function_type __libcpp_debug_function = __libcpp_abort_debug_function; @@ -35,56 +43,11 @@ bool __libcpp_set_debug_function(__libcpp_debug_function_type __func) { return true; } -_LIBCPP_NORETURN void __libcpp_abort_debug_function(__libcpp_debug_info const& info) { - std::fprintf(stderr, "%s\n", make_what_str(info).c_str()); - std::abort(); -} - -_LIBCPP_NORETURN void __libcpp_throw_debug_function(__libcpp_debug_info const& info) { -#ifndef _LIBCPP_NO_EXCEPTIONS - throw __libcpp_debug_exception(info); -#else - __libcpp_abort_debug_function(info); -#endif -} - -struct __libcpp_debug_exception::__libcpp_debug_exception_imp { - __libcpp_debug_info __info_; - std::string __what_str_; -}; - -__libcpp_debug_exception::__libcpp_debug_exception() _NOEXCEPT - : __imp_(nullptr) { -} - -__libcpp_debug_exception::__libcpp_debug_exception( - __libcpp_debug_info const& info) : __imp_(new __libcpp_debug_exception_imp) -{ - __imp_->__info_ = info; - __imp_->__what_str_ = make_what_str(info); -} -__libcpp_debug_exception::__libcpp_debug_exception( - __libcpp_debug_exception const& other) : __imp_(nullptr) { - if (other.__imp_) - __imp_ = new __libcpp_debug_exception_imp(*other.__imp_); -} - -__libcpp_debug_exception::~__libcpp_debug_exception() _NOEXCEPT { - if (__imp_) - delete __imp_; -} - -const char* __libcpp_debug_exception::what() const _NOEXCEPT { - if (__imp_) - return __imp_->__what_str_.c_str(); - return "__libcpp_debug_exception"; -} - _LIBCPP_FUNC_VIS __libcpp_db* __get_db() { - static __libcpp_db db; + static _LIBCPP_NO_DESTROY __libcpp_db db; return &db; } @@ -106,7 +69,7 @@ typedef lock_guard<mutex_type> RLock; mutex_type& mut() { - static mutex_type m; + static _LIBCPP_NO_DESTROY mutex_type m; return m; } #endif // !_LIBCPP_HAS_NO_THREADS @@ -204,8 +167,8 @@ __libcpp_db::__insert_ic(void* __i, const void* __c) i->__c_ = c; } -__c_node* -__libcpp_db::__insert_c(void* __c) +void +__libcpp_db::__insert_c(void* __c, __libcpp_db::_InsertConstruct *__fn) { #ifndef _LIBCPP_HAS_NO_THREADS WLock _(mut()); @@ -213,7 +176,7 @@ __libcpp_db::__insert_c(void* __c) if (__csz_ + 1 > static_cast<size_t>(__cend_ - __cbeg_)) { size_t nc = __next_prime(2*static_cast<size_t>(__cend_ - __cbeg_) + 1); - __c_node** cbeg = static_cast<__c_node**>(calloc(nc, sizeof(void*))); + __c_node** cbeg = static_cast<__c_node**>(calloc(nc, sizeof(__c_node*))); if (cbeg == nullptr) __throw_bad_alloc(); @@ -235,15 +198,12 @@ __libcpp_db::__insert_c(void* __c) } size_t hc = hash<void*>()(__c) % static_cast<size_t>(__cend_ - __cbeg_); __c_node* p = __cbeg_[hc]; - __c_node* r = __cbeg_[hc] = - static_cast<__c_node*>(malloc(sizeof(__c_node))); - if (__cbeg_[hc] == nullptr) - __throw_bad_alloc(); + void *buf = malloc(sizeof(__c_node)); + if (buf == nullptr) + __throw_bad_alloc(); + __cbeg_[hc] = __fn(buf, __c, p); - r->__c_ = __c; - r->__next_ = p; ++__csz_; - return r; } void @@ -553,7 +513,7 @@ __libcpp_db::__insert_iterator(void* __i) if (__isz_ + 1 > static_cast<size_t>(__iend_ - __ibeg_)) { size_t nc = __next_prime(2*static_cast<size_t>(__iend_ - __ibeg_) + 1); - __i_node** ibeg = static_cast<__i_node**>(calloc(nc, sizeof(void*))); + __i_node** ibeg = static_cast<__i_node**>(calloc(nc, sizeof(__i_node*))); if (ibeg == nullptr) __throw_bad_alloc(); diff --git a/src/exception.cpp b/src/exception.cpp index 3d2dcfd5b10e..fce6db7c38b6 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -1,9 +1,8 @@ //===------------------------ exception.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -11,8 +10,7 @@ #include "new" #include "typeinfo" -#if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI) || \ - (defined(__APPLE__) && !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY)) +#if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI) #include <cxxabi.h> using namespace __cxxabiv1; #define HAVE_DEPENDENT_EH_ABI 1 diff --git a/src/experimental/memory_resource.cpp b/src/experimental/memory_resource.cpp index 7f0052f2b50a..9aa077942b0d 100644 --- a/src/experimental/memory_resource.cpp +++ b/src/experimental/memory_resource.cpp @@ -1,9 +1,8 @@ //===------------------------ memory_resource.cpp -------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -13,6 +12,9 @@ #include "atomic" #elif !defined(_LIBCPP_HAS_NO_THREADS) #include "mutex" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif #endif _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR @@ -26,19 +28,23 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR class _LIBCPP_TYPE_VIS __new_delete_memory_resource_imp : public memory_resource { -public: - ~__new_delete_memory_resource_imp() = default; - -protected: - virtual void* do_allocate(size_t __size, size_t __align) - { return _VSTD::__libcpp_allocate(__size, __align); /* FIXME */} + void *do_allocate(size_t size, size_t align) override { +#ifdef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION + if (__is_overaligned_for_new(align)) + __throw_bad_alloc(); +#endif + return _VSTD::__libcpp_allocate(size, align); + } - virtual void do_deallocate(void* __p, size_t __n, size_t __align) { - _VSTD::__libcpp_deallocate(__p, __n, __align); /* FIXME */ + void do_deallocate(void *p, size_t n, size_t align) override { + _VSTD::__libcpp_deallocate(p, n, align); } - virtual bool do_is_equal(memory_resource const & __other) const _NOEXCEPT - { return &__other == this; } + bool do_is_equal(memory_resource const & other) const _NOEXCEPT override + { return &other == this; } + +public: + ~__new_delete_memory_resource_imp() override = default; }; // null_memory_resource() diff --git a/src/filesystem/directory_iterator.cpp b/src/filesystem/directory_iterator.cpp index f0d807a03db6..ca88dee06402 100644 --- a/src/filesystem/directory_iterator.cpp +++ b/src/filesystem/directory_iterator.cpp @@ -1,9 +1,8 @@ //===------------------ directory_iterator.cpp ----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -25,6 +24,8 @@ namespace detail { namespace { #if !defined(_LIBCPP_WIN32API) + +#if defined(DT_BLK) template <class DirEntT, class = decltype(DirEntT::d_type)> static file_type get_file_type(DirEntT* ent, int) { switch (ent->d_type) { @@ -50,6 +51,7 @@ static file_type get_file_type(DirEntT* ent, int) { } return file_type::none; } +#endif // defined(DT_BLK) template <class DirEntT> static file_type get_file_type(DirEntT* ent, long) { diff --git a/src/filesystem/filesystem_common.h b/src/filesystem/filesystem_common.h index 40419ee35e6a..fe5c42f5e6d0 100644 --- a/src/filesystem/filesystem_common.h +++ b/src/filesystem/filesystem_common.h @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===//// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===//// diff --git a/src/filesystem/int128_builtins.cpp b/src/filesystem/int128_builtins.cpp index 66adbdd2dc89..a55540fe276e 100644 --- a/src/filesystem/int128_builtins.cpp +++ b/src/filesystem/int128_builtins.cpp @@ -1,9 +1,8 @@ /*===-- int128_builtins.cpp - Implement __muloti4 --------------------------=== * - * The LLVM Compiler Infrastructure - * - * This file is dual licensed under the MIT and the University of Illinois Open - * Source Licenses. See LICENSE.TXT for details. + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception * * ===----------------------------------------------------------------------=== * diff --git a/src/filesystem/operations.cpp b/src/filesystem/operations.cpp index b41061888724..69350ddfe9da 100644 --- a/src/filesystem/operations.cpp +++ b/src/filesystem/operations.cpp @@ -1,9 +1,8 @@ //===--------------------- filesystem/ops.cpp -----------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -45,6 +44,10 @@ #include <sys/time.h> // for gettimeofday and timeval #endif // !defined(CLOCK_REALTIME) +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "rt") +#endif + #if defined(_LIBCPP_COMPILER_GCC) #if _GNUC_VER < 500 #pragma GCC diagnostic ignored "-Wmissing-field-initializers" @@ -543,11 +546,19 @@ path __canonical(path const& orig_p, error_code* ec) { ErrorHandler<path> err("canonical", ec, &orig_p, &cwd); path p = __do_absolute(orig_p, &cwd, ec); +#if _POSIX_VERSION >= 200112 + std::unique_ptr<char, decltype(&::free)> + hold(::realpath(p.c_str(), nullptr), &::free); + if (hold.get() == nullptr) + return err.report(capture_errno()); + return {hold.get()}; +#else char buff[PATH_MAX + 1]; char* ret; if ((ret = ::realpath(p.c_str(), buff)) == nullptr) return err.report(capture_errno()); return {ret}; +#endif } void __copy(const path& from, const path& to, copy_options options, @@ -1089,16 +1100,27 @@ void __permissions(const path& p, perms prms, perm_options opts, path __read_symlink(const path& p, error_code* ec) { ErrorHandler<path> err("read_symlink", ec, &p); - char buff[PATH_MAX + 1]; - error_code m_ec; - ::ssize_t ret; - if ((ret = ::readlink(p.c_str(), buff, PATH_MAX)) == -1) { +#ifdef PATH_MAX + struct NullDeleter { void operator()(void*) const {} }; + const size_t size = PATH_MAX + 1; + char stack_buff[size]; + auto buff = std::unique_ptr<char[], NullDeleter>(stack_buff); +#else + StatT sb; + if (::lstat(p.c_str(), &sb) == -1) { return err.report(capture_errno()); } - _LIBCPP_ASSERT(ret <= PATH_MAX, "TODO"); + const size_t size = sb.st_size + 1; + auto buff = unique_ptr<char[]>(new char[size]); +#endif + ::ssize_t ret; + if ((ret = ::readlink(p.c_str(), buff.get(), size)) == -1) + return err.report(capture_errno()); _LIBCPP_ASSERT(ret > 0, "TODO"); + if (static_cast<size_t>(ret) >= size) + return err.report(errc::value_too_large); buff[ret] = 0; - return {buff}; + return {buff.get()}; } bool __remove(const path& p, error_code* ec) { diff --git a/src/functional.cpp b/src/functional.cpp index 5c2646f01b2e..555d2c53f2b0 100644 --- a/src/functional.cpp +++ b/src/functional.cpp @@ -1,9 +1,8 @@ //===----------------------- functional.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/future.cpp b/src/future.cpp index cbcd2e7b7288..58d0b4c247cb 100644 --- a/src/future.cpp +++ b/src/future.cpp @@ -1,9 +1,8 @@ //===------------------------- future.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/hash.cpp b/src/hash.cpp index dc90f789c6b8..89bb736c86c2 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -1,9 +1,8 @@ //===-------------------------- hash.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -154,12 +153,8 @@ inline _LIBCPP_INLINE_VISIBILITY typename enable_if<_Sz == 4, void>::type __check_for_overflow(size_t N) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (N > 0xFFFFFFFB) - throw overflow_error("__next_prime overflow"); -#else - (void)N; -#endif + __throw_overflow_error("__next_prime overflow"); } template <size_t _Sz = sizeof(size_t)> @@ -167,12 +162,8 @@ inline _LIBCPP_INLINE_VISIBILITY typename enable_if<_Sz == 8, void>::type __check_for_overflow(size_t N) { -#ifndef _LIBCPP_NO_EXCEPTIONS if (N > 0xFFFFFFFFFFFFFFC5ull) - throw overflow_error("__next_prime overflow"); -#else - (void)N; -#endif + __throw_overflow_error("__next_prime overflow"); } size_t diff --git a/src/include/apple_availability.h b/src/include/apple_availability.h index c12f7325cb41..0091138170fd 100644 --- a/src/include/apple_availability.h +++ b/src/include/apple_availability.h @@ -1,9 +1,8 @@ //===------------------------ apple_availability.h ------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_SRC_INCLUDE_APPLE_AVAILABILITY_H diff --git a/src/include/atomic_support.h b/src/include/atomic_support.h index ccd8d78d3d71..43c1a00234d2 100644 --- a/src/include/atomic_support.h +++ b/src/include/atomic_support.h @@ -1,9 +1,8 @@ //===----------------------------------------------------------------------===//// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===//// diff --git a/src/include/config_elast.h b/src/include/config_elast.h index c3cc19c2234f..501cbc4ffeba 100644 --- a/src/include/config_elast.h +++ b/src/include/config_elast.h @@ -1,9 +1,8 @@ //===----------------------- config_elast.h -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -24,6 +23,8 @@ #define _LIBCPP_ELAST __ELASTERROR #elif defined(__Fuchsia__) // No _LIBCPP_ELAST needed on Fuchsia +#elif defined(__wasi__) +// No _LIBCPP_ELAST needed on WASI #elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC) #define _LIBCPP_ELAST 4095 #elif defined(__APPLE__) diff --git a/src/include/refstring.h b/src/include/refstring.h index 702f2b7388da..e464b79ba89c 100644 --- a/src/include/refstring.h +++ b/src/include/refstring.h @@ -1,9 +1,8 @@ //===------------------------ __refstring ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/ios.cpp b/src/ios.cpp index 0f1d88e378f5..2dc84be82873 100644 --- a/src/ios.cpp +++ b/src/ios.cpp @@ -1,9 +1,8 @@ //===-------------------------- ios.cpp -----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -267,10 +266,9 @@ ios_base::clear(iostate state) __rdstate_ = state; else __rdstate_ = state | badbit; -#ifndef _LIBCPP_NO_EXCEPTIONS + if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0) - throw failure("ios_base::clear"); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_failure("ios_base::clear"); } // init @@ -310,35 +308,27 @@ ios_base::copyfmt(const ios_base& rhs) { size_t newesize = sizeof(event_callback) * rhs.__event_size_; new_callbacks.reset(static_cast<event_callback*>(malloc(newesize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_callbacks) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_alloc(); size_t newisize = sizeof(int) * rhs.__event_size_; new_ints.reset(static_cast<int *>(malloc(newisize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_ints) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_alloc(); } if (__iarray_cap_ < rhs.__iarray_size_) { size_t newsize = sizeof(long) * rhs.__iarray_size_; new_longs.reset(static_cast<long*>(malloc(newsize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_longs) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_alloc(); } if (__parray_cap_ < rhs.__parray_size_) { size_t newsize = sizeof(void*) * rhs.__parray_size_; new_pointers.reset(static_cast<void**>(malloc(newsize))); -#ifndef _LIBCPP_NO_EXCEPTIONS if (!new_pointers) - throw bad_alloc(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_alloc(); } // Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_ __fmtflags_ = rhs.__fmtflags_; diff --git a/src/iostream.cpp b/src/iostream.cpp index 11bfb486208e..0a5d6e8d2264 100644 --- a/src/iostream.cpp +++ b/src/iostream.cpp @@ -1,13 +1,13 @@ //===------------------------ iostream.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "__std_stream" +#include "__locale" #include "string" #include "new" @@ -79,8 +79,28 @@ __asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_t _LIBCPP_HIDDEN ios_base::Init __start_std_streams; +// On Windows the TLS storage for locales needs to be initialized before we create +// the standard streams, otherwise it may not be alive during program termination +// when we flush the streams. +static void force_locale_initialization() { +#if defined(_LIBCPP_MSVCRT_LIKE) + static bool once = []() { + auto loc = newlocale(LC_ALL_MASK, "C", 0); + { + __libcpp_locale_guard g(loc); // forces initialization of locale TLS + ((void)g); + } + freelocale(loc); + return true; + }(); + ((void)once); +#endif +} + ios_base::Init::Init() { + force_locale_initialization(); + #ifndef _LIBCPP_HAS_NO_STDIN istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin)); wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin)); diff --git a/src/locale.cpp b/src/locale.cpp index b9c701137df2..5b29ee448685 100644 --- a/src/locale.cpp +++ b/src/locale.cpp @@ -1,9 +1,8 @@ //===------------------------- locale.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -469,10 +468,8 @@ locale::__imp::install(facet* f, long id) const locale::facet* locale::__imp::use_facet(long id) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (!has_facet(id)) - throw bad_cast(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_cast(); return facets_[static_cast<size_t>(id)]; } @@ -538,12 +535,8 @@ locale::operator=(const locale& other) _NOEXCEPT } locale::locale(const char* name) -#ifndef _LIBCPP_NO_EXCEPTIONS : __locale_(name ? new __imp(name) - : throw runtime_error("locale constructed with null")) -#else // _LIBCPP_NO_EXCEPTIONS - : __locale_(new __imp(name)) -#endif + : (__throw_runtime_error("locale constructed with null"), (__imp*)0)) { __locale_->__add_shared(); } @@ -555,12 +548,8 @@ locale::locale(const string& name) } locale::locale(const locale& other, const char* name, category c) -#ifndef _LIBCPP_NO_EXCEPTIONS : __locale_(name ? new __imp(*other.__locale_, name, c) - : throw runtime_error("locale constructed with null")) -#else // _LIBCPP_NO_EXCEPTIONS - : __locale_(new __imp(*other.__locale_, name, c)) -#endif + : (__throw_runtime_error("locale constructed with null"), (__imp*)0)) { __locale_->__add_shared(); } @@ -4390,7 +4379,9 @@ void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end, ios_base::iostate& __err) { - if (__grouping.size() != 0) +// if the grouping pattern is empty _or_ there are no grouping bits, then do nothing +// we always have at least a single entry in [__g, __g_end); the end of the input sequence + if (__grouping.size() != 0 && __g_end - __g > 1) { reverse(__g, __g_end); const char* __ig = __grouping.data(); diff --git a/src/memory.cpp b/src/memory.cpp index 77ebe837c73c..c8c00383cf92 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -1,9 +1,8 @@ //===------------------------ memory.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -11,6 +10,9 @@ #ifndef _LIBCPP_HAS_NO_THREADS #include "mutex" #include "thread" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif #endif #include "include/atomic_support.h" diff --git a/src/mutex.cpp b/src/mutex.cpp index c61d34bb885b..0d69d7cacfa1 100644 --- a/src/mutex.cpp +++ b/src/mutex.cpp @@ -1,9 +1,8 @@ //===------------------------- mutex.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -13,6 +12,12 @@ #include "include/atomic_support.h" #include "__undef_macros" +#ifndef _LIBCPP_HAS_NO_THREADS +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif +#endif + _LIBCPP_BEGIN_NAMESPACE_STD #ifndef _LIBCPP_HAS_NO_THREADS @@ -20,10 +25,7 @@ const defer_lock_t defer_lock = {}; const try_to_lock_t try_to_lock = {}; const adopt_lock_t adopt_lock = {}; -mutex::~mutex() -{ - __libcpp_mutex_destroy(&__m_); -} +// ~mutex is defined elsewhere void mutex::lock() @@ -198,8 +200,8 @@ _LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER; _LIBCPP_SAFE_STATIC static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER; #endif -void -__call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) +void __call_once(volatile once_flag::_State_type& flag, void* arg, + void (*func)(void*)) { #if defined(_LIBCPP_HAS_NO_THREADS) if (flag == 0) @@ -210,12 +212,12 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) #endif // _LIBCPP_NO_EXCEPTIONS flag = 1; func(arg); - flag = ~0ul; + flag = ~once_flag::_State_type(0); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - flag = 0ul; + flag = 0; throw; } #endif // _LIBCPP_NO_EXCEPTIONS @@ -230,11 +232,12 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) try { #endif // _LIBCPP_NO_EXCEPTIONS - __libcpp_relaxed_store(&flag, 1ul); + __libcpp_relaxed_store(&flag, once_flag::_State_type(1)); __libcpp_mutex_unlock(&mut); func(arg); __libcpp_mutex_lock(&mut); - __libcpp_atomic_store(&flag, ~0ul, _AO_Release); + __libcpp_atomic_store(&flag, ~once_flag::_State_type(0), + _AO_Release); __libcpp_mutex_unlock(&mut); __libcpp_condvar_broadcast(&cv); #ifndef _LIBCPP_NO_EXCEPTIONS @@ -242,7 +245,7 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) catch (...) { __libcpp_mutex_lock(&mut); - __libcpp_relaxed_store(&flag, 0ul); + __libcpp_relaxed_store(&flag, once_flag::_State_type(0)); __libcpp_mutex_unlock(&mut); __libcpp_condvar_broadcast(&cv); throw; @@ -252,7 +255,6 @@ __call_once(volatile unsigned long& flag, void* arg, void(*func)(void*)) else __libcpp_mutex_unlock(&mut); #endif // !_LIBCPP_HAS_NO_THREADS - } _LIBCPP_END_NAMESPACE_STD diff --git a/src/mutex_destructor.cpp b/src/mutex_destructor.cpp new file mode 100644 index 000000000000..3a6b6b55eeb7 --- /dev/null +++ b/src/mutex_destructor.cpp @@ -0,0 +1,51 @@ +//===--------------------- mutex_destructor.cpp ---------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Define ~mutex. +// +// On some platforms ~mutex has been made trivial and the definition is only +// provided for ABI compatibility. +// +// In order to avoid ODR violations within libc++ itself, we need to ensure +// that *nothing* sees the non-trivial mutex declaration. For this reason +// we re-declare the entire class in this file instead of using +// _LIBCPP_BUILDING_LIBRARY to change the definition in the headers. + +#include "__config" +#include "__threading_support" + +#if !defined(_LIBCPP_HAS_NO_THREADS) +#if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION) +#define NEEDS_MUTEX_DESTRUCTOR +#endif +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef NEEDS_MUTEX_DESTRUCTOR +class _LIBCPP_TYPE_VIS mutex +{ + __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER; + +public: + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + constexpr mutex() = default; + mutex(const mutex&) = delete; + mutex& operator=(const mutex&) = delete; + ~mutex() noexcept; +}; + + +mutex::~mutex() _NOEXCEPT +{ + __libcpp_mutex_destroy(&__m_); +} + +#endif // !_LIBCPP_HAS_NO_THREADS +_LIBCPP_END_NAMESPACE_STD + diff --git a/src/new.cpp b/src/new.cpp index cc8383d4f146..901e78565857 100644 --- a/src/new.cpp +++ b/src/new.cpp @@ -1,9 +1,8 @@ //===--------------------------- new.cpp ----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -13,29 +12,25 @@ #include "include/atomic_support.h" #if defined(_LIBCPP_ABI_MICROSOFT) -#if defined(_LIBCPP_NO_VCRUNTIME) -#include "support/runtime/new_handler_fallback.ipp" -#endif +# if !defined(_LIBCPP_ABI_VCRUNTIME) +# include "support/runtime/new_handler_fallback.ipp" +# endif #elif defined(LIBCXX_BUILDING_LIBCXXABI) -#include <cxxabi.h> +# include <cxxabi.h> #elif defined(LIBCXXRT) -#include <cxxabi.h> -#include "support/runtime/new_handler_fallback.ipp" +# include <cxxabi.h> +# include "support/runtime/new_handler_fallback.ipp" #elif defined(__GLIBCXX__) -// nothing todo + // nothing to do #else -# if defined(__APPLE__) && !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) -# include <cxxabi.h> // FIXME: remove this once buildit is gone. -# else # include "support/runtime/new_handler_fallback.ipp" -# endif #endif namespace std { #ifndef __GLIBCXX__ -const nothrow_t nothrow = {}; +const nothrow_t nothrow{}; #endif #ifndef LIBSTDCXX @@ -55,7 +50,7 @@ __throw_bad_alloc() } // std #if !defined(__GLIBCXX__) && \ - !defined(_LIBCPP_DEFER_NEW_TO_VCRUNTIME) && \ + !defined(_LIBCPP_ABI_VCRUNTIME) && \ !defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS) // Implement all new and delete operators as weak definitions @@ -299,4 +294,4 @@ operator delete[] (void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT } #endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION -#endif // !__GLIBCXX__ && (!_LIBCPP_ABI_MICROSOFT || _LIBCPP_NO_VCRUNTIME) && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS +#endif // !__GLIBCXX__ && !_LIBCPP_ABI_VCRUNTIME && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS diff --git a/src/optional.cpp b/src/optional.cpp index 6099b6b41e89..3aaf5ea553ef 100644 --- a/src/optional.cpp +++ b/src/optional.cpp @@ -1,9 +1,8 @@ //===------------------------ optional.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/random.cpp b/src/random.cpp index 4a2468368d06..04adc59f9bc9 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -1,9 +1,8 @@ //===-------------------------- random.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/regex.cpp b/src/regex.cpp index a7363599d5a5..a971f646459b 100644 --- a/src/regex.cpp +++ b/src/regex.cpp @@ -1,9 +1,8 @@ //===-------------------------- regex.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/shared_mutex.cpp b/src/shared_mutex.cpp index 6185f15deabd..eb3f5f3506f5 100644 --- a/src/shared_mutex.cpp +++ b/src/shared_mutex.cpp @@ -1,9 +1,8 @@ //===---------------------- shared_mutex.cpp ------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -11,6 +10,9 @@ #ifndef _LIBCPP_HAS_NO_THREADS #include "shared_mutex" +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/src/stdexcept.cpp b/src/stdexcept.cpp index 5e06e521e404..f8f335f34ae1 100644 --- a/src/stdexcept.cpp +++ b/src/stdexcept.cpp @@ -1,9 +1,8 @@ //===------------------------ stdexcept.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -11,94 +10,10 @@ #include "new" #include "string" #include "system_error" -#include "include/refstring.h" - -/* For _LIBCPPABI_VERSION */ -#if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \ - (defined(LIBCXX_BUILDING_LIBCXXABI) || defined(__APPLE__) || defined(LIBCXXRT)) -#include <cxxabi.h> -#endif - -static_assert(sizeof(std::__libcpp_refstring) == sizeof(const char *), ""); - - -namespace std // purposefully not using versioning namespace -{ - -logic_error::logic_error(const string& msg) : __imp_(msg.c_str()) -{ -} - -logic_error::logic_error(const char* msg) : __imp_(msg) -{ -} - -logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_) -{ -} - -logic_error& -logic_error::operator=(const logic_error& le) _NOEXCEPT -{ - __imp_ = le.__imp_; - return *this; -} - -#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX) - -logic_error::~logic_error() _NOEXCEPT -{ -} -const char* -logic_error::what() const _NOEXCEPT -{ - return __imp_.c_str(); -} +#ifdef _LIBCPP_ABI_VCRUNTIME +#include "support/runtime/stdexcept_vcruntime.ipp" +#else +#include "support/runtime/stdexcept_default.ipp" #endif - -runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str()) -{ -} - -runtime_error::runtime_error(const char* msg) : __imp_(msg) -{ -} - -runtime_error::runtime_error(const runtime_error& le) _NOEXCEPT - : __imp_(le.__imp_) -{ -} - -runtime_error& -runtime_error::operator=(const runtime_error& le) _NOEXCEPT -{ - __imp_ = le.__imp_; - return *this; -} - -#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX) - -runtime_error::~runtime_error() _NOEXCEPT -{ -} - -const char* -runtime_error::what() const _NOEXCEPT -{ - return __imp_.c_str(); -} - -domain_error::~domain_error() _NOEXCEPT {} -invalid_argument::~invalid_argument() _NOEXCEPT {} -length_error::~length_error() _NOEXCEPT {} -out_of_range::~out_of_range() _NOEXCEPT {} - -range_error::~range_error() _NOEXCEPT {} -overflow_error::~overflow_error() _NOEXCEPT {} -underflow_error::~underflow_error() _NOEXCEPT {} - -#endif - -} // std diff --git a/src/string.cpp b/src/string.cpp index d7ebdd3e5c9a..4802d63c811b 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -1,19 +1,20 @@ //===------------------------- string.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "string" +#include "charconv" #include "cstdlib" #include "cwchar" #include "cerrno" #include "limits" #include "stdexcept" #include <stdio.h> +#include "__debug" _LIBCPP_BEGIN_NAMESPACE_STD @@ -172,7 +173,7 @@ as_integer( const string& func, const wstring& s, size_t* idx, int base ) // as_float -template<typename V, typename S, typename F> +template<typename V, typename S, typename F> inline V as_float_helper(const string& func, const S& str, size_t* idx, F f ) @@ -376,11 +377,11 @@ as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a) return s; } -template <class S, class V, bool = is_floating_point<V>::value> +template <class S> struct initial_string; -template <class V, bool b> -struct initial_string<string, V, b> +template <> +struct initial_string<string> { string operator()() const @@ -391,23 +392,8 @@ struct initial_string<string, V, b> } }; -template <class V> -struct initial_string<wstring, V, false> -{ - wstring - operator()() const - { - const size_t n = (numeric_limits<unsigned long long>::digits / 3) - + ((numeric_limits<unsigned long long>::digits % 3) != 0) - + 1; - wstring s(n, wchar_t()); - s.resize(s.capacity()); - return s; - } -}; - -template <class V> -struct initial_string<wstring, V, true> +template <> +struct initial_string<wstring> { wstring operator()() const @@ -431,95 +417,42 @@ get_swprintf() #endif } -} // unnamed namespace - -string to_string(int val) -{ - return as_string(snprintf, initial_string<string, int>()(), "%d", val); -} - -string to_string(unsigned val) -{ - return as_string(snprintf, initial_string<string, unsigned>()(), "%u", val); -} - -string to_string(long val) -{ - return as_string(snprintf, initial_string<string, long>()(), "%ld", val); -} - -string to_string(unsigned long val) -{ - return as_string(snprintf, initial_string<string, unsigned long>()(), "%lu", val); -} - -string to_string(long long val) -{ - return as_string(snprintf, initial_string<string, long long>()(), "%lld", val); -} - -string to_string(unsigned long long val) -{ - return as_string(snprintf, initial_string<string, unsigned long long>()(), "%llu", val); -} - -string to_string(float val) -{ - return as_string(snprintf, initial_string<string, float>()(), "%f", val); -} - -string to_string(double val) -{ - return as_string(snprintf, initial_string<string, double>()(), "%f", val); -} - -string to_string(long double val) +template <typename S, typename V> +S i_to_string(const V v) { - return as_string(snprintf, initial_string<string, long double>()(), "%Lf", val); +// numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers. +// For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented), +// so we need +1 here. + constexpr size_t bufsize = numeric_limits<V>::digits10 + 2; // +1 for minus, +1 for digits10 + char buf[bufsize]; + const auto res = to_chars(buf, buf + bufsize, v); + _LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value"); + return S(buf, res.ptr); } -wstring to_wstring(int val) -{ - return as_string(get_swprintf(), initial_string<wstring, int>()(), L"%d", val); -} - -wstring to_wstring(unsigned val) -{ - return as_string(get_swprintf(), initial_string<wstring, unsigned>()(), L"%u", val); -} - -wstring to_wstring(long val) -{ - return as_string(get_swprintf(), initial_string<wstring, long>()(), L"%ld", val); -} +} // unnamed namespace -wstring to_wstring(unsigned long val) -{ - return as_string(get_swprintf(), initial_string<wstring, unsigned long>()(), L"%lu", val); -} +string to_string (int val) { return i_to_string< string>(val); } +string to_string (long val) { return i_to_string< string>(val); } +string to_string (long long val) { return i_to_string< string>(val); } +string to_string (unsigned val) { return i_to_string< string>(val); } +string to_string (unsigned long val) { return i_to_string< string>(val); } +string to_string (unsigned long long val) { return i_to_string< string>(val); } -wstring to_wstring(long long val) -{ - return as_string(get_swprintf(), initial_string<wstring, long long>()(), L"%lld", val); -} +wstring to_wstring(int val) { return i_to_string<wstring>(val); } +wstring to_wstring(long val) { return i_to_string<wstring>(val); } +wstring to_wstring(long long val) { return i_to_string<wstring>(val); } +wstring to_wstring(unsigned val) { return i_to_string<wstring>(val); } +wstring to_wstring(unsigned long val) { return i_to_string<wstring>(val); } +wstring to_wstring(unsigned long long val) { return i_to_string<wstring>(val); } -wstring to_wstring(unsigned long long val) -{ - return as_string(get_swprintf(), initial_string<wstring, unsigned long long>()(), L"%llu", val); -} -wstring to_wstring(float val) -{ - return as_string(get_swprintf(), initial_string<wstring, float>()(), L"%f", val); -} +string to_string (float val) { return as_string(snprintf, initial_string< string>()(), "%f", val); } +string to_string (double val) { return as_string(snprintf, initial_string< string>()(), "%f", val); } +string to_string (long double val) { return as_string(snprintf, initial_string< string>()(), "%Lf", val); } -wstring to_wstring(double val) -{ - return as_string(get_swprintf(), initial_string<wstring, double>()(), L"%f", val); -} +wstring to_wstring(float val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); } +wstring to_wstring(double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); } +wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); } -wstring to_wstring(long double val) -{ - return as_string(get_swprintf(), initial_string<wstring, long double>()(), L"%Lf", val); -} _LIBCPP_END_NAMESPACE_STD diff --git a/src/strstream.cpp b/src/strstream.cpp index 8b8521f76af1..ae66806833aa 100644 --- a/src/strstream.cpp +++ b/src/strstream.cpp @@ -1,9 +1,8 @@ //===------------------------ strstream.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/exception_fallback.ipp b/src/support/runtime/exception_fallback.ipp index 16d387b99e8c..376a0381f545 100644 --- a/src/support/runtime/exception_fallback.ipp +++ b/src/support/runtime/exception_fallback.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/exception_glibcxx.ipp b/src/support/runtime/exception_glibcxx.ipp index dda4432b508a..4bf3c4d87759 100644 --- a/src/support/runtime/exception_glibcxx.ipp +++ b/src/support/runtime/exception_glibcxx.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/exception_libcxxabi.ipp b/src/support/runtime/exception_libcxxabi.ipp index feefc5152891..6bc049bf382d 100644 --- a/src/support/runtime/exception_libcxxabi.ipp +++ b/src/support/runtime/exception_libcxxabi.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/exception_libcxxrt.ipp b/src/support/runtime/exception_libcxxrt.ipp index 52fe8635db77..0ebffdedba94 100644 --- a/src/support/runtime/exception_libcxxrt.ipp +++ b/src/support/runtime/exception_libcxxrt.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/exception_msvc.ipp b/src/support/runtime/exception_msvc.ipp index 042d3add6c7f..7315b8261b76 100644 --- a/src/support/runtime/exception_msvc.ipp +++ b/src/support/runtime/exception_msvc.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -83,7 +82,7 @@ int uncaught_exceptions() _NOEXCEPT { return __uncaught_exceptions(); } -#if defined(_LIBCPP_NO_VCRUNTIME) +#if !defined(_LIBCPP_ABI_VCRUNTIME) bad_cast::bad_cast() _NOEXCEPT { } @@ -159,6 +158,6 @@ bad_array_new_length::what() const _NOEXCEPT { return "bad_array_new_length"; } -#endif // _LIBCPP_NO_VCRUNTIME +#endif // !_LIBCPP_ABI_VCRUNTIME } // namespace std diff --git a/src/support/runtime/exception_pointer_cxxabi.ipp b/src/support/runtime/exception_pointer_cxxabi.ipp index dfac8648c498..82a8e6972fa3 100644 --- a/src/support/runtime/exception_pointer_cxxabi.ipp +++ b/src/support/runtime/exception_pointer_cxxabi.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/exception_pointer_glibcxx.ipp b/src/support/runtime/exception_pointer_glibcxx.ipp index 9d20dfe48622..3abc137c67ba 100644 --- a/src/support/runtime/exception_pointer_glibcxx.ipp +++ b/src/support/runtime/exception_pointer_glibcxx.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/exception_pointer_msvc.ipp b/src/support/runtime/exception_pointer_msvc.ipp index 9b0d2361e402..b1a36952232c 100644 --- a/src/support/runtime/exception_pointer_msvc.ipp +++ b/src/support/runtime/exception_pointer_msvc.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/exception_pointer_unimplemented.ipp b/src/support/runtime/exception_pointer_unimplemented.ipp index 21c182c85974..991bca9ecfe3 100644 --- a/src/support/runtime/exception_pointer_unimplemented.ipp +++ b/src/support/runtime/exception_pointer_unimplemented.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/new_handler_fallback.ipp b/src/support/runtime/new_handler_fallback.ipp index ec3f52354ca8..720509394297 100644 --- a/src/support/runtime/new_handler_fallback.ipp +++ b/src/support/runtime/new_handler_fallback.ipp @@ -1,10 +1,9 @@ // -*- C++ -*- //===----------------------------------------------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/support/runtime/stdexcept_default.ipp b/src/support/runtime/stdexcept_default.ipp new file mode 100644 index 000000000000..c827ca4c5130 --- /dev/null +++ b/src/support/runtime/stdexcept_default.ipp @@ -0,0 +1,64 @@ +//===--------------------- stdexcept_default.ipp --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "../../include/refstring.h" + +/* For _LIBCPPABI_VERSION */ +#if !defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) && \ + (defined(LIBCXX_BUILDING_LIBCXXABI) || defined(LIBCXXRT)) +#include <cxxabi.h> +#endif + +static_assert(sizeof(std::__libcpp_refstring) == sizeof(const char*), ""); + +namespace std // purposefully not using versioning namespace +{ + +logic_error::logic_error(const string& msg) : __imp_(msg.c_str()) {} + +logic_error::logic_error(const char* msg) : __imp_(msg) {} + +logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_) {} + +logic_error& logic_error::operator=(const logic_error& le) _NOEXCEPT { + __imp_ = le.__imp_; + return *this; +} + +runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str()) {} + +runtime_error::runtime_error(const char* msg) : __imp_(msg) {} + +runtime_error::runtime_error(const runtime_error& re) _NOEXCEPT + : __imp_(re.__imp_) {} + +runtime_error& runtime_error::operator=(const runtime_error& re) _NOEXCEPT { + __imp_ = re.__imp_; + return *this; +} + +#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX) + +const char* logic_error::what() const _NOEXCEPT { return __imp_.c_str(); } + +const char* runtime_error::what() const _NOEXCEPT { return __imp_.c_str(); } + +logic_error::~logic_error() _NOEXCEPT {} +domain_error::~domain_error() _NOEXCEPT {} +invalid_argument::~invalid_argument() _NOEXCEPT {} +length_error::~length_error() _NOEXCEPT {} +out_of_range::~out_of_range() _NOEXCEPT {} + +runtime_error::~runtime_error() _NOEXCEPT {} +range_error::~range_error() _NOEXCEPT {} +overflow_error::~overflow_error() _NOEXCEPT {} +underflow_error::~underflow_error() _NOEXCEPT {} + +#endif + +} // namespace std diff --git a/src/support/runtime/stdexcept_vcruntime.ipp b/src/support/runtime/stdexcept_vcruntime.ipp new file mode 100644 index 000000000000..94eed465ae97 --- /dev/null +++ b/src/support/runtime/stdexcept_vcruntime.ipp @@ -0,0 +1,16 @@ +//===------------------- stdexcept_vcruntime.ipp --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ABI_VCRUNTIME +#error This file may only be used when defering to vcruntime +#endif + +namespace std { +logic_error::logic_error(std::string const& s) : exception(s.c_str()) {} +runtime_error::runtime_error(std::string const& s) : exception(s.c_str()) {} +} // namespace std diff --git a/src/system_error.cpp b/src/system_error.cpp index 06caa6fecd9f..9ddf7bcbe030 100644 --- a/src/system_error.cpp +++ b/src/system_error.cpp @@ -1,9 +1,8 @@ //===---------------------- system_error.cpp ------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/thread.cpp b/src/thread.cpp index 241cfee23c5b..39bb9e9bac63 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -1,9 +1,8 @@ //===------------------------- thread.cpp----------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -24,9 +23,9 @@ # endif #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) -#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__) # include <unistd.h> -#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) +#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__) #if defined(__NetBSD__) #pragma weak pthread_create // Do not create libpthread dependency @@ -36,6 +35,10 @@ #include <windows.h> #endif +#if defined(__unix__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA) +#pragma comment(lib, "pthread") +#endif + _LIBCPP_BEGIN_NAMESPACE_STD thread::~thread() diff --git a/src/typeinfo.cpp b/src/typeinfo.cpp index 42ff9351ed21..49a07ef7dabe 100644 --- a/src/typeinfo.cpp +++ b/src/typeinfo.cpp @@ -1,15 +1,14 @@ //===------------------------- typeinfo.cpp -------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "typeinfo" -#if defined(_LIBCPP_ABI_MICROSOFT) && defined(_LIBCPP_NO_VCRUNTIME) +#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_VCRUNTIME) #include <string.h> int std::type_info::__compare(const type_info &__rhs) const _NOEXCEPT { @@ -46,11 +45,11 @@ size_t std::type_info::hash_code() const _NOEXCEPT { } #endif // _LIBCPP_ABI_MICROSOFT -// FIXME: Remove __APPLE__ default here once buildit is gone. // FIXME: Remove the _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY configuration. -#if (!defined(LIBCXX_BUILDING_LIBCXXABI) && !defined(LIBCXXRT) && \ - !defined(__GLIBCXX__) && !defined(__APPLE__) && \ - !(defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME))) || \ +#if (!defined(LIBCXX_BUILDING_LIBCXXABI) && \ + !defined(LIBCXXRT) && \ + !defined(__GLIBCXX__) && \ + !defined(_LIBCPP_ABI_VCRUNTIME)) || \ defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) std::type_info::~type_info() { diff --git a/src/utility.cpp b/src/utility.cpp index 7dccffb73e5a..016a5d91b85a 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -1,9 +1,8 @@ //===------------------------ utility.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/valarray.cpp b/src/valarray.cpp index 2d8db52ac36b..7bf0b4175889 100644 --- a/src/valarray.cpp +++ b/src/valarray.cpp @@ -1,9 +1,8 @@ //===------------------------ valarray.cpp --------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -11,8 +10,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD +// These two symbols are part of the v1 ABI but not part of the >=v2 ABI. +#if _LIBCPP_ABI_VERSION == 1 template valarray<size_t>::valarray(size_t); template valarray<size_t>::~valarray(); +#endif + template void valarray<size_t>::resize(size_t, size_t); void diff --git a/src/variant.cpp b/src/variant.cpp index 5bb508c3f467..1fe70a1809c9 100644 --- a/src/variant.cpp +++ b/src/variant.cpp @@ -1,9 +1,8 @@ //===------------------------ variant.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// diff --git a/src/vector.cpp b/src/vector.cpp index 300adaed5f47..3b65e558fd0a 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -1,9 +1,8 @@ //===------------------------- vector.cpp ---------------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// |