Fix basic_string_view typedefs and enforce preconditions
authorJonathan Wakely <jwakely@redhat.com>
Wed, 24 Apr 2019 15:17:53 +0000 (16:17 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 24 Apr 2019 15:17:53 +0000 (16:17 +0100)
commitfb8b3e2993f4f1bb646369feab59b3bd80d1d0e1
treeb45764ac1c617df739544c0de1c0fa03ef7e73dd
parent92750002ef200965cb33aa5af68676b540564758
Fix basic_string_view typedefs and enforce preconditions

The basic_string_view::pointer and basic_string_view::reference typedefs
are supposed to refer to the non-const value type.

In previous standards having traits_type::char_type different to
value_type was simply undefined, but in the C++2a draft it's ill-formed,
as changed by P1148R0. For std::basic_string and iostreams we might
want to only enforce this conditionally for __cplusplus > 201703L but
for std::basic_string_view we don't have backwards compatibility
concerns. Also add assertions to verify the _CharT argument is a
"char-like" type (non-array, trivial, standard layout type).

Also remove the non-standard basic_string_view::_M_check and
basic_string_view::_M_limit member functions, replacing them with
non-member functions that will still exist even if basic_string_view is
specialized by the program.

* include/experimental/string_view (basic_string_view::pointer)
(basic_string_view::reference): Fix to refer to non-const value_type.
* include/bits/basic_string.h (basic_string): Use __sv_check and
__sv_limit instead of basic_string_view::_M_check and
basic_string_view::_M_limit.
* include/std/string_view (__sv_check, __sv_limit): New
helper functions to replace basic_string_view::_M_check and
basic_string_view::_M_limit.
(basic_string_view): Add static assertions to enforce ill-formed
requirement for traits_type::char_type from P1148R0, and to enforce
required properties of char-like types.
(basic_string_view::pointer, basic_string_view::reference): Fix to
refer to non-const value_type.
(basic_string_view::operator[], basic_string_view::at)
(basic_string_view::front, basic_string_view::back)
(basic_string_view::data): Use const_reference and const_pointer
typedefs for return types.
(basic_string_view::_M_check, basic_string_view::_M_limit): Remove.
(hash<wstring_view>): Fix argument_type typedef.
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/
char/1.cc: Fix expected return type of basic_string_view::data().
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/
wchar_t/1.cc: Likewise.
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/
char/1.cc: Likewise.
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/
wchar_t/1.cc: Likewise.
* testsuite/21_strings/basic_string_view/requirements/traits_neg.cc:
New test.
* testsuite/21_strings/basic_string_view/requirements/typedefs.cc:
Check reference and pointer typedefs.
* testsuite/experimental/string_view/requirements/typedefs.cc:
Likewise.
* testsuite/experimental/string_view/modifiers/remove_prefix/char/1.cc:
Fix expected return type of basic_string_view::data().
* testsuite/experimental/string_view/modifiers/remove_prefix/wchar_t/
1.cc: Likewise.
* testsuite/experimental/string_view/modifiers/remove_suffix/char/1.cc:
Likewise.
* testsuite/experimental/string_view/modifiers/remove_suffix/wchar_t/
1.cc: Likewise.

From-SVN: r270548
15 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/experimental/string_view
libstdc++-v3/include/std/string_view
libstdc++-v3/testsuite/21_strings/basic_string_view/modifiers/remove_prefix/char/1.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/modifiers/remove_suffix/char/1.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/traits_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/typedefs.cc
libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_prefix/char/1.cc
libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_prefix/wchar_t/1.cc
libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_suffix/char/1.cc
libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_suffix/wchar_t/1.cc
libstdc++-v3/testsuite/experimental/string_view/requirements/typedefs.cc