diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-24 01:00:43 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-24 01:00:43 +0000 |
commit | c900243a09095e1ada97fb2e66ec08f68f277959 (patch) | |
tree | a27aa310f08ab03bb4eead4e773d3837c9f46b32 | |
parent | 0564cdb94a7a1facbb0dbf888ceb90638aa70ecd (diff) |
Vendor import of libc++ trunk r321414:vendor/libc++/libc++-trunk-r321426vendor/libc++/libc++-trunk-r321414
Notes
Notes:
svn path=/vendor/libc++/dist/; revision=327128
svn path=/vendor/libc++/libc++-trunk-r321426/; revision=327157; tag=vendor/libc++/libc++-trunk-r321426
-rw-r--r-- | include/sstream | 5 | ||||
-rw-r--r-- | include/string_view | 4 | ||||
-rw-r--r-- | test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp | 24 | ||||
-rw-r--r-- | test/std/strings/string.view/types.pass.cpp | 77 |
4 files changed, 106 insertions, 4 deletions
diff --git a/include/sstream b/include/sstream index 34b0014c14ad..b01f47b6872c 100644 --- a/include/sstream +++ b/include/sstream @@ -577,6 +577,7 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) && __way == ios_base::cur) return pos_type(-1); + const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data(); off_type __noff; switch (__way) { @@ -590,13 +591,13 @@ basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off, __noff = this->pptr() - this->pbase(); break; case ios_base::end: - __noff = __hm_ - __str_.data(); + __noff = __hm; break; default: return pos_type(-1); } __noff += __off; - if (__noff < 0 || __hm_ - __str_.data() < __noff) + if (__noff < 0 || __hm < __noff) return pos_type(-1); if (__noff != 0) { diff --git a/include/string_view b/include/string_view index 4d8358288f0c..72cf816e8d52 100644 --- a/include/string_view +++ b/include/string_view @@ -196,9 +196,9 @@ public: // types typedef _Traits traits_type; typedef _CharT value_type; - typedef const _CharT* pointer; + typedef _CharT* pointer; typedef const _CharT* const_pointer; - typedef const _CharT& reference; + typedef _CharT& reference; typedef const _CharT& const_reference; typedef const_pointer const_iterator; // See [string.view.iterators] typedef const_iterator iterator; diff --git a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp index 6d20db13189a..8ec69cb24b60 100644 --- a/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp +++ b/test/std/input.output/string.streams/stringbuf/stringbuf.virtuals/seekoff.pass.cpp @@ -21,6 +21,30 @@ int main() { { + std::stringbuf sb(std::ios_base::in); + assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1); + assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1); + assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == -1); + assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1); + assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1); + assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1); + assert(sb.pubseekoff(0, std::ios_base::beg, std::ios_base::in) == 0); + assert(sb.pubseekoff(0, std::ios_base::cur, std::ios_base::in) == 0); + assert(sb.pubseekoff(0, std::ios_base::end, std::ios_base::in) == 0); + } + { + std::stringbuf sb(std::ios_base::out); + assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == -1); + assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == -1); + assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == -1); + assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1); + assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1); + assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1); + assert(sb.pubseekoff(0, std::ios_base::beg, std::ios_base::out) == 0); + assert(sb.pubseekoff(0, std::ios_base::cur, std::ios_base::out) == 0); + assert(sb.pubseekoff(0, std::ios_base::end, std::ios_base::out) == 0); + } + { std::stringbuf sb("0123456789", std::ios_base::in); assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1); assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1); diff --git a/test/std/strings/string.view/types.pass.cpp b/test/std/strings/string.view/types.pass.cpp new file mode 100644 index 000000000000..68bbc29b9aa0 --- /dev/null +++ b/test/std/strings/string.view/types.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string_view> + +// Test nested types and default template args: + +// template<class charT, class traits = char_traits<charT>> +// { +// public: +// // types: +// using traits_type = traits; +// using value_type = charT; +// using pointer = value_type*; +// using const_pointer = const value_type*; +// using reference = value_type&; +// using const_reference = const value_type&; +// using const_iterator = implementation-defined ; // see 24.4.2.2 +// using iterator = const_iterator; +// using const_reverse_iterator = reverse_iterator<const_iterator>; +// using iterator = const_reverse_iterator; +// using size_type = size_t; +// using difference_type = ptrdiff_t; +// static constexpr size_type npos = size_type(-1); +// +// }; + +#include <string_view> +#include <iterator> +#include <type_traits> + +#include "test_macros.h" + +template <class Traits> +void +test() +{ + typedef std::basic_string_view<typename Traits::char_type, Traits> S; + + static_assert((std::is_same<typename S::traits_type, Traits>::value), ""); + static_assert((std::is_same<typename S::value_type, typename Traits::char_type>::value), ""); + static_assert((std::is_same<typename S::size_type, std::size_t>::value), ""); + static_assert((std::is_same<typename S::difference_type, ptrdiff_t>::value), ""); + static_assert((std::is_same<typename S::reference, typename S::value_type&>::value), ""); + static_assert((std::is_same<typename S::const_reference, const typename S::value_type&>::value), ""); + static_assert((std::is_same<typename S::pointer, typename S::value_type*>::value), ""); + static_assert((std::is_same<typename S::const_pointer, const typename S::value_type*>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename S::iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits<typename S::const_iterator>::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename S::reverse_iterator, + std::reverse_iterator<typename S::iterator> >::value), ""); + static_assert((std::is_same< + typename S::const_reverse_iterator, + std::reverse_iterator<typename S::const_iterator> >::value), ""); + static_assert(S::npos == -1, ""); + static_assert((std::is_same<typename S::iterator, typename S::const_iterator>::value), ""); + static_assert((std::is_same<typename S::reverse_iterator, typename S::const_reverse_iterator>::value), ""); +} + +int main() +{ + test<std::char_traits<char> >(); + test<std::char_traits<wchar_t> >(); + static_assert((std::is_same<std::basic_string_view<char>::traits_type, + std::char_traits<char> >::value), ""); +} |