diff options
author | dim <dim@FreeBSD.org> | 2017-09-26 19:56:36 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2017-09-26 19:56:36 +0000 |
commit | 12cd91cf4c6b96a24427c0de5374916f2808d263 (patch) | |
tree | 6d243b0ccba6738dbbd30767188e2963f90ef18f /contrib/libc++/include/string | |
parent | b60520398f206195e21774c315afb59a0f6d7146 (diff) | |
download | FreeBSD-src-12cd91cf4c6b96a24427c0de5374916f2808d263.zip FreeBSD-src-12cd91cf4c6b96a24427c0de5374916f2808d263.tar.gz |
Merge clang, llvm, lld, lldb, compiler-rt and libc++ 5.0.0 release.
MFC r309126 (by emaste):
Correct lld llvm-tblgen dependency file name
MFC r309169:
Get rid of separate Subversion mergeinfo properties for llvm-dwarfdump
and llvm-lto. The mergeinfo confuses Subversion enormously, and these
directories will just use the mergeinfo for llvm itself.
MFC r312765:
Pull in r276136 from upstream llvm trunk (by Wei Mi):
Use ValueOffsetPair to enhance value reuse during SCEV expansion.
In D12090, the ExprValueMap was added to reuse existing value during
SCEV expansion. However, const folding and sext/zext distribution can
make the reuse still difficult.
A simplified case is: suppose we know S1 expands to V1 in
ExprValueMap, and
S1 = S2 + C_a
S3 = S2 + C_b
where C_a and C_b are different SCEVConstants. Then we'd like to
expand S3 as V1 - C_a + C_b instead of expanding S2 literally. It is
helpful when S2 is a complex SCEV expr and S2 has no entry in
ExprValueMap, which is usually caused by the fact that S3 is
generated from S1 after const folding.
In order to do that, we represent ExprValueMap as a mapping from SCEV
to ValueOffsetPair. We will save both S1->{V1, 0} and S2->{V1, C_a}
into the ExprValueMap when we create SCEV for V1. When S3 is
expanded, it will first expand S2 to V1 - C_a because of S2->{V1,
C_a} in the map, then expand S3 to V1 - C_a + C_b.
Differential Revision: https://reviews.llvm.org/D21313
This should fix assertion failures when building OpenCV >= 3.1.
PR: 215649
MFC r312831:
Revert r312765 for now, since it causes assertions when building
lang/spidermonkey24.
Reported by: antoine
PR: 215649
MFC r316511 (by jhb):
Add an implementation of __ffssi2() derived from __ffsdi2().
Newer versions of GCC include an __ffssi2() symbol in libgcc and the
compiler can emit calls to it in generated code. This is true for at
least GCC 6.2 when compiling world for mips and mips64.
Reviewed by: jmallett, dim
Sponsored by: DARPA / AFRL
Differential Revision: https://reviews.freebsd.org/D10086
MFC r318601 (by adrian):
[libcompiler-rt] add bswapdi2/bswapsi2
This is required for mips gcc 6.3 userland to build/run.
Reviewed by: emaste, dim
Approved by: emaste
Differential Revision: https://reviews.freebsd.org/D10838
MFC r318884 (by emaste):
lldb: map TRAP_CAP to a trace trap
In the absense of a more specific handler for TRAP_CAP (generated by
ENOTCAPABLE or ECAPMODE while in capability mode) treat it as a trace
trap.
Example usage (testing the bug in PR219173):
% proccontrol -m trapcap lldb usr.bin/hexdump/obj/hexdump -- -Cv -s 1 /bin/ls
...
(lldb) run
Process 12980 launching
Process 12980 launched: '.../usr.bin/hexdump/obj/hexdump' (x86_64)
Process 12980 stopped
* thread #1, stop reason = trace
frame #0: 0x0000004b80c65f1a libc.so.7`__sys_lseek + 10
...
In the future we should have LLDB control the trapcap procctl itself
(as it does with ASLR), as well as report a specific stop reason.
This change eliminates an assertion failure from LLDB for now.
MFC r319796:
Remove a few unneeded files from libllvm, libclang and liblldb.
MFC r319885 (by emaste):
lld: ELF: Fix ICF crash on absolute symbol relocations.
If two sections contained relocations to absolute symbols with the same
value we would crash when trying to access their sections. Add a check that
both symbols point to sections before accessing their sections, and treat
absolute symbols as equal if their values are equal.
Obtained from: LLD commit r292578
MFC r319918:
Revert r319796 for now, it can cause undefined references when linking
in some circumstances.
Reported by: Shawn Webb <shawn.webb@hardenedbsd.org>
MFC r319957 (by emaste):
lld: Add armelf emulation mode
Obtained from: LLD r305375
MFC r321369:
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
5.0.0 (trunk r308421). Upstream has branched for the 5.0.0 release,
which should be in about a month. Please report bugs and regressions,
so we can get them into the release.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
MFC r321420:
Add a few more object files to liblldb, which should solve errors when
linking the lldb executable in some cases. In particular, when the
-ffunction-sections -fdata-sections options are turned off, or
ineffective.
Reported by: Shawn Webb, Mark Millard
MFC r321433:
Cleanup stale Options.inc files from the previous libllvm build for
clang 4.0.0. Otherwise, these can get included before the two newly
generated ones (which are different) for clang 5.0.0.
Reported by: Mark Millard
MFC r321439 (by bdrewery):
Move llvm Options.inc hack from r321433 for NO_CLEAN to lib/clang/libllvm.
The files are only ever generated to .OBJDIR, not to WORLDTMP (as a
sysroot) and are only ever included from a compilation. So using
a beforebuild target here removes the file before the compilation
tries to include it.
MFC r321664:
Pull in r308891 from upstream llvm trunk (by Benjamin Kramer):
[CodeGenPrepare] Cut off FindAllMemoryUses if there are too many uses.
This avoids excessive compile time. The case I'm looking at is
Function.cpp from an old version of LLVM that still had the giant
memcmp string matcher in it. Before r308322 this compiled in about 2
minutes, after it, clang takes infinite* time to compile it. With
this patch we're at 5 min, which is still bad but this is a
pathological case.
The cut off at 20 uses was chosen by looking at other cut-offs in LLVM
for user scanning. It's probably too high, but does the job and is
very unlikely to regress anything.
Fixes PR33900.
* I'm impatient and aborted after 15 minutes, on the bug report it was
killed after 2h.
Pull in r308986 from upstream llvm trunk (by Simon Pilgrim):
[X86][CGP] Reduce memcmp() expansion to 2 load pairs (PR33914)
D35067/rL308322 attempted to support up to 4 load pairs for memcmp
inlining which resulted in regressions for some optimized libc memcmp
implementations (PR33914).
Until we can match these more optimal cases, this patch reduces the
memcmp expansion to a maximum of 2 load pairs (which matches what we
do for -Os).
This patch should be considered for the 5.0.0 release branch as well
Differential Revision: https://reviews.llvm.org/D35830
These fix a hang (or extremely long compile time) when building older
LLVM ports.
Reported by: antoine
PR: 219139
MFC r321719:
Pull in r309503 from upstream clang trunk (by Richard Smith):
PR33902: Invalidate line number cache when adding more text to
existing buffer.
This led to crashes as the line number cache would report a bogus
line number for a line of code, and we'd try to find a nonexistent
column within the line when printing diagnostics.
This fixes an assertion when building the graphics/champlain port.
Reported by: antoine, kwm
PR: 219139
MFC r321723:
Upgrade our copies of clang, llvm, lld and lldb to r309439 from the
upstream release_50 branch. This is just after upstream's 5.0.0-rc1.
MFC r322320:
Upgrade our copies of clang, llvm and libc++ to r310316 from the
upstream release_50 branch.
MFC r322326 (by emaste):
lldb: Make i386-*-freebsd expression work on JIT path
* Enable i386 ABI creation for freebsd
* Added an extra argument in ABISysV_i386::PrepareTrivialCall for mmap
syscall
* Unlike linux, the last argument of mmap is actually 64-bit(off_t).
This requires us to push an additional word for the higher order bits.
* Prior to this change, ktrace dump will show mmap failures due to
invalid argument coming from the 6th mmap argument.
Submitted by: Karnajit Wangkhem
Differential Revision: https://reviews.llvm.org/D34776
MFC r322360 (by emaste):
lldb: Report inferior signals as signals, not exceptions, on FreeBSD
This is the FreeBSD equivalent of LLVM r238549.
This serves 2 purposes:
* LLDB should handle inferior process signals SIGSEGV/SIGILL/SIGBUS/
SIGFPE the way it is suppose to be handled. Prior to this fix these
signals will neither create a coredump, nor exit from the debugger
or work for signal handling scenario.
* eInvalidCrashReason need not report "unknown crash reason" if we have
a valid si_signo
llvm.org/pr23699
Patch by Karnajit Wangkhem
Differential Revision: https://reviews.llvm.org/D35223
Submitted by: Karnajit Wangkhem
Obtained from: LLVM r310591
MFC r322474 (by emaste):
lld: Add `-z muldefs` option.
Obtained from: LLVM r310757
MFC r322740:
Upgrade our copies of clang, llvm, lld and libc++ to r311219 from the
upstream release_50 branch.
MFC r322855:
Upgrade our copies of clang, llvm, lldb and compiler-rt to r311606 from
the upstream release_50 branch.
As of this version, lib/msun's trig test should also work correctly
again (see bug 220989 for more information).
PR: 220989
MFC r323112:
Upgrade our copies of clang, llvm, lldb and compiler-rt to r312293 from
the upstream release_50 branch. This corresponds to 5.0.0 rc4.
As of this version, the cad/stepcode port should now compile in a more
reasonable time on i386 (see bug 221836 for more information).
PR: 221836
MFC r323245:
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
5.0.0 release (upstream r312559).
Release notes for llvm, clang and lld will be available here soon:
<http://releases.llvm.org/5.0.0/docs/ReleaseNotes.html>
<http://releases.llvm.org/5.0.0/tools/clang/docs/ReleaseNotes.html>
<http://releases.llvm.org/5.0.0/tools/lld/docs/ReleaseNotes.html>
Relnotes: yes
Diffstat (limited to 'contrib/libc++/include/string')
-rw-r--r-- | contrib/libc++/include/string | 276 |
1 files changed, 157 insertions, 119 deletions
diff --git a/contrib/libc++/include/string b/contrib/libc++/include/string index ba311ef..610f19e 100644 --- a/contrib/libc++/include/string +++ b/contrib/libc++/include/string @@ -484,14 +484,16 @@ basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++1 #include <cstdint> #endif -#include <__undef_min_max> - #include <__debug> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + _LIBCPP_BEGIN_NAMESPACE_STD // fpos @@ -554,6 +556,8 @@ template<class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator> operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); +_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&)) + template <bool> class _LIBCPP_TEMPLATE_VIS __basic_string_common { @@ -576,14 +580,7 @@ __basic_string_common<__b>::__throw_out_of_range() const _VSTD::__throw_out_of_range("basic_string"); } -#ifdef _LIBCPP_MSVC -#pragma warning( push ) -#pragma warning( disable: 4231 ) -#endif // _LIBCPP_MSVC _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>) -#ifdef _LIBCPP_MSVC -#pragma warning( pop ) -#endif // _LIBCPP_MSVC #ifdef _LIBCPP_NO_EXCEPTIONS template <class _Iter> @@ -637,7 +634,7 @@ public: typedef basic_string __self; typedef basic_string_view<_CharT, _Traits> __self_view; typedef _Traits traits_type; - typedef typename traits_type::char_type value_type; + typedef _CharT value_type; typedef _Allocator allocator_type; typedef allocator_traits<allocator_type> __alloc_traits; typedef typename __alloc_traits::size_type size_type; @@ -648,7 +645,7 @@ public: typedef typename __alloc_traits::const_pointer const_pointer; static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD"); - static_assert((is_same<_CharT, value_type>::value), + static_assert((is_same<_CharT, typename traits_type::char_type>::value), "traits_type::char_type must be the same type as CharT"); static_assert((is_same<typename allocator_type::value_type, value_type>::value), "Allocator::value_type must be same type as value_type"); @@ -674,11 +671,11 @@ private: }; #if _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x01}; - enum {__long_mask = 0x1ul}; + static const size_type __short_mask = 0x01; + static const size_type __long_mask = 0x1ul; #else // _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x80}; - enum {__long_mask = ~(size_type(~0) >> 1)}; + static const size_type __short_mask = 0x80; + static const size_type __long_mask = ~(size_type(~0) >> 1); #endif // _LIBCPP_BIG_ENDIAN enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? @@ -704,11 +701,11 @@ private: }; #if _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x80}; - enum {__long_mask = ~(size_type(~0) >> 1)}; + static const size_type __short_mask = 0x80; + static const size_type __long_mask = ~(size_type(~0) >> 1); #else // _LIBCPP_BIG_ENDIAN - enum {__short_mask = 0x01}; - enum {__long_mask = 0x1ul}; + static const size_type __short_mask = 0x01; + static const size_type __long_mask = 0x1ul; #endif // _LIBCPP_BIG_ENDIAN enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? @@ -763,7 +760,7 @@ public: basic_string(const basic_string& __str); basic_string(const basic_string& __str, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string(basic_string&& __str) #if _LIBCPP_STD_VER <= 14 @@ -774,43 +771,44 @@ public: _LIBCPP_INLINE_VISIBILITY basic_string(basic_string&& __str, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES - _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s); +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s); _LIBCPP_INLINE_VISIBILITY - basic_string(const value_type* __s, const allocator_type& __a); + basic_string(const _CharT* __s, const _Allocator& __a); _LIBCPP_INLINE_VISIBILITY - basic_string(const value_type* __s, size_type __n); + basic_string(const _CharT* __s, size_type __n); _LIBCPP_INLINE_VISIBILITY - basic_string(const value_type* __s, size_type __n, const allocator_type& __a); + basic_string(const _CharT* __s, size_type __n, const _Allocator& __a); _LIBCPP_INLINE_VISIBILITY - basic_string(size_type __n, value_type __c); + basic_string(size_type __n, _CharT __c); _LIBCPP_INLINE_VISIBILITY - basic_string(size_type __n, value_type __c, const allocator_type& __a); + basic_string(size_type __n, _CharT __c, const _Allocator& __a); basic_string(const basic_string& __str, size_type __pos, size_type __n, - const allocator_type& __a = allocator_type()); + const _Allocator& __a = _Allocator()); _LIBCPP_INLINE_VISIBILITY basic_string(const basic_string& __str, size_type __pos, - const allocator_type& __a = allocator_type()); + const _Allocator& __a = _Allocator()); template<class _Tp> - basic_string(const _Tp& __t, size_type __pos, size_type __n, + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type(), typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0); _LIBCPP_INLINE_VISIBILITY explicit basic_string(__self_view __sv); _LIBCPP_INLINE_VISIBILITY - basic_string(__self_view __sv, const allocator_type& __a); + basic_string(__self_view __sv, const _Allocator& __a); template<class _InputIterator> _LIBCPP_INLINE_VISIBILITY basic_string(_InputIterator __first, _InputIterator __last); template<class _InputIterator> _LIBCPP_INLINE_VISIBILITY basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - basic_string(initializer_list<value_type> __il); + basic_string(initializer_list<_CharT> __il); _LIBCPP_INLINE_VISIBILITY - basic_string(initializer_list<value_type> __il, const allocator_type& __a); -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + basic_string(initializer_list<_CharT> __il, const _Allocator& __a); +#endif // _LIBCPP_CXX03_LANG inline ~basic_string(); @@ -824,17 +822,15 @@ public: #endif _LIBCPP_INLINE_VISIBILITY basic_string& operator=(__self_view __sv) {return assign(__sv);} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& operator=(basic_string&& __str) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); + _LIBCPP_INLINE_VISIBILITY + basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} #endif _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);} basic_string& operator=(value_type __c); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS - _LIBCPP_INLINE_VISIBILITY - basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #if _LIBCPP_DEBUG_LEVEL >= 2 _LIBCPP_INLINE_VISIBILITY @@ -900,7 +896,7 @@ public: void resize(size_type __n, value_type __c); _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());} - void reserve(size_type res_arg = 0); + void reserve(size_type __res_arg = 0); _LIBCPP_INLINE_VISIBILITY void shrink_to_fit() _NOEXCEPT {reserve();} _LIBCPP_INLINE_VISIBILITY @@ -917,9 +913,9 @@ public: _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);} _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);} _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;} -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& append(const basic_string& __str); @@ -927,7 +923,8 @@ public: basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); } basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos); template <class _Tp> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, basic_string& @@ -937,9 +934,11 @@ public: basic_string& append(const value_type* __s); basic_string& append(size_type __n, value_type __c); template <class _ForwardIterator> - inline basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator); + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator); template<class _InputIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_exactly_input_iterator<_InputIterator>::value || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, @@ -952,7 +951,8 @@ public: return *this; } template<class _ForwardIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_forward_iterator<_ForwardIterator>::value && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, @@ -963,10 +963,10 @@ public: return __append_forward_unsafe(__first, __last); } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG void push_back(value_type __c); _LIBCPP_INLINE_VISIBILITY @@ -980,25 +980,27 @@ public: basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); } _LIBCPP_INLINE_VISIBILITY basic_string& assign(const basic_string& __str) { return *this = __str; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY - basic_string& assign(basic_string&& str) + basic_string& assign(basic_string&& __str) _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) - {*this = _VSTD::move(str); return *this;} + {*this = _VSTD::move(__str); return *this;} #endif basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos); template <class _Tp> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, basic_string& >::type - assign(const _Tp & __t, size_type pos, size_type n=npos); + assign(const _Tp & __t, size_type __pos, size_type __n=npos); basic_string& assign(const value_type* __s, size_type __n); basic_string& assign(const value_type* __s); basic_string& assign(size_type __n, value_type __c); template<class _InputIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_exactly_input_iterator<_InputIterator>::value || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, @@ -1006,24 +1008,26 @@ public: >::type assign(_InputIterator __first, _InputIterator __last); template<class _ForwardIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_forward_iterator<_ForwardIterator>::value && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, basic_string& >::type assign(_ForwardIterator __first, _ForwardIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& insert(size_type __pos1, const basic_string& __str); _LIBCPP_INLINE_VISIBILITY basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); } template <class _Tp> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, basic_string& @@ -1037,7 +1041,8 @@ public: _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __pos, size_type __n, value_type __c); template<class _InputIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_exactly_input_iterator<_InputIterator>::value || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value, @@ -1045,18 +1050,19 @@ public: >::type insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); template<class _ForwardIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_forward_iterator<_ForwardIterator>::value && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value, iterator >::type insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY iterator insert(const_iterator __pos, initializer_list<value_type> __il) {return insert(__pos, __il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG basic_string& erase(size_type __pos = 0, size_type __n = npos); _LIBCPP_INLINE_VISIBILITY @@ -1070,7 +1076,8 @@ public: basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); } basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos); template <class _Tp> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, basic_string& @@ -1090,17 +1097,18 @@ public: _LIBCPP_INLINE_VISIBILITY basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c); template<class _InputIterator> - typename enable_if + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + typename enable_if < __is_input_iterator<_InputIterator>::value, basic_string& >::type replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) {return replace(__i1, __i2, __il.begin(), __il.end());} -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; _LIBCPP_INLINE_VISIBILITY @@ -1325,15 +1333,15 @@ private: __align_it<sizeof(value_type) < __alignment ? __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;} - inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + inline void __init(const value_type* __s, size_type __sz, size_type __reserve); - inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + inline void __init(const value_type* __s, size_type __sz); - inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + inline void __init(size_type __n, value_type __c); template <class _InputIterator> - inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + inline typename enable_if < __is_exactly_input_iterator<_InputIterator>::value, @@ -1342,7 +1350,7 @@ private: __init(_InputIterator __first, _InputIterator __last); template <class _ForwardIterator> - inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY + inline typename enable_if < __is_forward_iterator<_ForwardIterator>::value, @@ -1367,19 +1375,35 @@ private: _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const basic_string& __str, true_type) { - if (__alloc() != __str.__alloc()) + if (__alloc() == __str.__alloc()) + __alloc() = __str.__alloc(); + else { - clear(); - shrink_to_fit(); + if (!__str.__is_long()) + { + clear(); + shrink_to_fit(); + __alloc() = __str.__alloc(); + } + else + { + allocator_type __a = __str.__alloc(); + pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap()); + clear(); + shrink_to_fit(); + __alloc() = _VSTD::move(__a); + __set_long_pointer(__p); + __set_long_cap(__str.__get_long_cap()); + __set_long_size(__str.size()); + } } - __alloc() = __str.__alloc(); } _LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT {} -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY void __move_assign(basic_string& __str, false_type) _NOEXCEPT_(__alloc_traits::is_always_equal::value); @@ -1482,7 +1506,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __ #else _NOEXCEPT #endif -: __r_(__a) +: __r_(__second_tag(), __a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); @@ -1541,7 +1565,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_ty template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s) { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); __init(__s, traits_type::length(__s)); @@ -1552,8 +1576,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s) template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) + : __r_(__second_tag(), __a) { _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); __init(__s, traits_type::length(__s)); @@ -1564,7 +1588,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, c template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); __init(__s, __n); @@ -1575,8 +1599,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, s template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) + : __r_(__second_tag(), __a) { _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); __init(__s, __n); @@ -1587,7 +1611,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, s template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) - : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc())) + : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) { if (!__str.__is_long()) __r_.first().__r = __str.__r_.first().__r; @@ -1599,8 +1623,9 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st } template <class _CharT, class _Traits, class _Allocator> -basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string( + const basic_string& __str, const allocator_type& __a) + : __r_(__second_tag(), __a) { if (!__str.__is_long()) __r_.first().__r = __str.__r_.first().__r; @@ -1611,7 +1636,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st #endif } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -1634,7 +1659,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a) - : __r_(__a) + : __r_(__second_tag(), __a) { if (__str.__is_long() && __a != __str.__alloc()) // copy, not move __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size()); @@ -1650,7 +1675,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, co #endif } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> void @@ -1678,7 +1703,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c) +basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c) { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1688,8 +1713,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_typ template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a) + : __r_(__second_tag(), __a) { __init(__n, __c); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1698,9 +1723,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_typ } template <class _CharT, class _Traits, class _Allocator> -basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n, - const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, + size_type __pos, size_type __n, + const _Allocator& __a) + : __r_(__second_tag(), __a) { size_type __str_sz = __str.size(); if (__pos > __str_sz) @@ -1714,8 +1740,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, - const allocator_type& __a) - : __r_(__a) + const _Allocator& __a) + : __r_(__second_tag(), __a) { size_type __str_sz = __str.size(); if (__pos > __str_sz) @@ -1731,13 +1757,13 @@ template <class _Tp> basic_string<_CharT, _Traits, _Allocator>::basic_string( const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a, typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *) - : __r_(__a) + : __r_(__second_tag(), __a) { __self_view __sv = __self_view(__t).substr(__pos, __n); __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); -#endif +#endif } template <class _CharT, class _Traits, class _Allocator> @@ -1752,8 +1778,8 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv) template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const allocator_type& __a) - : __r_(__a) +basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const _Allocator& __a) + : __r_(__second_tag(), __a) { __init(__sv.data(), __sv.size()); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1835,7 +1861,7 @@ template<class _InputIterator> inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) - : __r_(__a) + : __r_(__second_tag(), __a) { __init(__first, __last); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1843,11 +1869,12 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, #endif } -#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il) +basic_string<_CharT, _Traits, _Allocator>::basic_string( + initializer_list<_CharT> __il) { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1857,8 +1884,10 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_t template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY -basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a) - : __r_(__a) + +basic_string<_CharT, _Traits, _Allocator>::basic_string( + initializer_list<_CharT> __il, const _Allocator& __a) + : __r_(__second_tag(), __a) { __init(__il.begin(), __il.end()); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1866,7 +1895,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_t #endif } -#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>::~basic_string() @@ -2015,7 +2044,7 @@ basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) return *this; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -2242,7 +2271,9 @@ basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe( size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); if (__n) { - if ( __ptr_in_range(&*__first, data(), data() + size())) + typedef typename iterator_traits<_ForwardIterator>::reference _CharRef; + _CharRef __tmp_ref = *__first; + if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size())) { const basic_string __temp (__first, __last, __alloc()); append(__temp.data(), __temp.size()); @@ -2406,7 +2437,9 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _Forward size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); if (__n) { - if ( __ptr_in_range(&*__first, data(), data() + size())) + typedef typename iterator_traits<_ForwardIterator>::reference _CharRef; + _CharRef __tmp_char = *__first; + if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size())) { const basic_string __temp(__first, __last, __alloc()); return insert(__pos, __temp.data(), __temp.data() + __temp.size()); @@ -2526,6 +2559,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_typ template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); size_type __sz = size(); @@ -2565,6 +2599,8 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __ } traits_type::move(__p + __pos, __s, __n2); __finish: +// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow, +// but this is a safe operation, so we disable the check. __sz += __n2 - __n1; __set_size(__sz); __invalidate_iterators_past(__sz); @@ -2578,6 +2614,7 @@ __finish: template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK { size_type __sz = size(); if (__pos > __sz) @@ -3748,7 +3785,7 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) return __r; } -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -3808,7 +3845,7 @@ operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) return _VSTD::move(__lhs); } -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG // swap @@ -3910,7 +3947,7 @@ basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Allocator>& __str); -#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_CXX03_LANG template<class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY @@ -3924,7 +3961,7 @@ basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>&& __is, basic_string<_CharT, _Traits, _Allocator>& __str); -#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif // _LIBCPP_CXX03_LANG #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -3962,6 +3999,9 @@ basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* #endif // _LIBCPP_DEBUG_LEVEL >= 2 +_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 // Literal suffixes for basic_string [basic.string.literals] inline namespace literals @@ -3995,10 +4035,8 @@ inline namespace literals } #endif -_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>) -_LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&)) - _LIBCPP_END_NAMESPACE_STD +_LIBCPP_POP_MACROS + #endif // _LIBCPP_STRING |