* [PATCH v3 3/5] Add gdb::string_view
2018-04-07 13:26 [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Simon Marchi
@ 2018-04-07 13:26 ` Simon Marchi
2018-04-09 13:44 ` Pedro Alves
2018-04-07 13:26 ` [PATCH v3 5/5] Adapt and integrate string_view tests Simon Marchi
` (4 subsequent siblings)
5 siblings, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2018-04-07 13:26 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
New in v3:
* Base on the implementation in experimental/, since it is easier to
adapt to the c++ standard we follow (c++11). I didn't see any
significant fix to import from the std/ version.
* Tested against clang and clang+libc++ to make sure we don't rely on
anything internal and specific to libstdc++. This caught a few
issues.
* Remove hash helpers, operator<<, operator ""sv.
We had a few times the need for a data structure that does essentially
what C++17's std::string_view does, which is to give an std::string-like
interface (only the read-only operations) to an arbitrary character
buffer.
This patch adapts the files copied from libstdc++ by the previous patch
to integrate them with GDB. Here's a summary of the changes:
* Remove things related to wstring_view, u16string_view and
u32string_view (I don't think we need them, but we can always add them
later).
* Remove usages of _GLIBCXX_BEGIN_NAMESPACE_VERSION and
_GLIBCXX_END_NAMESPACE_VERSION.
* Put the code in the gdb namespace. I had to add a few "std::" in
front of std type usages.
* Change __throw_out_of_range_fmt() for error().
* Make gdb::string_view an alias of std::string_view when building
with >= c++17.
* Remove a bunch of constexpr, because they are not valid in c++11
(e.g. they are not a single return line).
* Use std::common_type<_Tp>::type instead of std::common_type_t<_Tp>,
because c++11 doesn't have the later.
* Remove the #pragma GCC system_header, since that silences some
warnings that we might want to have if we're doing something not
correctly.
* Remove operator ""sv. It would need a lot of work to make all
supported compilers happy, and we can easily live without it.
* Remove operator<<. It is implemented using __ostream_insert (a
libstdc++ internal). Bringing it in might be possible, but I don't
think that would be worth the effort, since we don't really use
streams at the moment.
* Replace internal libstdc++ asserts ( __glibcxx_assert and
__glibcxx_requires_string_len) with gdb_assert.
* Remove hash helpers, because they use libstdc++ internal functions.
If we need them we always import them later.
The string_view class in cli/cli-script.c is removed and its usage
replaced with the new gdb::string_view.
gdb/ChangeLog:
* common/gdb_string_view.h: Remove libstdc++ implementation
details, adjust to gdb reality.
* common/gdb_string_view.tcc: Likewise.
* cli/cli-script.c (struct string_view): Remove.
(user_args) <m_args>: Change element type to gdb::string_view.
(user_args::insert_args): Adjust.
---
gdb/cli/cli-script.c | 17 +--
gdb/common/gdb_string_view.h | 298 ++++++++++++-----------------------------
gdb/common/gdb_string_view.tcc | 62 ++++-----
3 files changed, 117 insertions(+), 260 deletions(-)
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 366c42227c62..cdfda113a7c5 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -32,6 +32,7 @@
#include "extension.h"
#include "interps.h"
#include "compile/compile.h"
+#include "common/gdb_string_view.h"
#include <vector>
@@ -54,18 +55,6 @@ static int command_nest_depth = 1;
/* This is to prevent certain commands being printed twice. */
static int suppress_next_print_command_trace = 0;
-/* A non-owning slice of a string. */
-
-struct string_view
-{
- string_view (const char *str_, size_t len_)
- : str (str_), len (len_)
- {}
-
- const char *str;
- size_t len;
-};
-
/* Structure for arguments to user defined functions. */
class user_args
@@ -91,7 +80,7 @@ private:
std::string m_command_line;
/* The arguments. Each element points inside M_COMMAND_LINE. */
- std::vector<string_view> m_args;
+ std::vector<gdb::string_view> m_args;
};
/* The stack of arguments passed to user defined functions. We need a
@@ -827,7 +816,7 @@ user_args::insert_args (const char *line) const
error (_("Missing argument %ld in user function."), i);
else
{
- new_line.append (m_args[i].str, m_args[i].len);
+ new_line.append (m_args[i].data (), m_args[i].length ());
line = tmp;
}
}
diff --git a/gdb/common/gdb_string_view.h b/gdb/common/gdb_string_view.h
index e42d5acde785..02c6ffd2fc8f 100644
--- a/gdb/common/gdb_string_view.h
+++ b/gdb/common/gdb_string_view.h
@@ -1,5 +1,8 @@
// Components for manipulating non-owning sequences of characters -*- C++ -*-
+// Note: This file has been stolen from the gcc repo
+// (libstdc++-v3/include/experimental/string_view) and has local modifications.
+
// Copyright (C) 2013-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -22,34 +25,27 @@
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
-/** @file experimental/string_view
- * This is a TS C++ Library header.
- */
-
//
// N3762 basic_string_view library
//
-#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW
-#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW 1
+#ifndef GDB_STRING_VIEW_H
+#define GDB_STRING_VIEW_H 1
+
+#if __cplusplus >= 201703L
-#pragma GCC system_header
+#include <string_view>
-#if __cplusplus >= 201402L
+namespace gdb {
+ using string_view = std::string_view;
+} /* namespace gdb */
+
+#else /* __cplusplus < 201703L */
#include <string>
#include <limits>
-#include <experimental/bits/lfts_config.h>
-
-namespace std _GLIBCXX_VISIBILITY(default)
-{
-_GLIBCXX_BEGIN_NAMESPACE_VERSION
-namespace experimental
-{
-inline namespace fundamentals_v1
-{
-#define __cpp_lib_experimental_string_view 201411
+namespace gdb {
/**
* @class basic_string_view <experimental/string_view>
@@ -100,12 +96,12 @@ inline namespace fundamentals_v1
constexpr basic_string_view(const basic_string_view&) noexcept = default;
template<typename _Allocator>
- basic_string_view(const basic_string<_CharT, _Traits,
+ basic_string_view(const std::basic_string<_CharT, _Traits,
_Allocator>& __str) noexcept
: _M_len{__str.length()}, _M_str{__str.data()}
{ }
- constexpr basic_string_view(const _CharT* __str)
+ basic_string_view(const _CharT* __str)
: _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
_M_str{__str}
{ }
@@ -188,10 +184,10 @@ inline namespace fundamentals_v1
{
return __pos < this->_M_len
? *(this->_M_str + __pos)
- : (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
- "(which is %zu) >= this->size() "
- "(which is %zu)"),
- __pos, this->size()),
+ : (error (_("basic_string_view::at: __pos "
+ "(which is %zu) >= this->size() "
+ "(which is %zu)"),
+ __pos, this->size()),
*this->_M_str);
}
@@ -217,19 +213,19 @@ inline namespace fundamentals_v1
// [string.view.modifiers], modifiers:
- constexpr void
+ void
remove_prefix(size_type __n)
{
- __glibcxx_assert(this->_M_len >= __n);
+ gdb_assert (this->_M_len >= __n);
this->_M_str += __n;
this->_M_len -= __n;
}
- constexpr void
+ void
remove_suffix(size_type __n)
{ this->_M_len -= __n; }
- constexpr void
+ void
swap(basic_string_view& __sv) noexcept
{
auto __tmp = *this;
@@ -241,13 +237,13 @@ inline namespace fundamentals_v1
// [string.view.ops], string operations:
template<typename _Allocator>
- explicit operator basic_string<_CharT, _Traits, _Allocator>() const
+ explicit operator std::basic_string<_CharT, _Traits, _Allocator>() const
{
return { this->_M_str, this->_M_len };
}
template<typename _Allocator = std::allocator<_CharT>>
- basic_string<_CharT, _Traits, _Allocator>
+ std::basic_string<_CharT, _Traits, _Allocator>
to_string(const _Allocator& __alloc = _Allocator()) const
{
return { this->_M_str, this->_M_len, __alloc };
@@ -256,12 +252,12 @@ inline namespace fundamentals_v1
size_type
copy(_CharT* __str, size_type __n, size_type __pos = 0) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
if (__pos > this->_M_len)
- __throw_out_of_range_fmt(__N("basic_string_view::copy: __pos "
- "(which is %zu) > this->size() "
- "(which is %zu)"),
- __pos, this->size());
+ error (_("basic_string_view::copy: __pos "
+ "(which is %zu) > this->size() "
+ "(which is %zu)"),
+ __pos, this->size());
size_type __rlen{std::min(__n, size_type{this->_M_len - __pos})};
for (auto __begin = this->_M_str + __pos,
__end = __begin + __rlen; __begin != __end;)
@@ -272,19 +268,19 @@ inline namespace fundamentals_v1
// [string.view.ops], string operations:
- constexpr basic_string_view
+ basic_string_view
substr(size_type __pos, size_type __n=npos) const
{
return __pos <= this->_M_len
? basic_string_view{this->_M_str + __pos,
std::min(__n, size_type{this->_M_len - __pos})}
- : (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos "
- "(which is %zu) > this->size() "
- "(which is %zu)"),
- __pos, this->size()), basic_string_view{});
+ : (error (_("basic_string_view::substr: __pos "
+ "(which is %zu) > this->size() "
+ "(which is %zu)"),
+ __pos, this->size()), basic_string_view{});
}
- constexpr int
+ int
compare(basic_string_view __str) const noexcept
{
int __ret = traits_type::compare(this->_M_str, __str._M_str,
@@ -294,24 +290,24 @@ inline namespace fundamentals_v1
return __ret;
}
- constexpr int
+ int
compare(size_type __pos1, size_type __n1, basic_string_view __str) const
{ return this->substr(__pos1, __n1).compare(__str); }
- constexpr int
+ int
compare(size_type __pos1, size_type __n1,
basic_string_view __str, size_type __pos2, size_type __n2) const
{ return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }
- constexpr int
+ int
compare(const _CharT* __str) const noexcept
{ return this->compare(basic_string_view{__str}); }
- constexpr int
+ int
compare(size_type __pos1, size_type __n1, const _CharT* __str) const
{ return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }
- constexpr int
+ int
compare(size_type __pos1, size_type __n1,
const _CharT* __str, size_type __n2) const
{
@@ -319,97 +315,97 @@ inline namespace fundamentals_v1
.compare(basic_string_view(__str, __n2));
}
- constexpr size_type
+ size_type
find(basic_string_view __str, size_type __pos = 0) const noexcept
{ return this->find(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ size_type
find(_CharT __c, size_type __pos=0) const noexcept;
- constexpr size_type
+ size_type
find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
- constexpr size_type
+ size_type
find(const _CharT* __str, size_type __pos=0) const noexcept
{ return this->find(__str, __pos, traits_type::length(__str)); }
- constexpr size_type
+ size_type
rfind(basic_string_view __str, size_type __pos = npos) const noexcept
{ return this->rfind(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ size_type
rfind(_CharT __c, size_type __pos = npos) const noexcept;
- constexpr size_type
+ size_type
rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
- constexpr size_type
+ size_type
rfind(const _CharT* __str, size_type __pos = npos) const noexcept
{ return this->rfind(__str, __pos, traits_type::length(__str)); }
- constexpr size_type
+ size_type
find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept
{ return this->find_first_of(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ size_type
find_first_of(_CharT __c, size_type __pos = 0) const noexcept
{ return this->find(__c, __pos); }
- constexpr size_type
+ size_type
find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;
- constexpr size_type
+ size_type
find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept
{ return this->find_first_of(__str, __pos, traits_type::length(__str)); }
- constexpr size_type
+ size_type
find_last_of(basic_string_view __str,
size_type __pos = npos) const noexcept
{ return this->find_last_of(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ size_type
find_last_of(_CharT __c, size_type __pos=npos) const noexcept
{ return this->rfind(__c, __pos); }
- constexpr size_type
+ size_type
find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;
- constexpr size_type
+ size_type
find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept
{ return this->find_last_of(__str, __pos, traits_type::length(__str)); }
- constexpr size_type
+ size_type
find_first_not_of(basic_string_view __str,
size_type __pos = 0) const noexcept
{ return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ size_type
find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;
- constexpr size_type
+ size_type
find_first_not_of(const _CharT* __str,
size_type __pos, size_type __n) const;
- constexpr size_type
+ size_type
find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept
{
return this->find_first_not_of(__str, __pos,
traits_type::length(__str));
}
- constexpr size_type
+ size_type
find_last_not_of(basic_string_view __str,
size_type __pos = npos) const noexcept
{ return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ size_type
find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;
- constexpr size_type
+ size_type
find_last_not_of(const _CharT* __str,
size_type __pos, size_type __n) const;
- constexpr size_type
+ size_type
find_last_not_of(const _CharT* __str,
size_type __pos = npos) const noexcept
{
@@ -441,240 +437,124 @@ inline namespace fundamentals_v1
// argument participates in template argument deduction and the other
// argument gets implicitly converted to the deduced type. See n3766.html.
template<typename _Tp>
- using __idt = common_type_t<_Tp>;
+ using __idt = typename std::common_type<_Tp>::type;
}
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator==(basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.size() == __y.size() && __x.compare(__y) == 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator==(basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.size() == __y.size() && __x.compare(__y) == 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.size() == __y.size() && __x.compare(__y) == 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator!=(basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return !(__x == __y); }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator!=(basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return !(__x == __y); }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return !(__x == __y); }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator< (basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) < 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator< (basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.compare(__y) < 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) < 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator> (basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) > 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator> (basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.compare(__y) > 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) > 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator<=(basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) <= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator<=(basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.compare(__y) <= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) <= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator>=(basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) >= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator>=(basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.compare(__y) >= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ bool
operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) >= 0; }
- // [string.view.io], Inserters and extractors
- template<typename _CharT, typename _Traits>
- inline basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os,
- basic_string_view<_CharT,_Traits> __str)
- { return __ostream_insert(__os, __str.data(), __str.size()); }
-
-
// basic_string_view typedef names
using string_view = basic_string_view<char>;
-#ifdef _GLIBCXX_USE_WCHAR_T
- using wstring_view = basic_string_view<wchar_t>;
-#endif
-#ifdef _GLIBCXX_USE_C99_STDINT_TR1
- using u16string_view = basic_string_view<char16_t>;
- using u32string_view = basic_string_view<char32_t>;
-#endif
-} // namespace fundamentals_v1
-} // namespace experimental
-
-
- // [string.view.hash], hash support:
- template<typename _Tp>
- struct hash;
-
- template<>
- struct hash<experimental::string_view>
- : public __hash_base<size_t, experimental::string_view>
- {
- size_t
- operator()(const experimental::string_view& __str) const noexcept
- { return std::_Hash_impl::hash(__str.data(), __str.length()); }
- };
+} /* namespace gdb */
- template<>
- struct __is_fast_hash<hash<experimental::string_view>> : std::false_type
- { };
+#include "gdb_string_view.tcc"
-#ifdef _GLIBCXX_USE_WCHAR_T
- template<>
- struct hash<experimental::wstring_view>
- : public __hash_base<size_t, wstring>
- {
- size_t
- operator()(const experimental::wstring_view& __s) const noexcept
- { return std::_Hash_impl::hash(__s.data(),
- __s.length() * sizeof(wchar_t)); }
- };
-
- template<>
- struct __is_fast_hash<hash<experimental::wstring_view>> : std::false_type
- { };
-#endif
+#endif // __cplusplus < 201703L
-#ifdef _GLIBCXX_USE_C99_STDINT_TR1
- template<>
- struct hash<experimental::u16string_view>
- : public __hash_base<size_t, experimental::u16string_view>
- {
- size_t
- operator()(const experimental::u16string_view& __s) const noexcept
- { return std::_Hash_impl::hash(__s.data(),
- __s.length() * sizeof(char16_t)); }
- };
-
- template<>
- struct __is_fast_hash<hash<experimental::u16string_view>> : std::false_type
- { };
-
- template<>
- struct hash<experimental::u32string_view>
- : public __hash_base<size_t, experimental::u32string_view>
- {
- size_t
- operator()(const experimental::u32string_view& __s) const noexcept
- { return std::_Hash_impl::hash(__s.data(),
- __s.length() * sizeof(char32_t)); }
- };
-
- template<>
- struct __is_fast_hash<hash<experimental::u32string_view>> : std::false_type
- { };
-#endif
-
-namespace experimental
-{
- // I added these EMSR.
- inline namespace literals
- {
- inline namespace string_view_literals
- {
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wliteral-suffix"
- inline constexpr basic_string_view<char>
- operator""sv(const char* __str, size_t __len) noexcept
- { return basic_string_view<char>{__str, __len}; }
-
-#ifdef _GLIBCXX_USE_WCHAR_T
- inline constexpr basic_string_view<wchar_t>
- operator""sv(const wchar_t* __str, size_t __len) noexcept
- { return basic_string_view<wchar_t>{__str, __len}; }
-#endif
-
-#ifdef _GLIBCXX_USE_C99_STDINT_TR1
- inline constexpr basic_string_view<char16_t>
- operator""sv(const char16_t* __str, size_t __len) noexcept
- { return basic_string_view<char16_t>{__str, __len}; }
-
- inline constexpr basic_string_view<char32_t>
- operator""sv(const char32_t* __str, size_t __len) noexcept
- { return basic_string_view<char32_t>{__str, __len}; }
-#endif
-#pragma GCC diagnostic pop
- } // namespace string_literals
- } // namespace literals
-} // namespace experimental
-
-_GLIBCXX_END_NAMESPACE_VERSION
-} // namespace std
-
-#include <experimental/bits/string_view.tcc>
-
-#endif // __cplusplus <= 201103L
-
-#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW
+#endif /* GDB_STRING_VIEW_H */
diff --git a/gdb/common/gdb_string_view.tcc b/gdb/common/gdb_string_view.tcc
index 579ececd8d82..e79fe742555a 100644
--- a/gdb/common/gdb_string_view.tcc
+++ b/gdb/common/gdb_string_view.tcc
@@ -1,5 +1,9 @@
// Components for manipulating non-owning sequences of characters -*- C++ -*-
+// Note: This file has been stolen from the gcc repo
+// (libstdc++-v3/include/experimental/bits/string_view.tcc) and has local
+// modifications.
+
// Copyright (C) 2013-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -31,27 +35,17 @@
// N3762 basic_string_view library
//
-#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC
-#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC 1
-
-#pragma GCC system_header
-
-#if __cplusplus >= 201402L
-
-namespace std _GLIBCXX_VISIBILITY(default)
-{
-_GLIBCXX_BEGIN_NAMESPACE_VERSION
+#ifndef GDB_STRING_VIEW_TCC
+#define GDB_STRING_VIEW_TCC 1
-namespace experimental
-{
-inline namespace fundamentals_v1
+namespace gdb
{
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
if (__n == 0)
return __pos <= this->_M_len ? __pos : npos;
@@ -68,7 +62,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find(_CharT __c, size_type __pos) const noexcept
{
@@ -84,11 +78,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
if (__n <= this->_M_len)
{
@@ -104,7 +98,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
rfind(_CharT __c, size_type __pos) const noexcept
{
@@ -121,11 +115,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
for (; __n && __pos < this->_M_len; ++__pos)
{
const _CharT* __p = traits_type::find(__str, __n,
@@ -137,11 +131,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
size_type __size = this->size();
if (__size && __n)
{
@@ -158,11 +152,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
for (; __pos < this->_M_len; ++__pos)
if (!traits_type::find(__str, __n, this->_M_str[__pos]))
return __pos;
@@ -170,7 +164,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_not_of(_CharT __c, size_type __pos) const noexcept
{
@@ -181,11 +175,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
size_type __size = this->_M_len;
if (__size)
{
@@ -202,7 +196,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_not_of(_CharT __c, size_type __pos) const noexcept
{
@@ -220,12 +214,6 @@ inline namespace fundamentals_v1
}
return npos;
}
-} // namespace fundamentals_v1
-} // namespace experimental
-
-_GLIBCXX_END_NAMESPACE_VERSION
-} // namespace std
-
-#endif // __cplusplus <= 201103L
+} // namespace gdb
-#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC
+#endif // GDB_STRING_VIEW_TCC
--
2.16.3
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v3 2/5] Copy string_view files from libstdc++
2018-04-07 13:26 [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Simon Marchi
2018-04-07 13:26 ` [PATCH v3 3/5] Add gdb::string_view Simon Marchi
2018-04-07 13:26 ` [PATCH v3 5/5] Adapt and integrate string_view tests Simon Marchi
@ 2018-04-07 13:26 ` Simon Marchi
2018-04-09 13:44 ` Pedro Alves
2018-04-07 13:37 ` [PATCH v3 4/5] Copy string_view tests " Simon Marchi
` (2 subsequent siblings)
5 siblings, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2018-04-07 13:26 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
New in v3:
* Prefix files with gdb_, to avoid confusion with the standard files.
This patch copies the following files from libstdc++ (commit
02a4441f002c):
${gcc}/include/std/string_view -> ${binutils-gdb}/gdb/common/gdb_string_view.h
${gcc}/include/bits/string_view.tcc -> ${binutils-gdb}/gdb/common/gdb_string_view.tcc
The local modifications are done in the following patch in order to make
it easier to review them.
gdb/ChangeLog:
* common/gdb_string_view.h: New file.
* common/gdb_string_view.tcc: New file.
---
gdb/common/gdb_string_view.h | 680 +++++++++++++++++++++++++++++++++++++++++
gdb/common/gdb_string_view.tcc | 231 ++++++++++++++
2 files changed, 911 insertions(+)
create mode 100644 gdb/common/gdb_string_view.h
create mode 100644 gdb/common/gdb_string_view.tcc
diff --git a/gdb/common/gdb_string_view.h b/gdb/common/gdb_string_view.h
new file mode 100644
index 000000000000..e42d5acde785
--- /dev/null
+++ b/gdb/common/gdb_string_view.h
@@ -0,0 +1,680 @@
+// Components for manipulating non-owning sequences of characters -*- C++ -*-
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file experimental/string_view
+ * This is a TS C++ Library header.
+ */
+
+//
+// N3762 basic_string_view library
+//
+
+#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW
+#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW 1
+
+#pragma GCC system_header
+
+#if __cplusplus >= 201402L
+
+#include <string>
+#include <limits>
+#include <experimental/bits/lfts_config.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+namespace experimental
+{
+inline namespace fundamentals_v1
+{
+#define __cpp_lib_experimental_string_view 201411
+
+ /**
+ * @class basic_string_view <experimental/string_view>
+ * @brief A non-owning reference to a string.
+ *
+ * @ingroup strings
+ * @ingroup sequences
+ * @ingroup experimental
+ *
+ * @tparam _CharT Type of character
+ * @tparam _Traits Traits for character type, defaults to
+ * char_traits<_CharT>.
+ *
+ * A basic_string_view looks like this:
+ *
+ * @code
+ * _CharT* _M_str
+ * size_t _M_len
+ * @endcode
+ */
+ template<typename _CharT, typename _Traits = std::char_traits<_CharT>>
+ class basic_string_view
+ {
+ public:
+
+ // types
+ using traits_type = _Traits;
+ using value_type = _CharT;
+ using pointer = const _CharT*;
+ using const_pointer = const _CharT*;
+ using reference = const _CharT&;
+ using const_reference = const _CharT&;
+ using const_iterator = const _CharT*;
+ using iterator = const_iterator;
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
+ using reverse_iterator = const_reverse_iterator;
+ using size_type = size_t;
+ using difference_type = ptrdiff_t;
+ static constexpr size_type npos = size_type(-1);
+
+ // [string.view.cons], construct/copy
+
+ constexpr
+ basic_string_view() noexcept
+ : _M_len{0}, _M_str{nullptr}
+ { }
+
+ constexpr basic_string_view(const basic_string_view&) noexcept = default;
+
+ template<typename _Allocator>
+ basic_string_view(const basic_string<_CharT, _Traits,
+ _Allocator>& __str) noexcept
+ : _M_len{__str.length()}, _M_str{__str.data()}
+ { }
+
+ constexpr basic_string_view(const _CharT* __str)
+ : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
+ _M_str{__str}
+ { }
+
+ constexpr basic_string_view(const _CharT* __str, size_type __len)
+ : _M_len{__len},
+ _M_str{__str}
+ { }
+
+ basic_string_view&
+ operator=(const basic_string_view&) noexcept = default;
+
+ // [string.view.iterators], iterators
+
+ constexpr const_iterator
+ begin() const noexcept
+ { return this->_M_str; }
+
+ constexpr const_iterator
+ end() const noexcept
+ { return this->_M_str + this->_M_len; }
+
+ constexpr const_iterator
+ cbegin() const noexcept
+ { return this->_M_str; }
+
+ constexpr const_iterator
+ cend() const noexcept
+ { return this->_M_str + this->_M_len; }
+
+ const_reverse_iterator
+ rbegin() const noexcept
+ { return const_reverse_iterator(this->end()); }
+
+ const_reverse_iterator
+ rend() const noexcept
+ { return const_reverse_iterator(this->begin()); }
+
+ const_reverse_iterator
+ crbegin() const noexcept
+ { return const_reverse_iterator(this->end()); }
+
+ const_reverse_iterator
+ crend() const noexcept
+ { return const_reverse_iterator(this->begin()); }
+
+ // [string.view.capacity], capacity
+
+ constexpr size_type
+ size() const noexcept
+ { return this->_M_len; }
+
+ constexpr size_type
+ length() const noexcept
+ { return _M_len; }
+
+ constexpr size_type
+ max_size() const noexcept
+ {
+ return (npos - sizeof(size_type) - sizeof(void*))
+ / sizeof(value_type) / 4;
+ }
+
+ constexpr bool
+ empty() const noexcept
+ { return this->_M_len == 0; }
+
+ // [string.view.access], element access
+
+ constexpr const _CharT&
+ operator[](size_type __pos) const
+ {
+ // TODO: Assert to restore in a way compatible with the constexpr.
+ // __glibcxx_assert(__pos < this->_M_len);
+ return *(this->_M_str + __pos);
+ }
+
+ constexpr const _CharT&
+ at(size_type __pos) const
+ {
+ return __pos < this->_M_len
+ ? *(this->_M_str + __pos)
+ : (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
+ "(which is %zu) >= this->size() "
+ "(which is %zu)"),
+ __pos, this->size()),
+ *this->_M_str);
+ }
+
+ constexpr const _CharT&
+ front() const
+ {
+ // TODO: Assert to restore in a way compatible with the constexpr.
+ // __glibcxx_assert(this->_M_len > 0);
+ return *this->_M_str;
+ }
+
+ constexpr const _CharT&
+ back() const
+ {
+ // TODO: Assert to restore in a way compatible with the constexpr.
+ // __glibcxx_assert(this->_M_len > 0);
+ return *(this->_M_str + this->_M_len - 1);
+ }
+
+ constexpr const _CharT*
+ data() const noexcept
+ { return this->_M_str; }
+
+ // [string.view.modifiers], modifiers:
+
+ constexpr void
+ remove_prefix(size_type __n)
+ {
+ __glibcxx_assert(this->_M_len >= __n);
+ this->_M_str += __n;
+ this->_M_len -= __n;
+ }
+
+ constexpr void
+ remove_suffix(size_type __n)
+ { this->_M_len -= __n; }
+
+ constexpr void
+ swap(basic_string_view& __sv) noexcept
+ {
+ auto __tmp = *this;
+ *this = __sv;
+ __sv = __tmp;
+ }
+
+
+ // [string.view.ops], string operations:
+
+ template<typename _Allocator>
+ explicit operator basic_string<_CharT, _Traits, _Allocator>() const
+ {
+ return { this->_M_str, this->_M_len };
+ }
+
+ template<typename _Allocator = std::allocator<_CharT>>
+ basic_string<_CharT, _Traits, _Allocator>
+ to_string(const _Allocator& __alloc = _Allocator()) const
+ {
+ return { this->_M_str, this->_M_len, __alloc };
+ }
+
+ size_type
+ copy(_CharT* __str, size_type __n, size_type __pos = 0) const
+ {
+ __glibcxx_requires_string_len(__str, __n);
+ if (__pos > this->_M_len)
+ __throw_out_of_range_fmt(__N("basic_string_view::copy: __pos "
+ "(which is %zu) > this->size() "
+ "(which is %zu)"),
+ __pos, this->size());
+ size_type __rlen{std::min(__n, size_type{this->_M_len - __pos})};
+ for (auto __begin = this->_M_str + __pos,
+ __end = __begin + __rlen; __begin != __end;)
+ *__str++ = *__begin++;
+ return __rlen;
+ }
+
+
+ // [string.view.ops], string operations:
+
+ constexpr basic_string_view
+ substr(size_type __pos, size_type __n=npos) const
+ {
+ return __pos <= this->_M_len
+ ? basic_string_view{this->_M_str + __pos,
+ std::min(__n, size_type{this->_M_len - __pos})}
+ : (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos "
+ "(which is %zu) > this->size() "
+ "(which is %zu)"),
+ __pos, this->size()), basic_string_view{});
+ }
+
+ constexpr int
+ compare(basic_string_view __str) const noexcept
+ {
+ int __ret = traits_type::compare(this->_M_str, __str._M_str,
+ std::min(this->_M_len, __str._M_len));
+ if (__ret == 0)
+ __ret = _S_compare(this->_M_len, __str._M_len);
+ return __ret;
+ }
+
+ constexpr int
+ compare(size_type __pos1, size_type __n1, basic_string_view __str) const
+ { return this->substr(__pos1, __n1).compare(__str); }
+
+ constexpr int
+ compare(size_type __pos1, size_type __n1,
+ basic_string_view __str, size_type __pos2, size_type __n2) const
+ { return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }
+
+ constexpr int
+ compare(const _CharT* __str) const noexcept
+ { return this->compare(basic_string_view{__str}); }
+
+ constexpr int
+ compare(size_type __pos1, size_type __n1, const _CharT* __str) const
+ { return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }
+
+ constexpr int
+ compare(size_type __pos1, size_type __n1,
+ const _CharT* __str, size_type __n2) const
+ {
+ return this->substr(__pos1, __n1)
+ .compare(basic_string_view(__str, __n2));
+ }
+
+ constexpr size_type
+ find(basic_string_view __str, size_type __pos = 0) const noexcept
+ { return this->find(__str._M_str, __pos, __str._M_len); }
+
+ constexpr size_type
+ find(_CharT __c, size_type __pos=0) const noexcept;
+
+ constexpr size_type
+ find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
+
+ constexpr size_type
+ find(const _CharT* __str, size_type __pos=0) const noexcept
+ { return this->find(__str, __pos, traits_type::length(__str)); }
+
+ constexpr size_type
+ rfind(basic_string_view __str, size_type __pos = npos) const noexcept
+ { return this->rfind(__str._M_str, __pos, __str._M_len); }
+
+ constexpr size_type
+ rfind(_CharT __c, size_type __pos = npos) const noexcept;
+
+ constexpr size_type
+ rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
+
+ constexpr size_type
+ rfind(const _CharT* __str, size_type __pos = npos) const noexcept
+ { return this->rfind(__str, __pos, traits_type::length(__str)); }
+
+ constexpr size_type
+ find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept
+ { return this->find_first_of(__str._M_str, __pos, __str._M_len); }
+
+ constexpr size_type
+ find_first_of(_CharT __c, size_type __pos = 0) const noexcept
+ { return this->find(__c, __pos); }
+
+ constexpr size_type
+ find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;
+
+ constexpr size_type
+ find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept
+ { return this->find_first_of(__str, __pos, traits_type::length(__str)); }
+
+ constexpr size_type
+ find_last_of(basic_string_view __str,
+ size_type __pos = npos) const noexcept
+ { return this->find_last_of(__str._M_str, __pos, __str._M_len); }
+
+ constexpr size_type
+ find_last_of(_CharT __c, size_type __pos=npos) const noexcept
+ { return this->rfind(__c, __pos); }
+
+ constexpr size_type
+ find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;
+
+ constexpr size_type
+ find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept
+ { return this->find_last_of(__str, __pos, traits_type::length(__str)); }
+
+ constexpr size_type
+ find_first_not_of(basic_string_view __str,
+ size_type __pos = 0) const noexcept
+ { return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
+
+ constexpr size_type
+ find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;
+
+ constexpr size_type
+ find_first_not_of(const _CharT* __str,
+ size_type __pos, size_type __n) const;
+
+ constexpr size_type
+ find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept
+ {
+ return this->find_first_not_of(__str, __pos,
+ traits_type::length(__str));
+ }
+
+ constexpr size_type
+ find_last_not_of(basic_string_view __str,
+ size_type __pos = npos) const noexcept
+ { return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
+
+ constexpr size_type
+ find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;
+
+ constexpr size_type
+ find_last_not_of(const _CharT* __str,
+ size_type __pos, size_type __n) const;
+
+ constexpr size_type
+ find_last_not_of(const _CharT* __str,
+ size_type __pos = npos) const noexcept
+ {
+ return this->find_last_not_of(__str, __pos,
+ traits_type::length(__str));
+ }
+
+ private:
+
+ static constexpr int
+ _S_compare(size_type __n1, size_type __n2) noexcept
+ {
+ return difference_type(__n1 - __n2) > std::numeric_limits<int>::max()
+ ? std::numeric_limits<int>::max()
+ : difference_type(__n1 - __n2) < std::numeric_limits<int>::min()
+ ? std::numeric_limits<int>::min()
+ : static_cast<int>(difference_type(__n1 - __n2));
+ }
+
+ size_t _M_len;
+ const _CharT* _M_str;
+ };
+
+ // [string.view.comparison], non-member basic_string_view comparison functions
+
+ namespace __detail
+ {
+ // Identity transform to create a non-deduced context, so that only one
+ // argument participates in template argument deduction and the other
+ // argument gets implicitly converted to the deduced type. See n3766.html.
+ template<typename _Tp>
+ using __idt = common_type_t<_Tp>;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator==(basic_string_view<_CharT, _Traits> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.size() == __y.size() && __x.compare(__y) == 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator==(basic_string_view<_CharT, _Traits> __x,
+ __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
+ { return __x.size() == __y.size() && __x.compare(__y) == 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.size() == __y.size() && __x.compare(__y) == 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator!=(basic_string_view<_CharT, _Traits> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return !(__x == __y); }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator!=(basic_string_view<_CharT, _Traits> __x,
+ __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
+ { return !(__x == __y); }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return !(__x == __y); }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator< (basic_string_view<_CharT, _Traits> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.compare(__y) < 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator< (basic_string_view<_CharT, _Traits> __x,
+ __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
+ { return __x.compare(__y) < 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.compare(__y) < 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator> (basic_string_view<_CharT, _Traits> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.compare(__y) > 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator> (basic_string_view<_CharT, _Traits> __x,
+ __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
+ { return __x.compare(__y) > 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.compare(__y) > 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator<=(basic_string_view<_CharT, _Traits> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.compare(__y) <= 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator<=(basic_string_view<_CharT, _Traits> __x,
+ __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
+ { return __x.compare(__y) <= 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.compare(__y) <= 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator>=(basic_string_view<_CharT, _Traits> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.compare(__y) >= 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator>=(basic_string_view<_CharT, _Traits> __x,
+ __detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
+ { return __x.compare(__y) >= 0; }
+
+ template<typename _CharT, typename _Traits>
+ constexpr bool
+ operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
+ basic_string_view<_CharT, _Traits> __y) noexcept
+ { return __x.compare(__y) >= 0; }
+
+ // [string.view.io], Inserters and extractors
+ template<typename _CharT, typename _Traits>
+ inline basic_ostream<_CharT, _Traits>&
+ operator<<(basic_ostream<_CharT, _Traits>& __os,
+ basic_string_view<_CharT,_Traits> __str)
+ { return __ostream_insert(__os, __str.data(), __str.size()); }
+
+
+ // basic_string_view typedef names
+
+ using string_view = basic_string_view<char>;
+#ifdef _GLIBCXX_USE_WCHAR_T
+ using wstring_view = basic_string_view<wchar_t>;
+#endif
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ using u16string_view = basic_string_view<char16_t>;
+ using u32string_view = basic_string_view<char32_t>;
+#endif
+} // namespace fundamentals_v1
+} // namespace experimental
+
+
+ // [string.view.hash], hash support:
+ template<typename _Tp>
+ struct hash;
+
+ template<>
+ struct hash<experimental::string_view>
+ : public __hash_base<size_t, experimental::string_view>
+ {
+ size_t
+ operator()(const experimental::string_view& __str) const noexcept
+ { return std::_Hash_impl::hash(__str.data(), __str.length()); }
+ };
+
+ template<>
+ struct __is_fast_hash<hash<experimental::string_view>> : std::false_type
+ { };
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ template<>
+ struct hash<experimental::wstring_view>
+ : public __hash_base<size_t, wstring>
+ {
+ size_t
+ operator()(const experimental::wstring_view& __s) const noexcept
+ { return std::_Hash_impl::hash(__s.data(),
+ __s.length() * sizeof(wchar_t)); }
+ };
+
+ template<>
+ struct __is_fast_hash<hash<experimental::wstring_view>> : std::false_type
+ { };
+#endif
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ template<>
+ struct hash<experimental::u16string_view>
+ : public __hash_base<size_t, experimental::u16string_view>
+ {
+ size_t
+ operator()(const experimental::u16string_view& __s) const noexcept
+ { return std::_Hash_impl::hash(__s.data(),
+ __s.length() * sizeof(char16_t)); }
+ };
+
+ template<>
+ struct __is_fast_hash<hash<experimental::u16string_view>> : std::false_type
+ { };
+
+ template<>
+ struct hash<experimental::u32string_view>
+ : public __hash_base<size_t, experimental::u32string_view>
+ {
+ size_t
+ operator()(const experimental::u32string_view& __s) const noexcept
+ { return std::_Hash_impl::hash(__s.data(),
+ __s.length() * sizeof(char32_t)); }
+ };
+
+ template<>
+ struct __is_fast_hash<hash<experimental::u32string_view>> : std::false_type
+ { };
+#endif
+
+namespace experimental
+{
+ // I added these EMSR.
+ inline namespace literals
+ {
+ inline namespace string_view_literals
+ {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wliteral-suffix"
+ inline constexpr basic_string_view<char>
+ operator""sv(const char* __str, size_t __len) noexcept
+ { return basic_string_view<char>{__str, __len}; }
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ inline constexpr basic_string_view<wchar_t>
+ operator""sv(const wchar_t* __str, size_t __len) noexcept
+ { return basic_string_view<wchar_t>{__str, __len}; }
+#endif
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+ inline constexpr basic_string_view<char16_t>
+ operator""sv(const char16_t* __str, size_t __len) noexcept
+ { return basic_string_view<char16_t>{__str, __len}; }
+
+ inline constexpr basic_string_view<char32_t>
+ operator""sv(const char32_t* __str, size_t __len) noexcept
+ { return basic_string_view<char32_t>{__str, __len}; }
+#endif
+#pragma GCC diagnostic pop
+ } // namespace string_literals
+ } // namespace literals
+} // namespace experimental
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace std
+
+#include <experimental/bits/string_view.tcc>
+
+#endif // __cplusplus <= 201103L
+
+#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW
diff --git a/gdb/common/gdb_string_view.tcc b/gdb/common/gdb_string_view.tcc
new file mode 100644
index 000000000000..579ececd8d82
--- /dev/null
+++ b/gdb/common/gdb_string_view.tcc
@@ -0,0 +1,231 @@
+// Components for manipulating non-owning sequences of characters -*- C++ -*-
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file experimental/bits/string_view.tcc
+ * This is an internal header file, included by other library headers.
+ * Do not attempt to use it directly. @headername{experimental/string_view}
+ */
+
+//
+// N3762 basic_string_view library
+//
+
+#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC
+#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC 1
+
+#pragma GCC system_header
+
+#if __cplusplus >= 201402L
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+namespace experimental
+{
+inline namespace fundamentals_v1
+{
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
+ {
+ __glibcxx_requires_string_len(__str, __n);
+
+ if (__n == 0)
+ return __pos <= this->_M_len ? __pos : npos;
+
+ if (__n <= this->_M_len)
+ {
+ for (; __pos <= this->_M_len - __n; ++__pos)
+ if (traits_type::eq(this->_M_str[__pos], __str[0])
+ && traits_type::compare(this->_M_str + __pos + 1,
+ __str + 1, __n - 1) == 0)
+ return __pos;
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ find(_CharT __c, size_type __pos) const noexcept
+ {
+ size_type __ret = npos;
+ if (__pos < this->_M_len)
+ {
+ const size_type __n = this->_M_len - __pos;
+ const _CharT* __p = traits_type::find(this->_M_str + __pos, __n, __c);
+ if (__p)
+ __ret = __p - this->_M_str;
+ }
+ return __ret;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
+ {
+ __glibcxx_requires_string_len(__str, __n);
+
+ if (__n <= this->_M_len)
+ {
+ __pos = std::min(size_type(this->_M_len - __n), __pos);
+ do
+ {
+ if (traits_type::compare(this->_M_str + __pos, __str, __n) == 0)
+ return __pos;
+ }
+ while (__pos-- > 0);
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ rfind(_CharT __c, size_type __pos) const noexcept
+ {
+ size_type __size = this->_M_len;
+ if (__size > 0)
+ {
+ if (--__size > __pos)
+ __size = __pos;
+ for (++__size; __size-- > 0; )
+ if (traits_type::eq(this->_M_str[__size], __c))
+ return __size;
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
+ {
+ __glibcxx_requires_string_len(__str, __n);
+ for (; __n && __pos < this->_M_len; ++__pos)
+ {
+ const _CharT* __p = traits_type::find(__str, __n,
+ this->_M_str[__pos]);
+ if (__p)
+ return __pos;
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
+ {
+ __glibcxx_requires_string_len(__str, __n);
+ size_type __size = this->size();
+ if (__size && __n)
+ {
+ if (--__size > __pos)
+ __size = __pos;
+ do
+ {
+ if (traits_type::find(__str, __n, this->_M_str[__size]))
+ return __size;
+ }
+ while (__size-- != 0);
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
+ {
+ __glibcxx_requires_string_len(__str, __n);
+ for (; __pos < this->_M_len; ++__pos)
+ if (!traits_type::find(__str, __n, this->_M_str[__pos]))
+ return __pos;
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ find_first_not_of(_CharT __c, size_type __pos) const noexcept
+ {
+ for (; __pos < this->_M_len; ++__pos)
+ if (!traits_type::eq(this->_M_str[__pos], __c))
+ return __pos;
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
+ {
+ __glibcxx_requires_string_len(__str, __n);
+ size_type __size = this->_M_len;
+ if (__size)
+ {
+ if (--__size > __pos)
+ __size = __pos;
+ do
+ {
+ if (!traits_type::find(__str, __n, this->_M_str[__size]))
+ return __size;
+ }
+ while (__size--);
+ }
+ return npos;
+ }
+
+ template<typename _CharT, typename _Traits>
+ constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ basic_string_view<_CharT, _Traits>::
+ find_last_not_of(_CharT __c, size_type __pos) const noexcept
+ {
+ size_type __size = this->_M_len;
+ if (__size)
+ {
+ if (--__size > __pos)
+ __size = __pos;
+ do
+ {
+ if (!traits_type::eq(this->_M_str[__size], __c))
+ return __size;
+ }
+ while (__size--);
+ }
+ return npos;
+ }
+} // namespace fundamentals_v1
+} // namespace experimental
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace std
+
+#endif // __cplusplus <= 201103L
+
+#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC
--
2.16.3
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4
@ 2018-04-07 13:26 Simon Marchi
2018-04-07 13:26 ` [PATCH v3 3/5] Add gdb::string_view Simon Marchi
` (5 more replies)
0 siblings, 6 replies; 17+ messages in thread
From: Simon Marchi @ 2018-04-07 13:26 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
This file provides the AX_CXX_COMPILE_STDCXX macro. In the context of
the following patch, I wanted to build and test GDB in c++17 mode. The
version of the macro we have in the repo does not support detecting
c++17 compilers, but the upstream version has been updated to do so.
Since we have local modifications to the file, I had to reconcile our
modifications and the updated upstream version (which was relatively
straightforward).
gdb/ChangeLog:
* ax_cxx_compile_stdcxx.m4: Sync with upstream.
* configure: Re-generate.
---
gdb/ax_cxx_compile_stdcxx.m4 | 458 +++++++++++++++++++++++++++++++++++++++++--
gdb/configure | 28 +--
2 files changed, 455 insertions(+), 31 deletions(-)
diff --git a/gdb/ax_cxx_compile_stdcxx.m4 b/gdb/ax_cxx_compile_stdcxx.m4
index 444799a64678..9a9e9e713a53 100644
--- a/gdb/ax_cxx_compile_stdcxx.m4
+++ b/gdb/ax_cxx_compile_stdcxx.m4
@@ -8,7 +8,7 @@
# - AC_SUBST CXX_DIALECT instead of changing CXX/CXXCPP.
#
# ===========================================================================
-# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
+# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
# ===========================================================================
#
# SYNOPSIS
@@ -42,21 +42,22 @@
# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
# Copyright (c) 2015 Paul Norman <penorman@mac.com>
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
+# Copyright (c) 2016 Krzesimir Nowak <qdlacz@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
-#serial 4
+#serial 8
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
dnl (serial version number 13).
AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
- m4_if([$1], [11], [],
- [$1], [14], [],
- [$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])],
+ m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
+ [$1], [14], [ax_cxx_compile_alternatives="14 1y"],
+ [$1], [17], [ax_cxx_compile_alternatives="17 1z"],
[m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
m4_if([$2], [], [],
[$2], [ext], [],
@@ -80,7 +81,8 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
m4_if([$2], [noext], [], [dnl
if test x$ac_success = xno; then
- for switch in -std=gnu++$1 -std=gnu++0x; do
+ for alternative in ${ax_cxx_compile_alternatives}; do
+ switch="-std=gnu++${alternative}"
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
$cachevar,
@@ -103,19 +105,24 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
dnl HP's aCC needs +std=c++11 according to:
dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
dnl Cray's crayCC needs "-h std=c++11"
- for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do
- cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
- AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
- $cachevar,
- [ac_save_CXX="$CXX"
- CXX="$CXX $switch"
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
- [eval $cachevar=yes],
- [eval $cachevar=no])
- CXX="$ac_save_CXX"])
- if eval test x\$$cachevar = xyes; then
- CXX_DIALECT="$switch"
- ac_success=yes
+ for alternative in ${ax_cxx_compile_alternatives}; do
+ for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
+ $cachevar,
+ [ac_save_CXX="$CXX"
+ CXX="$CXX $switch"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [eval $cachevar=yes],
+ [eval $cachevar=no])
+ CXX="$ac_save_CXX"])
+ if eval test x\$$cachevar = xyes; then
+ CXX_DIALECT="$switch"
+ ac_success=yes
+ break
+ fi
+ done
+ if test x$ac_success = xyes; then
break
fi
done
@@ -153,6 +160,11 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
_AX_CXX_COMPILE_STDCXX_testbody_new_in_14
)
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
+)
dnl Tests for new features in C++11
@@ -523,7 +535,7 @@ namespace cxx14
}
- namespace test_digit_seperators
+ namespace test_digit_separators
{
constexpr auto ten_million = 100'000'000;
@@ -565,3 +577,409 @@ namespace cxx14
#endif // __cplusplus >= 201402L
]])
+
+
+dnl Tests for new features in C++17
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
+
+// If the compiler admits that it is not ready for C++17, why torture it?
+// Hopefully, this will speed up the test.
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus <= 201402L
+
+#error "This is not a C++17 compiler"
+
+#else
+
+#if defined(__clang__)
+ #define REALLY_CLANG
+#else
+ #if defined(__GNUC__)
+ #define REALLY_GCC
+ #endif
+#endif
+
+#include <initializer_list>
+#include <utility>
+#include <type_traits>
+
+namespace cxx17
+{
+
+#if !defined(REALLY_CLANG)
+ namespace test_constexpr_lambdas
+ {
+
+ // TODO: test it with clang++ from git
+
+ constexpr int foo = [](){return 42;}();
+
+ }
+#endif // !defined(REALLY_CLANG)
+
+ namespace test::nested_namespace::definitions
+ {
+
+ }
+
+ namespace test_fold_expression
+ {
+
+ template<typename... Args>
+ int multiply(Args... args)
+ {
+ return (args * ... * 1);
+ }
+
+ template<typename... Args>
+ bool all(Args... args)
+ {
+ return (args && ...);
+ }
+
+ }
+
+ namespace test_extended_static_assert
+ {
+
+ static_assert (true);
+
+ }
+
+ namespace test_auto_brace_init_list
+ {
+
+ auto foo = {5};
+ auto bar {5};
+
+ static_assert(std::is_same<std::initializer_list<int>, decltype(foo)>::value);
+ static_assert(std::is_same<int, decltype(bar)>::value);
+ }
+
+ namespace test_typename_in_template_template_parameter
+ {
+
+ template<template<typename> typename X> struct D;
+
+ }
+
+ namespace test_fallthrough_nodiscard_maybe_unused_attributes
+ {
+
+ int f1()
+ {
+ return 42;
+ }
+
+ [[nodiscard]] int f2()
+ {
+ [[maybe_unused]] auto unused = f1();
+
+ switch (f1())
+ {
+ case 17:
+ f1();
+ [[fallthrough]];
+ case 42:
+ f1();
+ }
+ return f1();
+ }
+
+ }
+
+ namespace test_extended_aggregate_initialization
+ {
+
+ struct base1
+ {
+ int b1, b2 = 42;
+ };
+
+ struct base2
+ {
+ base2() {
+ b3 = 42;
+ }
+ int b3;
+ };
+
+ struct derived : base1, base2
+ {
+ int d;
+ };
+
+ derived d1 {{1, 2}, {}, 4}; // full initialization
+ derived d2 {{}, {}, 4}; // value-initialized bases
+
+ }
+
+ namespace test_general_range_based_for_loop
+ {
+
+ struct iter
+ {
+ int i;
+
+ int& operator* ()
+ {
+ return i;
+ }
+
+ const int& operator* () const
+ {
+ return i;
+ }
+
+ iter& operator++()
+ {
+ ++i;
+ return *this;
+ }
+ };
+
+ struct sentinel
+ {
+ int i;
+ };
+
+ bool operator== (const iter& i, const sentinel& s)
+ {
+ return i.i == s.i;
+ }
+
+ bool operator!= (const iter& i, const sentinel& s)
+ {
+ return !(i == s);
+ }
+
+ struct range
+ {
+ iter begin() const
+ {
+ return {0};
+ }
+
+ sentinel end() const
+ {
+ return {5};
+ }
+ };
+
+ void f()
+ {
+ range r {};
+
+ for (auto i : r)
+ {
+ [[maybe_unused]] auto v = i;
+ }
+ }
+
+ }
+
+ namespace test_lambda_capture_asterisk_this_by_value
+ {
+
+ struct t
+ {
+ int i;
+ int foo()
+ {
+ return [*this]()
+ {
+ return i;
+ }();
+ }
+ };
+
+ }
+
+ namespace test_enum_class_construction
+ {
+
+ enum class byte : unsigned char
+ {};
+
+ byte foo {42};
+
+ }
+
+ namespace test_constexpr_if
+ {
+
+ template <bool cond>
+ int f ()
+ {
+ if constexpr(cond)
+ {
+ return 13;
+ }
+ else
+ {
+ return 42;
+ }
+ }
+
+ }
+
+ namespace test_selection_statement_with_initializer
+ {
+
+ int f()
+ {
+ return 13;
+ }
+
+ int f2()
+ {
+ if (auto i = f(); i > 0)
+ {
+ return 3;
+ }
+
+ switch (auto i = f(); i + 4)
+ {
+ case 17:
+ return 2;
+
+ default:
+ return 1;
+ }
+ }
+
+ }
+
+#if !defined(REALLY_CLANG)
+ namespace test_template_argument_deduction_for_class_templates
+ {
+
+ // TODO: test it with clang++ from git
+
+ template <typename T1, typename T2>
+ struct pair
+ {
+ pair (T1 p1, T2 p2)
+ : m1 {p1},
+ m2 {p2}
+ {}
+
+ T1 m1;
+ T2 m2;
+ };
+
+ void f()
+ {
+ [[maybe_unused]] auto p = pair{13, 42u};
+ }
+
+ }
+#endif // !defined(REALLY_CLANG)
+
+ namespace test_non_type_auto_template_parameters
+ {
+
+ template <auto n>
+ struct B
+ {};
+
+ B<5> b1;
+ B<'a'> b2;
+
+ }
+
+#if !defined(REALLY_CLANG)
+ namespace test_structured_bindings
+ {
+
+ // TODO: test it with clang++ from git
+
+ int arr[2] = { 1, 2 };
+ std::pair<int, int> pr = { 1, 2 };
+
+ auto f1() -> int(&)[2]
+ {
+ return arr;
+ }
+
+ auto f2() -> std::pair<int, int>&
+ {
+ return pr;
+ }
+
+ struct S
+ {
+ int x1 : 2;
+ volatile double y1;
+ };
+
+ S f3()
+ {
+ return {};
+ }
+
+ auto [ x1, y1 ] = f1();
+ auto& [ xr1, yr1 ] = f1();
+ auto [ x2, y2 ] = f2();
+ auto& [ xr2, yr2 ] = f2();
+ const auto [ x3, y3 ] = f3();
+
+ }
+#endif // !defined(REALLY_CLANG)
+
+#if !defined(REALLY_CLANG)
+ namespace test_exception_spec_type_system
+ {
+
+ // TODO: test it with clang++ from git
+
+ struct Good {};
+ struct Bad {};
+
+ void g1() noexcept;
+ void g2();
+
+ template<typename T>
+ Bad
+ f(T*, T*);
+
+ template<typename T1, typename T2>
+ Good
+ f(T1*, T2*);
+
+ static_assert (std::is_same_v<Good, decltype(f(g1, g2))>);
+
+ }
+#endif // !defined(REALLY_CLANG)
+
+ namespace test_inline_variables
+ {
+
+ template<class T> void f(T)
+ {}
+
+ template<class T> inline T g(T)
+ {
+ return T{};
+ }
+
+ template<> inline void f<>(int)
+ {}
+
+ template<> int g<>(int)
+ {
+ return 5;
+ }
+
+ }
+
+} // namespace cxx17
+
+#endif // __cplusplus <= 201402L
+
+]])
diff --git a/gdb/configure b/gdb/configure
index f2acc1bf9e2c..b31315201810 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -4967,7 +4967,7 @@ program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"`
# We require a C++11 compiler. Check if one is available, and if
# necessary, set CXX_DIALECT to some -std=xxx switch.
- ax_cxx_compile_cxx11_required=true
+ ax_cxx_compile_alternatives="11 0x" ax_cxx_compile_cxx11_required=true
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -5283,7 +5283,8 @@ $as_echo "$ax_cv_cxx_compile_cxx11" >&6; }
fi
if test x$ac_success = xno; then
- for switch in -std=gnu++11 -std=gnu++0x; do
+ for alternative in ${ax_cxx_compile_alternatives}; do
+ switch="-std=gnu++${alternative}"
cachevar=`$as_echo "ax_cv_cxx_compile_cxx11_$switch" | $as_tr_sh`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports C++11 features with $switch" >&5
$as_echo_n "checking whether $CXX supports C++11 features with $switch... " >&6; }
@@ -5601,16 +5602,17 @@ $as_echo "$ac_res" >&6; }
fi
if test x$ac_success = xno; then
- for switch in -std=c++11 -std=c++0x +std=c++11 "-h std=c++11"; do
- cachevar=`$as_echo "ax_cv_cxx_compile_cxx11_$switch" | $as_tr_sh`
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports C++11 features with $switch" >&5
+ for alternative in ${ax_cxx_compile_alternatives}; do
+ for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
+ cachevar=`$as_echo "ax_cv_cxx_compile_cxx11_$switch" | $as_tr_sh`
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports C++11 features with $switch" >&5
$as_echo_n "checking whether $CXX supports C++11 features with $switch... " >&6; }
if { as_var=$cachevar; eval "test \"\${$as_var+set}\" = set"; }; then :
$as_echo_n "(cached) " >&6
else
ac_save_CXX="$CXX"
- CXX="$CXX $switch"
- cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ CXX="$CXX $switch"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -5905,14 +5907,18 @@ else
eval $cachevar=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
- CXX="$ac_save_CXX"
+ CXX="$ac_save_CXX"
fi
eval ac_res=\$$cachevar
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
- if eval test x\$$cachevar = xyes; then
- CXX_DIALECT="$switch"
- ac_success=yes
+ if eval test x\$$cachevar = xyes; then
+ CXX_DIALECT="$switch"
+ ac_success=yes
+ break
+ fi
+ done
+ if test x$ac_success = xyes; then
break
fi
done
--
2.16.3
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v3 5/5] Adapt and integrate string_view tests
2018-04-07 13:26 [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Simon Marchi
2018-04-07 13:26 ` [PATCH v3 3/5] Add gdb::string_view Simon Marchi
@ 2018-04-07 13:26 ` Simon Marchi
2018-04-09 13:45 ` Pedro Alves
2018-04-07 13:26 ` [PATCH v3 2/5] Copy string_view files from libstdc++ Simon Marchi
` (3 subsequent siblings)
5 siblings, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2018-04-07 13:26 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
New in v3:
* Remove tests corresponding to features removed (e.g. operator ""sv,
operator<<).
* Use try/catch with gdb_exception instead of CATCH/END_CATCH.
* Fix copy-pasta.
* Add some constexpr tests, to validate that all the constexpr
methods left in gdb_string_view.h can actually be used as part of
constant expressions.
The previous patch copied the string_view tests from libstdc++. This
patch adjusts them in a similar way that the libstdc++ optional tests
are integrated in our unit test suite.
Not all tests are used, some of them require language features not
present in c++11. For example, we can't use a string_view constructor
where the length is not explicit in a constexpr, because
std::char_traits::length is not a constexpr itself (it is in c++17
though). Nevertheless, a good number of tests are integrated, which
covers pretty well the string_view features.
gdb/ChangeLog:
* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
string_view-selftests.c.
* unittests/basic_string_view/capacity/1.cc: Adapt to GDB
testsuite.
* unittests/basic_string_view/cons/char/1.cc: Likewise.
* unittests/basic_string_view/cons/char/2.cc: Likewise.
* unittests/basic_string_view/cons/char/3.cc: Likewise.
* unittests/basic_string_view/element_access/char/1.cc:
Likewise.
* unittests/basic_string_view/element_access/char/empty.cc:
Likewise.
* unittests/basic_string_view/element_access/char/front_back.cc:
Likewise.
* unittests/basic_string_view/inserters/char/2.cc: Likewise.
* unittests/basic_string_view/modifiers/remove_prefix/char/1.cc:
Likewise.
* unittests/basic_string_view/modifiers/remove_suffix/char/1.cc:
Likewise.
* unittests/basic_string_view/modifiers/swap/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/compare/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/compare/char/13650.cc:
Likewise.
* unittests/basic_string_view/operations/copy/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/data/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/find/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/find/char/2.cc:
Likewise.
* unittests/basic_string_view/operations/find/char/3.cc:
Likewise.
* unittests/basic_string_view/operations/find/char/4.cc:
Likewise.
* unittests/basic_string_view/operations/rfind/char/1.cc:
Likewise.
* unittests/basic_string_view/operations/rfind/char/2.cc:
Likewise.
* unittests/basic_string_view/operations/rfind/char/3.cc:
Likewise.
* unittests/basic_string_view/operations/substr/char/1.cc:
Likewise.
* unittests/basic_string_view/operators/char/2.cc: Likewise.
* unittests/string_view-selftests.c: New file.
---
gdb/Makefile.in | 1 +
gdb/unittests/basic_string_view/capacity/1.cc | 24 ++-
gdb/unittests/basic_string_view/cons/char/1.cc | 21 ++-
gdb/unittests/basic_string_view/cons/char/2.cc | 11 +-
gdb/unittests/basic_string_view/cons/char/3.cc | 8 +-
.../basic_string_view/element_access/char/1.cc | 20 +--
.../basic_string_view/element_access/char/empty.cc | 9 +-
.../element_access/char/front_back.cc | 9 +-
.../basic_string_view/inserters/char/2.cc | 12 +-
.../modifiers/remove_prefix/char/1.cc | 11 +-
.../modifiers/remove_suffix/char/1.cc | 11 +-
.../basic_string_view/modifiers/swap/char/1.cc | 11 +-
.../basic_string_view/operations/compare/char/1.cc | 8 +-
.../operations/compare/char/13650.cc | 7 +-
.../basic_string_view/operations/copy/char/1.cc | 9 +-
.../basic_string_view/operations/data/char/1.cc | 9 +-
.../basic_string_view/operations/find/char/1.cc | 26 +--
.../basic_string_view/operations/find/char/2.cc | 23 +--
.../basic_string_view/operations/find/char/3.cc | 21 ++-
.../basic_string_view/operations/find/char/4.cc | 11 +-
.../basic_string_view/operations/rfind/char/1.cc | 21 +--
.../basic_string_view/operations/rfind/char/2.cc | 13 +-
.../basic_string_view/operations/rfind/char/3.cc | 17 +-
.../basic_string_view/operations/substr/char/1.cc | 18 +--
.../basic_string_view/operators/char/2.cc | 20 ++-
gdb/unittests/string_view-selftests.c | 177 +++++++++++++++++++++
26 files changed, 376 insertions(+), 152 deletions(-)
create mode 100644 gdb/unittests/string_view-selftests.c
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 0a07cabb438d..e885dca7d2c7 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -430,6 +430,7 @@ SUBDIR_UNITTESTS_SRCS = \
unittests/scoped_fd-selftests.c \
unittests/scoped_mmap-selftests.c \
unittests/scoped_restore-selftests.c \
+ unittests/string_view-selftests.c \
unittests/tracepoint-selftests.c \
unittests/unpack-selftests.c \
unittests/utils-selftests.c \
diff --git a/gdb/unittests/basic_string_view/capacity/1.cc b/gdb/unittests/basic_string_view/capacity/1.cc
index d49ecbd9dd53..f297853f0b7a 100644
--- a/gdb/unittests/basic_string_view/capacity/1.cc
+++ b/gdb/unittests/basic_string_view/capacity/1.cc
@@ -19,9 +19,7 @@
// string_view size, length
-#include <string_view>
-#include <cstring>
-#include <testsuite_hooks.h>
+namespace capacity_1 {
template<typename T>
struct A { };
@@ -36,13 +34,19 @@ template<typename T>
struct B { };
+} // namespace capacity_1
+} // namespace string_view
+} // namespace selftests
+
// char_traits specialization
namespace std
{
template<>
- struct char_traits<A<B> >
+ struct char_traits<selftests::string_view::capacity_1::A<
+ selftests::string_view::capacity_1::B> >
{
- typedef A<B> char_type;
+ typedef selftests::string_view::capacity_1::A<
+ selftests::string_view::capacity_1::B> char_type;
// Unsigned as wint_t in unsigned.
typedef unsigned long int_type;
typedef streampos pos_type;
@@ -123,11 +127,15 @@ namespace std
};
} // namespace std
+namespace selftests {
+namespace string_view {
+namespace capacity_1 {
+
void
test01()
{
- std::basic_string_view<A<B>> str02;
- typedef std::basic_string_view< A<B> >::size_type size_type_o;
+ gdb::basic_string_view<A<B>> str02;
+ typedef gdb::basic_string_view< A<B> >::size_type size_type_o;
size_type_o sz03;
size_type_o sz04;
@@ -160,3 +168,5 @@ main()
return 0;
}
+
+} // namespace capacity_1
diff --git a/gdb/unittests/basic_string_view/cons/char/1.cc b/gdb/unittests/basic_string_view/cons/char/1.cc
index f80ae92f2f80..cfe9cce4b55a 100644
--- a/gdb/unittests/basic_string_view/cons/char/1.cc
+++ b/gdb/unittests/basic_string_view/cons/char/1.cc
@@ -19,43 +19,40 @@
// basic_string_view constructors.
-#include <string_view>
-#include <string>
-#include <cstring>
-#include <testsuite_hooks.h>
+namespace cons_1 {
void
test01()
{
- typedef std::string_view::size_type csize_type;
+ typedef gdb::string_view::size_type csize_type;
// basic_string_view()
- const std::string_view str00{};
+ const gdb::string_view str00{};
VERIFY( str00.length() == 0 );
VERIFY( str00.data() == nullptr );
// basic_string_view(const char*)
const char str_lit01[] = "rodeo beach, marin";
- const std::string_view str01{str_lit01};
+ const gdb::string_view str01{str_lit01};
VERIFY( str01.length() == 18 );
VERIFY( str01.data() == str_lit01 );
- const std::string_view str02{"baker beach, san francisco"};
+ const gdb::string_view str02{"baker beach, san francisco"};
VERIFY( str02.length() == 26 );
// basic_string_view(const string_view&)
- std::string_view str04{str01};
+ gdb::string_view str04{str01};
VERIFY( str04.length() == str01.length() );
VERIFY( str04.data() == str01.data() );
// basic_string_view(const char* s)
csize_type len_lit01 = strlen(str_lit01);
- std::string_view str05{str_lit01, len_lit01};
+ gdb::string_view str05{str_lit01, len_lit01};
VERIFY( str05.length() == len_lit01 );
VERIFY( str05.data() == str_lit01 );
// basic_string_view(basic_string& s)
std::string istr07(10, 'z');
- std::string_view str07{istr07};
+ gdb::string_view str07{istr07};
VERIFY( str07.length() == 10 );
}
@@ -66,3 +63,5 @@ main()
return 0;
}
+
+} // namespace cons_1
diff --git a/gdb/unittests/basic_string_view/cons/char/2.cc b/gdb/unittests/basic_string_view/cons/char/2.cc
index 8dbca7a621e7..a1b45367e009 100644
--- a/gdb/unittests/basic_string_view/cons/char/2.cc
+++ b/gdb/unittests/basic_string_view/cons/char/2.cc
@@ -19,10 +19,7 @@
// basic_string_view constructors.
-#include <new>
-#include <string_view>
-#include <stdexcept>
-#include <testsuite_hooks.h>
+namespace cons_2 {
void
test03()
@@ -32,9 +29,9 @@ test03()
// These are tests to see how basic_string_view handles data with NUL
// bytes. Obviously basic_string_view(char*) will halt at the first one, but
// nothing else should.
- std::string_view s1(with_nulls, 28);
+ gdb::string_view s1(with_nulls, 28);
VERIFY( s1.size() == 28 );
- std::string_view s2(s1);
+ gdb::string_view s2(s1);
VERIFY( s2.size() == 28 );
}
@@ -45,3 +42,5 @@ main()
return 0;
}
+
+} // namespace cons_2
diff --git a/gdb/unittests/basic_string_view/cons/char/3.cc b/gdb/unittests/basic_string_view/cons/char/3.cc
index c892cbc62720..358c118508e8 100644
--- a/gdb/unittests/basic_string_view/cons/char/3.cc
+++ b/gdb/unittests/basic_string_view/cons/char/3.cc
@@ -19,15 +19,13 @@
// basic_string_view constructors.
-#include <string_view>
-#include <vector>
-#include <testsuite_hooks.h>
+namespace cons_3 {
void
test05()
{
char const * s = 0;
- std::string_view zero_length_built_with_NULL(s, 0);
+ gdb::string_view zero_length_built_with_NULL(s, 0);
}
int
@@ -37,3 +35,5 @@ main()
return 0;
}
+
+} // namespace cons_3
diff --git a/gdb/unittests/basic_string_view/element_access/char/1.cc b/gdb/unittests/basic_string_view/element_access/char/1.cc
index 03c588efb0d7..7f8e79e6d008 100644
--- a/gdb/unittests/basic_string_view/element_access/char/1.cc
+++ b/gdb/unittests/basic_string_view/element_access/char/1.cc
@@ -19,21 +19,19 @@
// basic_string element access
-#include <string_view>
-#include <stdexcept>
-#include <testsuite_hooks.h>
+namespace element_access_1 {
void
test01()
{
- typedef std::string_view::size_type csize_type;
- typedef std::string_view::const_reference cref;
- typedef std::string_view::reference ref;
+ typedef gdb::string_view::size_type csize_type;
+ typedef gdb::string_view::const_reference cref;
+ typedef gdb::string_view::reference ref;
csize_type csz01, csz02;
- const std::string_view str01("tamarindo, costa rica");
- std::string_view str02("41st street beach, capitola, california");
- std::string_view str03;
+ const gdb::string_view str01("tamarindo, costa rica");
+ gdb::string_view str02("41st street beach, capitola, california");
+ gdb::string_view str03;
// const_reference operator[] (size_type pos) const;
csz01 = str01.size();
@@ -52,7 +50,7 @@ test01()
str01.at(csz01);
VERIFY( false ); // Should not get here, as exception thrown.
}
- catch (std::out_of_range& fail)
+ catch (gdb_exception& fail)
{
VERIFY( true );
}
@@ -68,3 +66,5 @@ main()
test01();
return 0;
}
+
+} // namespace element_access_1
diff --git a/gdb/unittests/basic_string_view/element_access/char/empty.cc b/gdb/unittests/basic_string_view/element_access/char/empty.cc
index fad5eb798ba6..97e85d675f26 100644
--- a/gdb/unittests/basic_string_view/element_access/char/empty.cc
+++ b/gdb/unittests/basic_string_view/element_access/char/empty.cc
@@ -18,21 +18,22 @@
// <http://www.gnu.org/licenses/>.
//
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace element_access_empty {
int
main()
{
{
- std::string_view empty;
+ gdb::string_view empty;
VERIFY( empty.empty() );
}
{
- const std::string_view empty;
+ const gdb::string_view empty;
VERIFY( empty.empty() );
}
return 0;
}
+
+} // namespace element_access_empty
diff --git a/gdb/unittests/basic_string_view/element_access/char/front_back.cc b/gdb/unittests/basic_string_view/element_access/char/front_back.cc
index efff787e365e..450364726cfa 100644
--- a/gdb/unittests/basic_string_view/element_access/char/front_back.cc
+++ b/gdb/unittests/basic_string_view/element_access/char/front_back.cc
@@ -18,14 +18,13 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace element_access_front_back {
void
test01()
{
- std::string_view str("ramifications");
- const std::string_view cstr("melodien");
+ gdb::string_view str("ramifications");
+ const gdb::string_view cstr("melodien");
VERIFY( str.front() == 'r' );
VERIFY( str.back() == 's' );
@@ -40,3 +39,5 @@ main()
return 0;
}
+
+} // namespace element_access_front_back
diff --git a/gdb/unittests/basic_string_view/inserters/char/2.cc b/gdb/unittests/basic_string_view/inserters/char/2.cc
index 6562d58615df..64b82de66a49 100644
--- a/gdb/unittests/basic_string_view/inserters/char/2.cc
+++ b/gdb/unittests/basic_string_view/inserters/char/2.cc
@@ -25,11 +25,7 @@
// { dg-options "-std=gnu++17" }
// { dg-require-fileio "" }
-#include <string_view>
-#include <string>
-#include <fstream>
-#include <iostream>
-#include <testsuite_hooks.h>
+namespace inserters_2 {
// testing basic_filebuf::xsputn via stress testing with large string_views
// based on a bug report libstdc++ 9
@@ -37,13 +33,13 @@
void
test05(std::size_t size)
{
- bool test = true;
+ bool test ATTRIBUTE_UNUSED = true;
const char filename[] = "inserters_extractors-2.txt";
const char fillc = 'f';
std::ofstream ofs(filename);
std::string str(size, fillc);
- std::string_view strv{str};
+ gdb::string_view strv{str};
// sanity checks
VERIFY( str.size() == size );
@@ -91,3 +87,5 @@ main()
return 0;
}
+
+} // namespace inserters_2
diff --git a/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc b/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc
index ba08a98eeaec..f73fdc72012b 100644
--- a/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc
+++ b/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc
@@ -17,13 +17,12 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace modifiers_remove_prefix {
void
test01()
{
- using std::string_view;
+ using gdb::string_view;
string_view str0{"olympus mons"};
string_view::pointer p = str0.data();
@@ -33,6 +32,7 @@ test01()
VERIFY( str0 == string_view{"pus mons"} );
}
+#ifndef GDB_STRING_VIEW
constexpr bool
test02()
{
@@ -50,12 +50,17 @@ test02()
return true;
}
+#endif
int
main()
{
test01();
+#ifndef GDB_STRING_VIEW
static_assert( test02() );
+#endif
return 0;
}
+
+} // namespace modifiers_remove_prefix
diff --git a/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc b/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc
index 1b71ee936e8c..0407f37d227b 100644
--- a/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc
+++ b/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc
@@ -17,13 +17,12 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace modifiers_remove_suffix {
void
test01()
{
- using std::string_view;
+ using gdb::string_view;
string_view str0{"olympus mons"};
string_view::pointer p = str0.data();
@@ -33,6 +32,7 @@ test01()
VERIFY( str0 == string_view{"olympus mo"} );
}
+#ifndef GDB_STRING_VIEW
constexpr bool
test02()
{
@@ -50,12 +50,17 @@ test02()
return true;
}
+#endif
int
main()
{
test01();
+#ifndef GDB_STRING_VIEW
static_assert( test02() );
+#endif
return 0;
}
+
+} // namespace modifiers_remove_suffix
diff --git a/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc b/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc
index 90d26692599c..3bc7f01fa7ab 100644
--- a/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc
+++ b/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc
@@ -18,18 +18,19 @@
// { dg-options "-std=gnu++17" }
// { dg-do compile { target c++17 } }
-#include <string_view>
+namespace modifiers_swap {
-constexpr bool
+void
test01()
{
- using std::string_view;
+ using gdb::string_view;
string_view s1{"last"};
string_view s2{"first"};
s1.swap(s2);
- return s1 == "first" && s2 == "last";
+ VERIFY( s1 == "first" );
+ VERIFY( s2 == "last" );
}
-static_assert( test01() );
+} // namespace modifiers_swap
diff --git a/gdb/unittests/basic_string_view/operations/compare/char/1.cc b/gdb/unittests/basic_string_view/operations/compare/char/1.cc
index 46691ebd52a1..66d2613a25b9 100644
--- a/gdb/unittests/basic_string_view/operations/compare/char/1.cc
+++ b/gdb/unittests/basic_string_view/operations/compare/char/1.cc
@@ -29,9 +29,7 @@
// NB compare should be thought of as a lexographical compare, ie how
// things would be sorted in a dictionary.
-#include <string_view>
-#include <cstring>
-#include <testsuite_hooks.h>
+namespace operations_compare_1 {
enum want_value {lt=0, z=1, gt=2};
@@ -66,7 +64,7 @@ test_value(int result, want_value expected)
int
test01()
{
- using std::string_view;
+ using gdb::string_view;
string_view str_0("costa rica");
string_view str_1("costa marbella");
@@ -130,3 +128,5 @@ main()
return 0;
}
+
+} // namespace operations_compare_1
diff --git a/gdb/unittests/basic_string_view/operations/compare/char/13650.cc b/gdb/unittests/basic_string_view/operations/compare/char/13650.cc
index ef9df20e6eec..0cc3ee824cbf 100644
--- a/gdb/unittests/basic_string_view/operations/compare/char/13650.cc
+++ b/gdb/unittests/basic_string_view/operations/compare/char/13650.cc
@@ -19,14 +19,13 @@
// basic_string_view::compare [lib.string_view::compare]
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_compare_13650 {
// libstdc++/13650
void
test01()
{
- using std::string_view;
+ using gdb::string_view;
const char lit_01[]{ 'w', 'e', '\0', 'r', 'd' };
const char lit_02[]{ 'w', 'e', 'i', '\0', 'd' };
@@ -47,3 +46,5 @@ main()
return 0;
}
+
+} // namespace operations_compare_13650
diff --git a/gdb/unittests/basic_string_view/operations/copy/char/1.cc b/gdb/unittests/basic_string_view/operations/copy/char/1.cc
index 6caf0e1507a6..5b6dd346583f 100644
--- a/gdb/unittests/basic_string_view/operations/copy/char/1.cc
+++ b/gdb/unittests/basic_string_view/operations/copy/char/1.cc
@@ -19,16 +19,15 @@
// basic_string_view::copy
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_copy_1 {
void
test01()
{
- typedef std::string_view::size_type csize_type;
+ typedef gdb::string_view::size_type csize_type;
const char str_lit01[] = "123456789A";
- const std::string_view str01(str_lit01);
+ const gdb::string_view str01(str_lit01);
char buffer[4] = { 0 };
csize_type len = str01.copy(buffer, sizeof(buffer), 8);
@@ -43,3 +42,5 @@ main()
return 0;
}
+
+} // namespace operations_copy_1
diff --git a/gdb/unittests/basic_string_view/operations/data/char/1.cc b/gdb/unittests/basic_string_view/operations/data/char/1.cc
index 18fc9f5fe888..4149e16b22dd 100644
--- a/gdb/unittests/basic_string_view/operations/data/char/1.cc
+++ b/gdb/unittests/basic_string_view/operations/data/char/1.cc
@@ -19,16 +19,15 @@
// string_view operations
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_data_1 {
int
test01()
{
- std::string_view empty;
+ gdb::string_view empty;
VERIFY( empty.size() == 0 );
- const std::string_view::value_type* p = empty.data();
+ const gdb::string_view::value_type* p = empty.data();
VERIFY( p == nullptr );
return 0;
@@ -41,3 +40,5 @@ main()
return 0;
}
+
+} // namespace operations_data_1
diff --git a/gdb/unittests/basic_string_view/operations/find/char/1.cc b/gdb/unittests/basic_string_view/operations/find/char/1.cc
index d7d2f37706eb..a68434a22a9d 100644
--- a/gdb/unittests/basic_string_view/operations/find/char/1.cc
+++ b/gdb/unittests/basic_string_view/operations/find/char/1.cc
@@ -19,23 +19,22 @@
// basic_string_view find
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_find_1 {
void
test01()
{
- typedef std::string_view::size_type csize_type;
- typedef std::string_view::const_reference cref;
- typedef std::string_view::reference ref;
- csize_type npos = std::string_view::npos;
+ typedef gdb::string_view::size_type csize_type;
+ typedef gdb::string_view::const_reference cref;
+ typedef gdb::string_view::reference ref;
+ csize_type npos = gdb::string_view::npos;
csize_type csz01, csz02;
const char str_lit01[] = "mave";
- const std::string_view str01("mavericks, santa cruz");
- std::string_view str02(str_lit01);
- std::string_view str03("s, s");
- std::string_view str04;
+ const gdb::string_view str01("mavericks, santa cruz");
+ gdb::string_view str02(str_lit01);
+ gdb::string_view str03("s, s");
+ gdb::string_view str04;
// size_type find(const string_view&, size_type pos = 0) const;
csz01 = str01.find(str01);
@@ -85,6 +84,7 @@ test01()
VERIFY( csz01 == npos );
}
+#ifndef GDB_STRING_VIEW
constexpr bool
test02()
{
@@ -152,13 +152,17 @@ test02()
return true;
}
-
+#endif
int
main()
{
test01();
+#ifndef GDB_STRING_VIEW
static_assert( test02() );
+#endif
return 0;
}
+
+} // namespace operations_find_1
diff --git a/gdb/unittests/basic_string_view/operations/find/char/2.cc b/gdb/unittests/basic_string_view/operations/find/char/2.cc
index af8a526d12c7..ce4579eaf952 100644
--- a/gdb/unittests/basic_string_view/operations/find/char/2.cc
+++ b/gdb/unittests/basic_string_view/operations/find/char/2.cc
@@ -19,24 +19,23 @@
// basic_string_view find_first_of
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_find_2 {
void
test02()
{
- typedef std::string_view::size_type csize_type;
- csize_type npos = std::string_view::npos;
+ typedef gdb::string_view::size_type csize_type;
+ csize_type npos = gdb::string_view::npos;
csize_type csz01, csz02;
const char str_lit01[] = "mave";
- const std::string_view str01("mavericks, santa cruz");
- std::string_view str02(str_lit01);
- std::string_view str03("s, s");
- std::string_view str04;
+ const gdb::string_view str01("mavericks, santa cruz");
+ gdb::string_view str02(str_lit01);
+ gdb::string_view str03("s, s");
+ gdb::string_view str04;
// size_type find_first_of(const string_view&, size_type pos = 0) const;
- std::string_view str05("xena rulez");
+ gdb::string_view str05("xena rulez");
csz01 = str01.find_first_of(str01);
VERIFY( csz01 == 0 );
csz01 = str01.find_first_of(str01, 4);
@@ -84,6 +83,7 @@ test02()
VERIFY( csz01 == csz02 );
}
+#ifndef GDB_STRING_VIEW
constexpr bool
test03()
{
@@ -150,12 +150,17 @@ test03()
return true;
}
+#endif
int
main()
{
test02();
+#ifndef GDB_STRING_VIEW
static_assert( test03() );
+#endif
return 0;
}
+
+} // namespace operations_find_2 {
diff --git a/gdb/unittests/basic_string_view/operations/find/char/3.cc b/gdb/unittests/basic_string_view/operations/find/char/3.cc
index 5ec651ef3f93..71fd83b727c6 100644
--- a/gdb/unittests/basic_string_view/operations/find/char/3.cc
+++ b/gdb/unittests/basic_string_view/operations/find/char/3.cc
@@ -19,21 +19,20 @@
// basic_string_view find_first_not_of
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_find_3 {
void
test03()
{
- typedef std::string_view::size_type csize_type;
- csize_type npos = std::string_view::npos;
+ typedef gdb::string_view::size_type csize_type;
+ csize_type npos = gdb::string_view::npos;
csize_type csz01;
- const std::string_view str01("Bob Rock, per me");
+ const gdb::string_view str01("Bob Rock, per me");
const char str_lit01[] = "Bob Rock";
- std::string_view str02("ovvero Trivi");
- std::string_view str03(str_lit01);
- std::string_view str04;
+ gdb::string_view str02("ovvero Trivi");
+ gdb::string_view str03(str_lit01);
+ gdb::string_view str04;
// size_type find_first_not_of(const string_view&, size_type pos = 0) const;
csz01 = str01.find_first_not_of(str01);
@@ -84,6 +83,7 @@ test03()
VERIFY( csz01 == npos );
}
+#ifndef GDB_STRING_VIEW
constexpr bool
test04()
{
@@ -150,12 +150,17 @@ test04()
return true;
}
+#endif
int
main()
{
test03();
+#ifndef GDB_STRING_VIEW
static_assert( test04() );
+#endif
return 0;
}
+
+} // namespace operations_find_3
diff --git a/gdb/unittests/basic_string_view/operations/find/char/4.cc b/gdb/unittests/basic_string_view/operations/find/char/4.cc
index ca4b1f17db42..23d15b291347 100644
--- a/gdb/unittests/basic_string_view/operations/find/char/4.cc
+++ b/gdb/unittests/basic_string_view/operations/find/char/4.cc
@@ -19,17 +19,16 @@
// basic_string_view find
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_find_4 {
// libstdc++/31401
void
test01()
{
- typedef std::string_view::size_type csize_type;
- csize_type npos = std::string_view::npos;
+ typedef gdb::string_view::size_type csize_type;
+ csize_type npos = gdb::string_view::npos;
- std::string_view use = "anu";
+ gdb::string_view use = "anu";
csize_type pos1 = use.find("a", npos);
VERIFY( pos1 == npos );
@@ -42,3 +41,5 @@ main()
return 0;
}
+
+} // namespace operations_find_4
diff --git a/gdb/unittests/basic_string_view/operations/rfind/char/1.cc b/gdb/unittests/basic_string_view/operations/rfind/char/1.cc
index ef26688fd761..8b0c49800d75 100644
--- a/gdb/unittests/basic_string_view/operations/rfind/char/1.cc
+++ b/gdb/unittests/basic_string_view/operations/rfind/char/1.cc
@@ -17,25 +17,24 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_rfind_1 {
// basic_string_view rfind
void
test01()
{
- typedef std::string_view::size_type csize_type;
- typedef std::string_view::const_reference cref;
- typedef std::string_view::reference ref;
- csize_type npos = std::string_view::npos;
+ typedef gdb::string_view::size_type csize_type;
+ typedef gdb::string_view::const_reference cref;
+ typedef gdb::string_view::reference ref;
+ csize_type npos = gdb::string_view::npos;
csize_type csz01, csz02;
const char str_lit01[] = "mave";
- const std::string_view str01("mavericks, santa cruz");
- std::string_view str02(str_lit01);
- std::string_view str03("s, s");
- std::string_view str04;
+ const gdb::string_view str01("mavericks, santa cruz");
+ gdb::string_view str02(str_lit01);
+ gdb::string_view str03("s, s");
+ gdb::string_view str04;
// size_type rfind(const string_view&, size_type pos = 0) const;
csz01 = str01.rfind(str01);
@@ -92,3 +91,5 @@ main()
return 0;
}
+
+} // namespace operations_rfind_1
diff --git a/gdb/unittests/basic_string_view/operations/rfind/char/2.cc b/gdb/unittests/basic_string_view/operations/rfind/char/2.cc
index df37f8c7745b..e51022da3faf 100644
--- a/gdb/unittests/basic_string_view/operations/rfind/char/2.cc
+++ b/gdb/unittests/basic_string_view/operations/rfind/char/2.cc
@@ -17,16 +17,15 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_rfind_2 {
// basic_string_view::find_last_of
void
test02()
{
- std::string_view z("ab");
- std::string_view::size_type pos;
+ gdb::string_view z("ab");
+ gdb::string_view::size_type pos;
pos = z.find_last_of("ab");
VERIFY( pos == 1 );
pos = z.find_last_of("Xa");
@@ -34,13 +33,13 @@ test02()
pos = z.find_last_of("Xb");
VERIFY( pos == 1 );
pos = z.find_last_of("XYZ");
- VERIFY( pos == std::string_view::npos );
+ VERIFY( pos == gdb::string_view::npos );
pos = z.find_last_of('a');
VERIFY( pos == 0 );
pos = z.find_last_of('b');
VERIFY( pos == 1 );
pos = z.find_last_of('X');
- VERIFY( pos == std::string_view::npos );
+ VERIFY( pos == gdb::string_view::npos );
}
int
@@ -50,3 +49,5 @@ main()
return 0;
}
+
+} // namespace operations_rfind_2
diff --git a/gdb/unittests/basic_string_view/operations/rfind/char/3.cc b/gdb/unittests/basic_string_view/operations/rfind/char/3.cc
index 37f01a28af7f..02d6a7325315 100644
--- a/gdb/unittests/basic_string_view/operations/rfind/char/3.cc
+++ b/gdb/unittests/basic_string_view/operations/rfind/char/3.cc
@@ -17,25 +17,24 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operations_rfind_3 {
// basic_string_view::find_last_not_of
void
test03()
{
- typedef std::string_view::size_type csize_type;
- std::string_view::size_type pos;
- csize_type npos = std::string_view::npos;
+ typedef gdb::string_view::size_type csize_type;
+ gdb::string_view::size_type pos;
+ csize_type npos = gdb::string_view::npos;
- std::string_view x;
+ gdb::string_view x;
pos = x.find_last_not_of('X');
VERIFY( pos == npos );
pos = x.find_last_not_of("XYZ");
VERIFY( pos == npos );
- std::string_view y("a");
+ gdb::string_view y("a");
pos = y.find_last_not_of('X');
VERIFY( pos == 0 );
pos = y.find_last_not_of('a');
@@ -45,7 +44,7 @@ test03()
pos = y.find_last_not_of("a");
VERIFY( pos == npos );
- std::string_view z("ab");
+ gdb::string_view z("ab");
pos = z.find_last_not_of('X');
VERIFY( pos == 1 );
pos = z.find_last_not_of("XYZ");
@@ -64,3 +63,5 @@ main()
return 0;
}
+
+} // namespace operations_rfind_3
diff --git a/gdb/unittests/basic_string_view/operations/substr/char/1.cc b/gdb/unittests/basic_string_view/operations/substr/char/1.cc
index ac65c23c54be..cbc916b33de2 100644
--- a/gdb/unittests/basic_string_view/operations/substr/char/1.cc
+++ b/gdb/unittests/basic_string_view/operations/substr/char/1.cc
@@ -19,21 +19,19 @@
// basic_string_view::substr
-#include <string_view>
-#include <stdexcept>
-#include <testsuite_hooks.h>
+namespace operations_substr_1 {
void
test01()
{
- typedef std::string_view::size_type csize_type;
- typedef std::string_view::const_reference cref;
- typedef std::string_view::reference ref;
+ typedef gdb::string_view::size_type csize_type;
+ typedef gdb::string_view::const_reference cref;
+ typedef gdb::string_view::reference ref;
csize_type csz01;
const char str_lit01[] = "rockaway, pacifica";
- const std::string_view str01(str_lit01);
- std::string_view str02;
+ const gdb::string_view str01(str_lit01);
+ gdb::string_view str02;
// basic_string_view<charT, _Traits, _Alloc>
// substr(size_type pos = 0, size_type n = npos) const;
@@ -48,7 +46,7 @@ test01()
str02 = str01.substr(csz01 + 1);
VERIFY( false );
}
- catch(std::out_of_range& fail)
+ catch(gdb_exception& fail)
{
VERIFY( true );
}
@@ -77,3 +75,5 @@ main()
return 0;
}
+
+} // namespace operations_substr_1
diff --git a/gdb/unittests/basic_string_view/operators/char/2.cc b/gdb/unittests/basic_string_view/operators/char/2.cc
index 4be652daafb2..963bc4cec865 100644
--- a/gdb/unittests/basic_string_view/operators/char/2.cc
+++ b/gdb/unittests/basic_string_view/operators/char/2.cc
@@ -109,17 +109,16 @@ template<class charT, class traits, class Allocator>
const basic_string<charT,traits,Allocator>& rhs);
*/
-#include <string_view>
-#include <testsuite_hooks.h>
+namespace operators_2 {
void
test01()
{
- std::string_view str_0("costa rica");
- std::string_view str_1("costa marbella");
- std::string_view str_2("cost");
- std::string_view str_3("costa ricans");
- std::string_view str_4;
+ gdb::string_view str_0("costa rica");
+ gdb::string_view str_1("costa marbella");
+ gdb::string_view str_2("cost");
+ gdb::string_view str_3("costa ricans");
+ gdb::string_view str_4;
str_4 = str_0;
//comparisons between string objects
@@ -233,6 +232,7 @@ test01()
VERIFY( str_0 <= "costa rica" );
}
+#ifndef GDB_STRING_VIEW
constexpr bool
test02()
{
@@ -358,10 +358,16 @@ test02()
return true;
}
+#endif
int
main()
{
test01();
+#ifndef GDB_STRING_VIEW
static_assert( test02() );
+#endif
+ return 0;
}
+
+} // namespace operators_2
diff --git a/gdb/unittests/string_view-selftests.c b/gdb/unittests/string_view-selftests.c
new file mode 100644
index 000000000000..182a5df9e4d3
--- /dev/null
+++ b/gdb/unittests/string_view-selftests.c
@@ -0,0 +1,177 @@
+/* Self tests for string_view for GDB, the GNU debugger.
+
+ Copyright (C) 2018 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* No need to test string_view if we're using C++17, since we're going to use
+ the "real" version. */
+#if __cplusplus < 201703L
+
+#include "defs.h"
+#include "selftest.h"
+#include "common/gdb_string_view.h"
+
+/* Used by the included .cc files below. Included here because the
+ included test files are wrapped in a namespace. */
+#include <string>
+#include <sstream>
+#include <fstream>
+#include <iostream>
+
+/* libstdc++'s testsuite uses VERIFY. */
+#define VERIFY SELF_CHECK
+
+/* Used to disable testing features not supported by
+ gdb::string_view. */
+#define GDB_STRING_VIEW
+
+namespace selftests {
+namespace string_view {
+
+/* The actual tests live in separate files, which were originally
+ copied over from libstdc++'s testsuite. To preserve the structure
+ and help with comparison with the original tests, the file names
+ have been preserved, and only minimal modification was done to have
+ them compile against gdb::string_view instead of std::string_view:
+
+ - std::string_view->gdb::string_view, etc.
+ - ATTRIBUTE_UNUSED in a few places
+ - wrap each file in a namespace so they can all be compiled as a
+ single unit.
+ - libstdc++'s license and formatting style was preserved.
+*/
+
+#include "basic_string_view/capacity/1.cc"
+#include "basic_string_view/cons/char/1.cc"
+#include "basic_string_view/cons/char/2.cc"
+#include "basic_string_view/cons/char/3.cc"
+#include "basic_string_view/element_access/char/1.cc"
+#include "basic_string_view/element_access/char/empty.cc"
+#include "basic_string_view/element_access/char/front_back.cc"
+#include "basic_string_view/inserters/char/2.cc"
+#include "basic_string_view/modifiers/remove_prefix/char/1.cc"
+#include "basic_string_view/modifiers/remove_suffix/char/1.cc"
+#include "basic_string_view/modifiers/swap/char/1.cc"
+#include "basic_string_view/operations/compare/char/1.cc"
+#include "basic_string_view/operations/compare/char/13650.cc"
+#include "basic_string_view/operations/copy/char/1.cc"
+#include "basic_string_view/operations/data/char/1.cc"
+#include "basic_string_view/operations/find/char/1.cc"
+#include "basic_string_view/operations/find/char/2.cc"
+#include "basic_string_view/operations/find/char/3.cc"
+#include "basic_string_view/operations/find/char/4.cc"
+#include "basic_string_view/operations/rfind/char/1.cc"
+#include "basic_string_view/operations/rfind/char/2.cc"
+#include "basic_string_view/operations/rfind/char/3.cc"
+#include "basic_string_view/operations/substr/char/1.cc"
+#include "basic_string_view/operators/char/2.cc"
+
+static void
+run_tests ()
+{
+ capacity_1::main ();
+ cons_1::main ();
+ cons_2::main ();
+ cons_3::main ();
+ element_access_1::main ();
+ element_access_empty::main ();
+ element_access_front_back::main ();
+ inserters_2::main ();
+ modifiers_remove_prefix::main ();
+ modifiers_remove_suffix::main ();
+ modifiers_swap::test01 ();
+ operations_compare_1::main ();
+ operations_compare_13650::main ();
+ operations_copy_1::main ();
+ operations_data_1::main ();
+ operations_find_1::main ();
+ operations_find_2::main ();
+ operations_find_3::main ();
+ operations_find_4::main ();
+ operations_rfind_1::main ();
+ operations_rfind_2::main ();
+ operations_rfind_3::main ();
+ operations_substr_1::main ();
+ operators_2::main ();
+
+ constexpr gdb::string_view sv_empty;
+ SELF_CHECK (sv_empty.empty ());
+
+ std::string std_string = "fika";
+ gdb::string_view sv1 (std_string);
+ SELF_CHECK (sv1 == "fika");
+
+ constexpr const char *fika = "fika";
+ gdb::string_view sv2 (fika);
+ SELF_CHECK (sv2 == "fika");
+
+ constexpr gdb::string_view sv3 (fika, 3);
+ SELF_CHECK (sv3 == "fik");
+
+ constexpr gdb::string_view sv4 (sv3);
+ SELF_CHECK (sv4 == "fik");
+
+ constexpr gdb::string_view::iterator it_begin = sv4.begin ();
+ static_assert (*it_begin == 'f', "");
+
+ constexpr gdb::string_view::iterator it_end = sv4.end ();
+ static_assert (*it_end == 'a', "");
+
+ const gdb::string_view::reverse_iterator it_rbegin = sv4.rbegin ();
+ SELF_CHECK (*it_rbegin == 'k');
+
+ const gdb::string_view::reverse_iterator it_rend = sv4.rend ();
+ SELF_CHECK (*(it_rend - 1) == 'f');
+
+ constexpr gdb::string_view::size_type size = sv4.size ();
+ static_assert (size == 3, "");
+
+ constexpr gdb::string_view::size_type length = sv4.length ();
+ static_assert (length == 3, "");
+
+ constexpr gdb::string_view::size_type max_size = sv4.max_size ();
+ static_assert (max_size > 0, "");
+
+ constexpr bool empty = sv4.empty ();
+ static_assert (!empty, "");
+
+ constexpr char c1 = sv4[1];
+ static_assert (c1 == 'i', "");
+
+ constexpr char c2 = sv4.at (2);
+ static_assert (c2 == 'k', "");
+
+ constexpr char front = sv4.front ();
+ static_assert (front == 'f', "");
+
+ constexpr char back = sv4.back ();
+ static_assert (back == 'k', "");
+
+ constexpr const char *data = sv4.data ();
+ static_assert (data == fika, "");
+}
+
+} /* namespace string_view */
+} /* namespace selftests */
+
+void
+_initialize_string_view_selftests ()
+{
+ selftests::register_test ("string_view", selftests::string_view::run_tests);
+}
+
+#endif /* __cplusplus < 201703L */
--
2.16.3
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v3 4/5] Copy string_view tests from libstdc++
2018-04-07 13:26 [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Simon Marchi
` (2 preceding siblings ...)
2018-04-07 13:26 ` [PATCH v3 2/5] Copy string_view files from libstdc++ Simon Marchi
@ 2018-04-07 13:37 ` Simon Marchi
2018-04-09 13:47 ` Pedro Alves
2018-04-09 13:46 ` [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Pedro Alves
2018-04-09 18:27 ` Simon Marchi
5 siblings, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2018-04-07 13:37 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
This patch copies the string_view tests from the gcc repository (commit
02a4441f002c).
${gcc}/libstdc++-v3/testsuite/21_strings/basic_string_view ->
${binutils-gdb}/gdb/unittests/basic_string_view
The local modifications are done in the following patch, so that it's
easier to review them.
gdb/ChangeLog:
* unittests/basic_string_view/capacity/1.cc: New file.
* unittests/basic_string_view/capacity/empty_neg.cc: New file.
* unittests/basic_string_view/cons/char/1.cc: New file.
* unittests/basic_string_view/cons/char/2.cc: New file.
* unittests/basic_string_view/cons/char/3.cc: New file.
* unittests/basic_string_view/cons/wchar_t/1.cc: New file.
* unittests/basic_string_view/cons/wchar_t/2.cc: New file.
* unittests/basic_string_view/cons/wchar_t/3.cc: New file.
* unittests/basic_string_view/element_access/char/1.cc: New file.
* unittests/basic_string_view/element_access/char/2.cc: New file.
* unittests/basic_string_view/element_access/char/empty.cc: New file.
* unittests/basic_string_view/element_access/char/front_back.cc: New file.
* unittests/basic_string_view/element_access/wchar_t/1.cc: New file.
* unittests/basic_string_view/element_access/wchar_t/2.cc: New file.
* unittests/basic_string_view/element_access/wchar_t/empty.cc: New file.
* unittests/basic_string_view/element_access/wchar_t/front_back.cc: New file.
* unittests/basic_string_view/include.cc: New file.
* unittests/basic_string_view/inserters/char/1.cc: New file.
* unittests/basic_string_view/inserters/char/2.cc: New file.
* unittests/basic_string_view/inserters/char/3.cc: New file.
* unittests/basic_string_view/inserters/pod/10081-out.cc: New file.
* unittests/basic_string_view/inserters/wchar_t/1.cc: New file.
* unittests/basic_string_view/inserters/wchar_t/2.cc: New file.
* unittests/basic_string_view/inserters/wchar_t/3.cc: New file.
* unittests/basic_string_view/literals/types.cc: New file.
* unittests/basic_string_view/literals/values.cc: New file.
* unittests/basic_string_view/modifiers/remove_prefix/char/1.cc: New file.
* unittests/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc: New file.
* unittests/basic_string_view/modifiers/remove_suffix/char/1.cc: New file.
* unittests/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc: New file.
* unittests/basic_string_view/modifiers/swap/char/1.cc: New file.
* unittests/basic_string_view/modifiers/swap/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/compare/char/1.cc: New file.
* unittests/basic_string_view/operations/compare/char/13650.cc: New file.
* unittests/basic_string_view/operations/compare/char/2.cc: New file.
* unittests/basic_string_view/operations/compare/char/70483.cc: New file.
* unittests/basic_string_view/operations/compare/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/compare/wchar_t/13650.cc: New file.
* unittests/basic_string_view/operations/compare/wchar_t/2.cc: New file.
* unittests/basic_string_view/operations/copy/char/1.cc: New file.
* unittests/basic_string_view/operations/copy/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/data/char/1.cc: New file.
* unittests/basic_string_view/operations/data/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/find/char/1.cc: New file.
* unittests/basic_string_view/operations/find/char/2.cc: New file.
* unittests/basic_string_view/operations/find/char/3.cc: New file.
* unittests/basic_string_view/operations/find/char/4.cc: New file.
* unittests/basic_string_view/operations/find/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/find/wchar_t/2.cc: New file.
* unittests/basic_string_view/operations/find/wchar_t/3.cc: New file.
* unittests/basic_string_view/operations/find/wchar_t/4.cc: New file.
* unittests/basic_string_view/operations/rfind/char/1.cc: New file.
* unittests/basic_string_view/operations/rfind/char/2.cc: New file.
* unittests/basic_string_view/operations/rfind/char/3.cc: New file.
* unittests/basic_string_view/operations/rfind/wchar_t/1.cc: New file.
* unittests/basic_string_view/operations/rfind/wchar_t/2.cc: New file.
* unittests/basic_string_view/operations/rfind/wchar_t/3.cc: New file.
* unittests/basic_string_view/operations/string_conversion/1.cc: New file.
* unittests/basic_string_view/operations/substr/char/1.cc: New file.
* unittests/basic_string_view/operations/substr/wchar_t/1.cc: New file.
* unittests/basic_string_view/operators/char/2.cc: New file.
* unittests/basic_string_view/operators/wchar_t/2.cc: New file.
* unittests/basic_string_view/range_access/char/1.cc: New file.
* unittests/basic_string_view/range_access/wchar_t/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/char/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc: New file.
* unittests/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc: New file.
* unittests/basic_string_view/requirements/typedefs.cc: New file.
* unittests/basic_string_view/typedefs.cc: New file.
* unittests/basic_string_view/types/1.cc: New file.
---
gdb/unittests/basic_string_view/capacity/1.cc | 162 +++++++++
.../basic_string_view/capacity/empty_neg.cc | 28 ++
gdb/unittests/basic_string_view/cons/char/1.cc | 68 ++++
gdb/unittests/basic_string_view/cons/char/2.cc | 47 +++
gdb/unittests/basic_string_view/cons/char/3.cc | 39 +++
gdb/unittests/basic_string_view/cons/wchar_t/1.cc | 68 ++++
gdb/unittests/basic_string_view/cons/wchar_t/2.cc | 45 +++
gdb/unittests/basic_string_view/cons/wchar_t/3.cc | 38 +++
.../basic_string_view/element_access/char/1.cc | 70 ++++
.../basic_string_view/element_access/char/2.cc | 30 ++
.../basic_string_view/element_access/char/empty.cc | 38 +++
.../element_access/char/front_back.cc | 42 +++
.../basic_string_view/element_access/wchar_t/1.cc | 71 ++++
.../basic_string_view/element_access/wchar_t/2.cc | 32 ++
.../element_access/wchar_t/empty.cc | 38 +++
.../element_access/wchar_t/front_back.cc | 42 +++
gdb/unittests/basic_string_view/include.cc | 25 ++
.../basic_string_view/inserters/char/1.cc | 65 ++++
.../basic_string_view/inserters/char/2.cc | 93 ++++++
.../basic_string_view/inserters/char/3.cc | 54 +++
.../basic_string_view/inserters/pod/10081-out.cc | 75 +++++
.../basic_string_view/inserters/wchar_t/1.cc | 70 ++++
.../basic_string_view/inserters/wchar_t/2.cc | 91 +++++
.../basic_string_view/inserters/wchar_t/3.cc | 53 +++
gdb/unittests/basic_string_view/literals/types.cc | 45 +++
gdb/unittests/basic_string_view/literals/values.cc | 72 ++++
.../modifiers/remove_prefix/char/1.cc | 61 ++++
.../modifiers/remove_prefix/wchar_t/1.cc | 61 ++++
.../modifiers/remove_suffix/char/1.cc | 61 ++++
.../modifiers/remove_suffix/wchar_t/1.cc | 61 ++++
.../basic_string_view/modifiers/swap/char/1.cc | 35 ++
.../basic_string_view/modifiers/swap/wchar_t/1.cc | 35 ++
.../basic_string_view/operations/compare/char/1.cc | 132 ++++++++
.../operations/compare/char/13650.cc | 49 +++
.../basic_string_view/operations/compare/char/2.cc | 30 ++
.../operations/compare/char/70483.cc | 89 +++++
.../operations/compare/wchar_t/1.cc | 133 ++++++++
.../operations/compare/wchar_t/13650.cc | 49 +++
.../operations/compare/wchar_t/2.cc | 30 ++
.../basic_string_view/operations/copy/char/1.cc | 45 +++
.../basic_string_view/operations/copy/wchar_t/1.cc | 46 +++
.../basic_string_view/operations/data/char/1.cc | 43 +++
.../basic_string_view/operations/data/wchar_t/1.cc | 43 +++
.../basic_string_view/operations/find/char/1.cc | 164 +++++++++
.../basic_string_view/operations/find/char/2.cc | 161 +++++++++
.../basic_string_view/operations/find/char/3.cc | 161 +++++++++
.../basic_string_view/operations/find/char/4.cc | 44 +++
.../basic_string_view/operations/find/wchar_t/1.cc | 163 +++++++++
.../basic_string_view/operations/find/wchar_t/2.cc | 161 +++++++++
.../basic_string_view/operations/find/wchar_t/3.cc | 161 +++++++++
.../basic_string_view/operations/find/wchar_t/4.cc | 44 +++
.../basic_string_view/operations/rfind/char/1.cc | 94 ++++++
.../basic_string_view/operations/rfind/char/2.cc | 52 +++
.../basic_string_view/operations/rfind/char/3.cc | 66 ++++
.../operations/rfind/wchar_t/1.cc | 94 ++++++
.../operations/rfind/wchar_t/2.cc | 52 +++
.../operations/rfind/wchar_t/3.cc | 66 ++++
.../operations/string_conversion/1.cc | 51 +++
.../basic_string_view/operations/substr/char/1.cc | 79 +++++
.../operations/substr/wchar_t/1.cc | 79 +++++
.../basic_string_view/operators/char/2.cc | 367 +++++++++++++++++++++
.../basic_string_view/operators/wchar_t/2.cc | 367 +++++++++++++++++++++
.../basic_string_view/range_access/char/1.cc | 47 +++
.../basic_string_view/range_access/wchar_t/1.cc | 47 +++
.../requirements/explicit_instantiation/1.cc | 26 ++
.../requirements/explicit_instantiation/char/1.cc | 23 ++
.../explicit_instantiation/char16_t/1.cc | 24 ++
.../explicit_instantiation/char32_t/1.cc | 24 ++
.../explicit_instantiation/wchar_t/1.cc | 23 ++
.../basic_string_view/requirements/typedefs.cc | 47 +++
gdb/unittests/basic_string_view/typedefs.cc | 36 ++
gdb/unittests/basic_string_view/types/1.cc | 43 +++
72 files changed, 5270 insertions(+)
create mode 100644 gdb/unittests/basic_string_view/capacity/1.cc
create mode 100644 gdb/unittests/basic_string_view/capacity/empty_neg.cc
create mode 100644 gdb/unittests/basic_string_view/cons/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/cons/char/2.cc
create mode 100644 gdb/unittests/basic_string_view/cons/char/3.cc
create mode 100644 gdb/unittests/basic_string_view/cons/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/cons/wchar_t/2.cc
create mode 100644 gdb/unittests/basic_string_view/cons/wchar_t/3.cc
create mode 100644 gdb/unittests/basic_string_view/element_access/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/element_access/char/2.cc
create mode 100644 gdb/unittests/basic_string_view/element_access/char/empty.cc
create mode 100644 gdb/unittests/basic_string_view/element_access/char/front_back.cc
create mode 100644 gdb/unittests/basic_string_view/element_access/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/element_access/wchar_t/2.cc
create mode 100644 gdb/unittests/basic_string_view/element_access/wchar_t/empty.cc
create mode 100644 gdb/unittests/basic_string_view/element_access/wchar_t/front_back.cc
create mode 100644 gdb/unittests/basic_string_view/include.cc
create mode 100644 gdb/unittests/basic_string_view/inserters/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/inserters/char/2.cc
create mode 100644 gdb/unittests/basic_string_view/inserters/char/3.cc
create mode 100644 gdb/unittests/basic_string_view/inserters/pod/10081-out.cc
create mode 100644 gdb/unittests/basic_string_view/inserters/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/inserters/wchar_t/2.cc
create mode 100644 gdb/unittests/basic_string_view/inserters/wchar_t/3.cc
create mode 100644 gdb/unittests/basic_string_view/literals/types.cc
create mode 100644 gdb/unittests/basic_string_view/literals/values.cc
create mode 100644 gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/modifiers/swap/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/modifiers/swap/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/compare/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/compare/char/13650.cc
create mode 100644 gdb/unittests/basic_string_view/operations/compare/char/2.cc
create mode 100644 gdb/unittests/basic_string_view/operations/compare/char/70483.cc
create mode 100644 gdb/unittests/basic_string_view/operations/compare/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/compare/wchar_t/13650.cc
create mode 100644 gdb/unittests/basic_string_view/operations/compare/wchar_t/2.cc
create mode 100644 gdb/unittests/basic_string_view/operations/copy/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/copy/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/data/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/data/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/find/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/find/char/2.cc
create mode 100644 gdb/unittests/basic_string_view/operations/find/char/3.cc
create mode 100644 gdb/unittests/basic_string_view/operations/find/char/4.cc
create mode 100644 gdb/unittests/basic_string_view/operations/find/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/find/wchar_t/2.cc
create mode 100644 gdb/unittests/basic_string_view/operations/find/wchar_t/3.cc
create mode 100644 gdb/unittests/basic_string_view/operations/find/wchar_t/4.cc
create mode 100644 gdb/unittests/basic_string_view/operations/rfind/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/rfind/char/2.cc
create mode 100644 gdb/unittests/basic_string_view/operations/rfind/char/3.cc
create mode 100644 gdb/unittests/basic_string_view/operations/rfind/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/rfind/wchar_t/2.cc
create mode 100644 gdb/unittests/basic_string_view/operations/rfind/wchar_t/3.cc
create mode 100644 gdb/unittests/basic_string_view/operations/string_conversion/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/substr/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/operations/substr/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/operators/char/2.cc
create mode 100644 gdb/unittests/basic_string_view/operators/wchar_t/2.cc
create mode 100644 gdb/unittests/basic_string_view/range_access/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/range_access/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/requirements/explicit_instantiation/1.cc
create mode 100644 gdb/unittests/basic_string_view/requirements/explicit_instantiation/char/1.cc
create mode 100644 gdb/unittests/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc
create mode 100644 gdb/unittests/basic_string_view/requirements/typedefs.cc
create mode 100644 gdb/unittests/basic_string_view/typedefs.cc
create mode 100644 gdb/unittests/basic_string_view/types/1.cc
diff --git a/gdb/unittests/basic_string_view/capacity/1.cc b/gdb/unittests/basic_string_view/capacity/1.cc
new file mode 100644
index 000000000000..d49ecbd9dd53
--- /dev/null
+++ b/gdb/unittests/basic_string_view/capacity/1.cc
@@ -0,0 +1,162 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// string_view size, length
+
+#include <string_view>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+template<typename T>
+ struct A { };
+
+template<typename T>
+ bool
+ operator==(const A<T>&, const A<T>&) { return true; }
+
+template<typename T>
+ bool
+ operator<(const A<T>&, const A<T>&) { return true; }
+
+struct B { };
+
+// char_traits specialization
+namespace std
+{
+ template<>
+ struct char_traits<A<B> >
+ {
+ typedef A<B> char_type;
+ // Unsigned as wint_t in unsigned.
+ typedef unsigned long int_type;
+ typedef streampos pos_type;
+ typedef streamoff off_type;
+ typedef mbstate_t state_type;
+
+ static void
+ assign(char_type& __c1, const char_type& __c2)
+ { __c1 = __c2; }
+
+ static bool
+ eq(const char_type& __c1, const char_type& __c2)
+ { return __c1 == __c2; }
+
+ static bool
+ lt(const char_type& __c1, const char_type& __c2)
+ { return __c1 < __c2; }
+
+ static int
+ compare(const char_type* __s1, const char_type* __s2, size_t __n)
+ {
+ for (size_t __i = 0; __i < __n; ++__i)
+ if (!eq(__s1[__i], __s2[__i]))
+ return lt(__s1[__i], __s2[__i]) ? -1 : 1;
+ return 0;
+ }
+
+ static size_t
+ length(const char_type* __s)
+ {
+ const char_type* __p = __s;
+ while (__p)
+ ++__p;
+ return (__p - __s);
+ }
+
+ static const char_type*
+ find(const char_type* __s, size_t __n, const char_type& __a)
+ {
+ for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
+ if (*__p == __a) return __p;
+ return 0;
+ }
+
+ static char_type*
+ move(char_type* __s1, const char_type* __s2, size_t __n)
+ { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
+
+ static char_type*
+ copy(char_type* __s1, const char_type* __s2, size_t __n)
+ { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
+
+ static char_type*
+ assign(char_type* __s, size_t __n, char_type __a)
+ {
+ for (char_type* __p = __s; __p < __s + __n; ++__p)
+ assign(*__p, __a);
+ return __s;
+ }
+
+ static char_type
+ to_char_type(const int_type&)
+ { return char_type(); }
+
+ static int_type
+ to_int_type(const char_type&) { return int_type(); }
+
+ static bool
+ eq_int_type(const int_type& __c1, const int_type& __c2)
+ { return __c1 == __c2; }
+
+ static int_type
+ eof() { return static_cast<int_type>(-1); }
+
+ static int_type
+ not_eof(const int_type& __c)
+ { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
+ };
+} // namespace std
+
+void
+test01()
+{
+ std::basic_string_view<A<B>> str02;
+ typedef std::basic_string_view< A<B> >::size_type size_type_o;
+ size_type_o sz03;
+ size_type_o sz04;
+
+ // non-POD types: size, length, max_size, empty()
+ bool b01 = str02.empty();
+ VERIFY( b01 == true );
+ sz03 = str02.size();
+ sz04 = str02.length();
+ VERIFY( sz03 == sz04 );
+ str02.data();
+ sz03 = str02.size();
+ sz04 = str02.length();
+ VERIFY( sz03 == sz04 );
+
+ sz03 = str02.max_size();
+ VERIFY( sz03 >= sz04 );
+
+ sz03 = str02.size();
+ str02 = {};
+ b01 = str02.empty();
+ VERIFY( b01 == true );
+ sz04 = str02.size();
+ VERIFY( sz03 >= sz04 );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/capacity/empty_neg.cc b/gdb/unittests/basic_string_view/capacity/empty_neg.cc
new file mode 100644
index 000000000000..4ea506365c03
--- /dev/null
+++ b/gdb/unittests/basic_string_view/capacity/empty_neg.cc
@@ -0,0 +1,28 @@
+// Copyright (C) 2017-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <string_view>
+
+void
+test01()
+{
+ std::string_view s;
+ s.empty(); // { dg-warning "ignoring return value" }
+}
diff --git a/gdb/unittests/basic_string_view/cons/char/1.cc b/gdb/unittests/basic_string_view/cons/char/1.cc
new file mode 100644
index 000000000000..f80ae92f2f80
--- /dev/null
+++ b/gdb/unittests/basic_string_view/cons/char/1.cc
@@ -0,0 +1,68 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view constructors.
+
+#include <string_view>
+#include <string>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::string_view::size_type csize_type;
+
+ // basic_string_view()
+ const std::string_view str00{};
+ VERIFY( str00.length() == 0 );
+ VERIFY( str00.data() == nullptr );
+
+ // basic_string_view(const char*)
+ const char str_lit01[] = "rodeo beach, marin";
+ const std::string_view str01{str_lit01};
+ VERIFY( str01.length() == 18 );
+ VERIFY( str01.data() == str_lit01 );
+ const std::string_view str02{"baker beach, san francisco"};
+ VERIFY( str02.length() == 26 );
+
+ // basic_string_view(const string_view&)
+ std::string_view str04{str01};
+ VERIFY( str04.length() == str01.length() );
+ VERIFY( str04.data() == str01.data() );
+
+ // basic_string_view(const char* s)
+ csize_type len_lit01 = strlen(str_lit01);
+ std::string_view str05{str_lit01, len_lit01};
+ VERIFY( str05.length() == len_lit01 );
+ VERIFY( str05.data() == str_lit01 );
+
+ // basic_string_view(basic_string& s)
+ std::string istr07(10, 'z');
+ std::string_view str07{istr07};
+ VERIFY( str07.length() == 10 );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/cons/char/2.cc b/gdb/unittests/basic_string_view/cons/char/2.cc
new file mode 100644
index 000000000000..8dbca7a621e7
--- /dev/null
+++ b/gdb/unittests/basic_string_view/cons/char/2.cc
@@ -0,0 +1,47 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view constructors.
+
+#include <new>
+#include <string_view>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+void
+test03()
+{
+ const char* with_nulls = "This contains \0 a zero byte.";
+
+ // These are tests to see how basic_string_view handles data with NUL
+ // bytes. Obviously basic_string_view(char*) will halt at the first one, but
+ // nothing else should.
+ std::string_view s1(with_nulls, 28);
+ VERIFY( s1.size() == 28 );
+ std::string_view s2(s1);
+ VERIFY( s2.size() == 28 );
+}
+
+int
+main()
+{
+ test03();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/cons/char/3.cc b/gdb/unittests/basic_string_view/cons/char/3.cc
new file mode 100644
index 000000000000..c892cbc62720
--- /dev/null
+++ b/gdb/unittests/basic_string_view/cons/char/3.cc
@@ -0,0 +1,39 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view constructors.
+
+#include <string_view>
+#include <vector>
+#include <testsuite_hooks.h>
+
+void
+test05()
+{
+ char const * s = 0;
+ std::string_view zero_length_built_with_NULL(s, 0);
+}
+
+int
+main()
+{
+ test05();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/cons/wchar_t/1.cc b/gdb/unittests/basic_string_view/cons/wchar_t/1.cc
new file mode 100644
index 000000000000..4f935d57e469
--- /dev/null
+++ b/gdb/unittests/basic_string_view/cons/wchar_t/1.cc
@@ -0,0 +1,68 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view constructors.
+
+#include <string_view>
+#include <string>
+#include <cwchar>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::wstring_view::size_type csize_type;
+
+ // basic_string_view()
+ const std::wstring_view str00{};
+ VERIFY( str00.length() == 0 );
+ VERIFY( str00.data() == nullptr );
+
+ // basic_string_view(const char*)
+ const wchar_t str_lit01[] = L"rodeo beach, marin";
+ const std::wstring_view str01{str_lit01};
+ VERIFY( str01.length() == 18 );
+ VERIFY( str01.data() == str_lit01 );
+ const std::wstring_view str02{L"baker beach, san francisco"};
+ VERIFY( str02.length() == 26 );
+
+ // basic_string_view(const string_view&)
+ std::wstring_view str04{str01};
+ VERIFY( str04.length() == str01.length() );
+ VERIFY( str04.data() == str01.data() );
+
+ // basic_string_view(const char* s)
+ csize_type len_lit01 = wcslen(str_lit01);
+ std::wstring_view str05{str_lit01, len_lit01};
+ VERIFY( str05.length() == len_lit01 );
+ VERIFY( str05.data() == str_lit01 );
+
+ // basic_string_view(basic_string& s)
+ std::wstring istr07(10, L'z');
+ std::wstring_view str07{istr07};
+ VERIFY( str07.length() == 10 );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/cons/wchar_t/2.cc b/gdb/unittests/basic_string_view/cons/wchar_t/2.cc
new file mode 100644
index 000000000000..3134ec0781e9
--- /dev/null
+++ b/gdb/unittests/basic_string_view/cons/wchar_t/2.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view constructors.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test03()
+{
+ const wchar_t* with_nulls = L"This contains \0 a zero byte.";
+
+ // These are tests to see how basic_string_view handles data with NUL
+ // bytes. Obviously basic_string_view(char*) will halt at the first one, but
+ // nothing else should.
+ std::wstring_view s1 (with_nulls, 28);
+ VERIFY( s1.size() == 28 );
+ std::wstring_view s2 (s1);
+ VERIFY( s2.size() == 28 );
+}
+
+int
+main()
+{
+ test03();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/cons/wchar_t/3.cc b/gdb/unittests/basic_string_view/cons/wchar_t/3.cc
new file mode 100644
index 000000000000..c49dc2579868
--- /dev/null
+++ b/gdb/unittests/basic_string_view/cons/wchar_t/3.cc
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view constructors.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test05()
+{
+ wchar_t const * s = 0;
+ std::wstring_view zero_length_built_with_NULL(s, 0);
+}
+
+int
+main()
+{
+ test05();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/element_access/char/1.cc b/gdb/unittests/basic_string_view/element_access/char/1.cc
new file mode 100644
index 000000000000..03c588efb0d7
--- /dev/null
+++ b/gdb/unittests/basic_string_view/element_access/char/1.cc
@@ -0,0 +1,70 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string element access
+
+#include <string_view>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::string_view::size_type csize_type;
+ typedef std::string_view::const_reference cref;
+ typedef std::string_view::reference ref;
+ csize_type csz01, csz02;
+
+ const std::string_view str01("tamarindo, costa rica");
+ std::string_view str02("41st street beach, capitola, california");
+ std::string_view str03;
+
+ // const_reference operator[] (size_type pos) const;
+ csz01 = str01.size();
+ cref cref1 = str01[csz01 - 1];
+ VERIFY( cref1 == 'a' );
+ // Undefined behavior at size().
+ //cref cref2 = str01[csz01];
+ //VERIFY( cref2 == char() );
+
+ // const_reference at(size_type pos) const;
+ csz01 = str01.size();
+ cref cref3 = str01.at(csz01 - 1);
+ VERIFY( cref3 == 'a' );
+ try
+ {
+ str01.at(csz01);
+ VERIFY( false ); // Should not get here, as exception thrown.
+ }
+ catch (std::out_of_range& fail)
+ {
+ VERIFY( true );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/element_access/char/2.cc b/gdb/unittests/basic_string_view/element_access/char/2.cc
new file mode 100644
index 000000000000..4ee2b64a0bba
--- /dev/null
+++ b/gdb/unittests/basic_string_view/element_access/char/2.cc
@@ -0,0 +1,30 @@
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++17 -O0" }
+// { dg-require-debug-mode "" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+
+int
+main()
+{
+ typedef std::string_view string_view_type;
+ string_view_type s;
+ s[0]; // abort
+}
diff --git a/gdb/unittests/basic_string_view/element_access/char/empty.cc b/gdb/unittests/basic_string_view/element_access/char/empty.cc
new file mode 100644
index 000000000000..fad5eb798ba6
--- /dev/null
+++ b/gdb/unittests/basic_string_view/element_access/char/empty.cc
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 3 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+//
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+ {
+ std::string_view empty;
+ VERIFY( empty.empty() );
+ }
+
+ {
+ const std::string_view empty;
+ VERIFY( empty.empty() );
+ }
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/element_access/char/front_back.cc b/gdb/unittests/basic_string_view/element_access/char/front_back.cc
new file mode 100644
index 000000000000..efff787e365e
--- /dev/null
+++ b/gdb/unittests/basic_string_view/element_access/char/front_back.cc
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++17" }
+// { dg-require-string-conversions "" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::string_view str("ramifications");
+ const std::string_view cstr("melodien");
+
+ VERIFY( str.front() == 'r' );
+ VERIFY( str.back() == 's' );
+ VERIFY( cstr.front() == 'm' );
+ VERIFY( cstr.back() == 'n' );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/element_access/wchar_t/1.cc b/gdb/unittests/basic_string_view/element_access/wchar_t/1.cc
new file mode 100644
index 000000000000..b74ee29f316d
--- /dev/null
+++ b/gdb/unittests/basic_string_view/element_access/wchar_t/1.cc
@@ -0,0 +1,71 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view element access
+
+#include <string_view>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::wstring_view::size_type csize_type;
+ typedef std::wstring_view::const_reference cref;
+ typedef std::wstring_view::reference ref;
+ csize_type csz01, csz02;
+
+ const std::wstring_view str01(L"tamarindo, costa rica");
+ std::wstring_view str02(L"41st street beach, capitola, california");
+ std::wstring_view str03;
+
+ // const_reference operator[] (size_type pos) const;
+ csz01 = str01.size();
+ cref cref1 = str01[csz01 - 1];
+ VERIFY( cref1 == L'a' );
+ // Undefined behavior at size().
+ //cref cref2 = str01[csz01];
+ //VERIFY( cref2 == wchar_t() );
+
+ // const_reference at(size_type pos) const;
+ csz01 = str01.size();
+ cref cref3 = str01.at(csz01 - 1);
+ VERIFY( cref3 == L'a' );
+ try
+ {
+ str01.at(csz01);
+ VERIFY( false ); // Should not get here, as exception thrown.
+ }
+ catch (std::out_of_range& fail)
+ {
+ VERIFY( true );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/element_access/wchar_t/2.cc b/gdb/unittests/basic_string_view/element_access/wchar_t/2.cc
new file mode 100644
index 000000000000..5b7421f2f304
--- /dev/null
+++ b/gdb/unittests/basic_string_view/element_access/wchar_t/2.cc
@@ -0,0 +1,32 @@
+// { dg-do run { xfail *-*-* } }
+// { dg-options "-std=gnu++17 -O0" }
+// { dg-require-debug-mode "" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+
+// libstdc++/21674
+// NB: Should work without any inlining or optimizations (ie. -O0).
+int
+main()
+{
+ typedef std::wstring_view string_view_type;
+ string_view_type s;
+ s[0]; // abort
+}
diff --git a/gdb/unittests/basic_string_view/element_access/wchar_t/empty.cc b/gdb/unittests/basic_string_view/element_access/wchar_t/empty.cc
new file mode 100644
index 000000000000..b1ac051b91dd
--- /dev/null
+++ b/gdb/unittests/basic_string_view/element_access/wchar_t/empty.cc
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+//
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+main()
+{
+ {
+ std::wstring_view empty;
+ VERIFY( empty.empty() );
+ }
+
+ {
+ const std::wstring_view empty;
+ VERIFY( empty.empty() );
+ }
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/element_access/wchar_t/front_back.cc b/gdb/unittests/basic_string_view/element_access/wchar_t/front_back.cc
new file mode 100644
index 000000000000..a7c8483f6fc7
--- /dev/null
+++ b/gdb/unittests/basic_string_view/element_access/wchar_t/front_back.cc
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++17" }
+// { dg-require-string-conversions "" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::wstring_view str(L"ramifications");
+ const std::wstring_view cstr(L"melodien");
+
+ VERIFY( str.front() == L'r' );
+ VERIFY( str.back() == L's' );
+ VERIFY( cstr.front() == L'm' );
+ VERIFY( cstr.back() == L'n' );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/include.cc b/gdb/unittests/basic_string_view/include.cc
new file mode 100644
index 000000000000..59dc47dc3226
--- /dev/null
+++ b/gdb/unittests/basic_string_view/include.cc
@@ -0,0 +1,25 @@
+// -*- C++ -*-
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This issue affected only debug-mode.
+
+// { dg-options "-std=gnu++17 -fno-rtti" }
+// { dg-do compile }
+
+#include <string_view>
diff --git a/gdb/unittests/basic_string_view/inserters/char/1.cc b/gdb/unittests/basic_string_view/inserters/char/1.cc
new file mode 100644
index 000000000000..26bd0fdc918d
--- /dev/null
+++ b/gdb/unittests/basic_string_view/inserters/char/1.cc
@@ -0,0 +1,65 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// inserters
+
+// NB: This file is predicated on sstreams, istreams, and ostreams
+// working, not to mention other major details like char_traits, and
+// all of the string_view class.
+
+#include <string_view>
+#include <stdexcept>
+#include <sstream>
+#include <fstream>
+#include <iostream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::string_view::size_type csize_type;
+ typedef std::string_view::const_reference cref;
+ typedef std::string_view::reference ref;
+
+ const std::string_view str01("sailing grand traverse bay\n"
+ "\t\t\t from Elk Rapids to the point reminds me of miles");
+
+ // ostream& operator<<(ostream&, const basic_string_view&)
+ std::ostringstream ostrs01;
+ try
+ {
+ ostrs01 << str01;
+ VERIFY( ostrs01.str() == str01 );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false );
+ }
+
+ std::string_view hello_world;
+ std::cout << hello_world;
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/inserters/char/2.cc b/gdb/unittests/basic_string_view/inserters/char/2.cc
new file mode 100644
index 000000000000..6562d58615df
--- /dev/null
+++ b/gdb/unittests/basic_string_view/inserters/char/2.cc
@@ -0,0 +1,93 @@
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// inserters
+
+// NB: This file is predicated on sstreams, ostreams
+// working, not to mention other major details like char_traits, and
+// all of the string_view class.
+
+// { dg-options "-std=gnu++17" }
+// { dg-require-fileio "" }
+
+#include <string_view>
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <testsuite_hooks.h>
+
+// testing basic_filebuf::xsputn via stress testing with large string_views
+// based on a bug report libstdc++ 9
+// mode == out
+void
+test05(std::size_t size)
+{
+ bool test = true;
+
+ const char filename[] = "inserters_extractors-2.txt";
+ const char fillc = 'f';
+ std::ofstream ofs(filename);
+ std::string str(size, fillc);
+ std::string_view strv{str};
+
+ // sanity checks
+ VERIFY( str.size() == size );
+ VERIFY( ofs.good() );
+
+ // stress test
+ ofs << str << std::endl;
+ if (!ofs.good())
+ test = false;
+
+ ofs << str << std::endl;
+ if (!ofs.good())
+ test = false;
+
+ VERIFY( str.size() == size );
+ VERIFY( ofs.good() );
+
+ ofs.close();
+
+ // sanity check on the written file
+ std::ifstream ifs(filename);
+ std::size_t count = 0;
+ char c;
+ while (count <= (2 * size) + 4)
+ {
+ ifs >> c;
+ if (ifs.good() && c == fillc)
+ {
+ ++count;
+ c = '0';
+ }
+ else
+ break;
+ }
+
+ VERIFY( count == 2 * size );
+}
+
+int
+main()
+{
+ test05(1);
+ test05(1000);
+ test05(10000);
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/inserters/char/3.cc b/gdb/unittests/basic_string_view/inserters/char/3.cc
new file mode 100644
index 000000000000..7905661396da
--- /dev/null
+++ b/gdb/unittests/basic_string_view/inserters/char/3.cc
@@ -0,0 +1,54 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// inserters
+
+// NB: This file is predicated on sstreams, and ostreams
+// working, not to mention other major details like char_traits, and
+// all of the string_view class.
+
+#include <string_view>
+#include <sstream>
+#include <iomanip>
+#include <testsuite_hooks.h>
+
+// libstdc++/2830
+void
+test09()
+{
+ std::string_view foo{"peace\0\0\0& love"};
+
+ std::ostringstream oss1;
+ oss1 << foo;
+ VERIFY( oss1.str() == foo );
+
+ std::ostringstream oss2;
+ oss2.width(20);
+ oss2 << foo;
+ VERIFY( oss2.str() != foo );
+ VERIFY( oss2.str().size() == 20 );
+}
+
+int
+main()
+{
+ test09();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/inserters/pod/10081-out.cc b/gdb/unittests/basic_string_view/inserters/pod/10081-out.cc
new file mode 100644
index 000000000000..15538a45386c
--- /dev/null
+++ b/gdb/unittests/basic_string_view/inserters/pod/10081-out.cc
@@ -0,0 +1,75 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// class basic_istream::sentry
+
+#include <string_view>
+#include <ostream>
+#include <sstream>
+#include <locale>
+#include <typeinfo>
+#include <testsuite_hooks.h>
+#include <testsuite_character.h>
+
+void
+test01()
+{
+ using namespace std;
+
+ using __gnu_test::pod_ushort;
+ typedef basic_string_view<pod_ushort> string_type;
+ typedef basic_stringbuf<pod_ushort> stringbuf_type;
+ typedef basic_ostream<pod_ushort> ostream_type;
+
+ string_type str;
+ stringbuf_type strbuf01;
+ ostream_type stream(&strbuf01);
+
+ try
+ {
+ stream << str;
+ }
+ catch (std::bad_cast& obj)
+ {
+ // Ok, throws bad_cast because locale has no ctype facet.
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+
+ const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
+ stream.imbue(loc);
+ try
+ {
+ stream << str;
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/inserters/wchar_t/1.cc b/gdb/unittests/basic_string_view/inserters/wchar_t/1.cc
new file mode 100644
index 000000000000..c5cbdba25640
--- /dev/null
+++ b/gdb/unittests/basic_string_view/inserters/wchar_t/1.cc
@@ -0,0 +1,70 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// inserters
+
+// NB: This file is predicated on sstreams, and ostreams
+// working, not to mention other major details like char_traits, and
+// all of the string_view class.
+
+#include <string_view>
+#include <stdexcept>
+#include <sstream>
+#include <fstream>
+#include <iostream>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::wstring_view::size_type csize_type;
+ typedef std::wstring_view::const_reference cref;
+ typedef std::wstring_view::reference ref;
+
+ const std::wstring_view str01(L"sailing grand traverse bay\n"
+ L"\t\t\t from Elk Rapids to the point reminds me of miles");
+ const std::wstring_view str02(L"sailing");
+ const std::wstring_view str03(L"grand");
+ const std::wstring_view str04(L"traverse");
+ const std::wstring_view str05;
+ std::wstring_view str10;
+
+ // ostream& operator<<(ostream&, const basic_string_view&)
+ std::wostringstream ostrs01;
+ try
+ {
+ ostrs01 << str01;
+ VERIFY( ostrs01.str() == str01 );
+ }
+ catch(std::exception& fail)
+ {
+ VERIFY( false );
+ }
+
+ std::wstring_view hello_world;
+ std::wcout << hello_world;
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/inserters/wchar_t/2.cc b/gdb/unittests/basic_string_view/inserters/wchar_t/2.cc
new file mode 100644
index 000000000000..ebb275213258
--- /dev/null
+++ b/gdb/unittests/basic_string_view/inserters/wchar_t/2.cc
@@ -0,0 +1,91 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// inserters
+
+// NB: This file is predicated on sstreams, istreams, and ostreams
+// working, not to mention other major details like char_traits, and
+// all of the string_view class.
+
+#include <string_view>
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <testsuite_hooks.h>
+
+// testing basic_filebuf::xsputn via stress testing with large string_views
+// based on a bug report libstdc++ 9
+// mode == out
+void
+test05(std::size_t size)
+{
+ bool test = true;
+
+ const char filename[] = "inserters_extractors-2.txt";
+ const wchar_t fillc = L'f';
+ std::wofstream ofs(filename);
+ std::wstring str(size, fillc);
+ std::wstring_view strv(str);
+
+ // sanity checks
+ VERIFY( str.size() == size );
+ VERIFY( ofs.good() );
+
+ // stress test
+ ofs << str << std::endl;
+ if (!ofs.good())
+ test = false;
+
+ ofs << str << std::endl;
+ if (!ofs.good())
+ test = false;
+
+ VERIFY( str.size() == size );
+ VERIFY( ofs.good() );
+
+ ofs.close();
+
+ // sanity check on the written file
+ std::wifstream ifs(filename);
+ std::size_t count = 0;
+ wchar_t c;
+ while (count <= (2 * size) + 4)
+ {
+ ifs >> c;
+ if (ifs.good() && c == fillc)
+ {
+ ++count;
+ c = '0';
+ }
+ else
+ break;
+ }
+
+ VERIFY( count == 2 * size );
+}
+
+int
+main()
+{
+ test05(1);
+ test05(1000);
+ test05(10000);
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/inserters/wchar_t/3.cc b/gdb/unittests/basic_string_view/inserters/wchar_t/3.cc
new file mode 100644
index 000000000000..569c4213a7fa
--- /dev/null
+++ b/gdb/unittests/basic_string_view/inserters/wchar_t/3.cc
@@ -0,0 +1,53 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// inserters
+
+// NB: This file is predicated on sstreams, istreams, and ostreams
+// working, not to mention other major details like char_traits, and
+// all of the string_view class.
+
+#include <string_view>
+#include <sstream>
+#include <iomanip>
+#include <testsuite_hooks.h>
+
+void
+test09()
+{
+ std::wstring_view foo{L"peace\0\0\0& love"};
+
+ std::wostringstream oss1;
+ oss1 << foo;
+ VERIFY( oss1.str() == foo );
+
+ std::wostringstream oss2;
+ oss2.width(20);
+ oss2 << foo;
+ VERIFY( oss2.str() != foo );
+ VERIFY( oss2.str().size() == 20 );
+}
+
+int
+main()
+{
+ test09();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/literals/types.cc b/gdb/unittests/basic_string_view/literals/types.cc
new file mode 100644
index 000000000000..8b3b467efc43
--- /dev/null
+++ b/gdb/unittests/basic_string_view/literals/types.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <type_traits>
+
+void
+test01()
+{
+ using namespace std::literals::string_view_literals;
+
+ static_assert(std::is_same<decltype("Hello"sv), std::string_view>::value,
+ "\"Hello\"s is std::string_view");
+
+ static_assert(std::is_same<decltype(u8"Hello"sv), std::string_view>::value,
+ "u8\"Hello\"s is std::string_view");
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ static_assert(std::is_same<decltype(L"Hello"sv), std::wstring_view>::value,
+ "L\"Hello\"s is std::wstring_view");
+#endif
+
+ static_assert(std::is_same<decltype(u"Hello"sv), std::u16string_view>::value,
+ "u\"Hello\"s is std::u16string_view");
+
+ static_assert(std::is_same<decltype(U"Hello"sv), std::u32string_view>::value,
+ "U\"Hello\"s is std::u32string_view");
+}
diff --git a/gdb/unittests/basic_string_view/literals/values.cc b/gdb/unittests/basic_string_view/literals/values.cc
new file mode 100644
index 000000000000..b2897a136b8b
--- /dev/null
+++ b/gdb/unittests/basic_string_view/literals/values.cc
@@ -0,0 +1,72 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using namespace std::literals::string_view_literals;
+
+ std::string_view planet = "Mercury"sv;
+#ifdef _GLIBCXX_USE_WCHAR_T
+ std::wstring_view wplanet = L"Venus"sv;
+#endif
+ std::string_view u8planet = u8"Mars"sv;
+ std::u16string_view u16planet = u"Jupiter"sv;
+ std::u32string_view u32planet = U"Saturn"sv;
+
+ VERIFY( planet == std::string_view("Mercury") );
+#ifdef _GLIBCXX_USE_WCHAR_T
+ VERIFY( wplanet == std::wstring_view(L"Venus") );
+#endif
+ VERIFY( u8planet == std::string_view(u8"Mars") );
+ VERIFY( u16planet == std::u16string_view(u"Jupiter") );
+ VERIFY( u32planet == std::u32string_view(U"Saturn") );
+}
+
+void
+test02()
+{
+ using namespace std::literals::string_view_literals;
+
+ std::string_view planet_cratered = "Mercury\0cratered"sv;
+#ifdef _GLIBCXX_USE_WCHAR_T
+ std::wstring_view wplanet_cratered = L"Venus\0cratered"sv;
+#endif
+ std::string_view u8planet_cratered = u8"Mars\0cratered"sv;
+ std::u16string_view u16planet_cratered = u"Jupiter\0cratered"sv;
+ std::u32string_view u32planet_cratered = U"Saturn\0cratered"sv;
+
+ VERIFY( planet_cratered == std::string_view("Mercury\0cratered", 16) );
+#ifdef _GLIBCXX_USE_WCHAR_T
+ VERIFY( wplanet_cratered == std::wstring_view(L"Venus\0cratered", 14) );
+#endif
+ VERIFY( u8planet_cratered == std::string_view(u8"Mars\0cratered", 13) );
+ VERIFY( u16planet_cratered == std::u16string_view(u"Jupiter\0cratered", 16) );
+ VERIFY( u32planet_cratered == std::u32string_view(U"Saturn\0cratered", 15) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc b/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc
new file mode 100644
index 000000000000..ba08a98eeaec
--- /dev/null
+++ b/gdb/unittests/basic_string_view/modifiers/remove_prefix/char/1.cc
@@ -0,0 +1,61 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using std::string_view;
+
+ string_view str0{"olympus mons"};
+ string_view::pointer p = str0.data();
+ str0.remove_prefix(4);
+ VERIFY( str0.data() == p + 4);
+ VERIFY( str0.length() == 8 );
+ VERIFY( str0 == string_view{"pus mons"} );
+}
+
+constexpr bool
+test02()
+{
+ using std::string_view;
+
+ string_view str0{"olympus mons"};
+ string_view::pointer p = str0.data();
+ str0.remove_prefix(4);
+ if ( str0.data() != p + 4)
+ return false;
+ if ( str0.length() != 8 )
+ return false;
+ if ( str0 != string_view{"pus mons"} )
+ return false;
+
+ return true;
+}
+
+int
+main()
+{
+ test01();
+ static_assert( test02() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc b/gdb/unittests/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc
new file mode 100644
index 000000000000..3c6911824c6a
--- /dev/null
+++ b/gdb/unittests/basic_string_view/modifiers/remove_prefix/wchar_t/1.cc
@@ -0,0 +1,61 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using std::wstring_view;
+
+ wstring_view str0{L"olympus mons"};
+ wstring_view::pointer p = str0.data();
+ str0.remove_prefix(4);
+ VERIFY( str0.data() == p + 4);
+ VERIFY( str0.length() == 8 );
+ VERIFY( str0 == wstring_view{L"pus mons"} );
+}
+
+constexpr bool
+test02()
+{
+ using std::wstring_view;
+
+ wstring_view str0{L"olympus mons"};
+ wstring_view::pointer p = str0.data();
+ str0.remove_prefix(4);
+ if ( str0.data() != p + 4)
+ return false;
+ if ( str0.length() != 8 )
+ return false;
+ if ( str0 != wstring_view{L"pus mons"} )
+ return false;
+
+ return true;
+}
+
+int
+main()
+{
+ test01();
+ static_assert( test02() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc b/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc
new file mode 100644
index 000000000000..1b71ee936e8c
--- /dev/null
+++ b/gdb/unittests/basic_string_view/modifiers/remove_suffix/char/1.cc
@@ -0,0 +1,61 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using std::string_view;
+
+ string_view str0{"olympus mons"};
+ string_view::pointer p = str0.data();
+ str0.remove_suffix(2);
+ VERIFY( str0.data() == p);
+ VERIFY( str0.length() == 10 );
+ VERIFY( str0 == string_view{"olympus mo"} );
+}
+
+constexpr bool
+test02()
+{
+ using std::string_view;
+
+ string_view str0{"olympus mons"};
+ string_view::pointer p = str0.data();
+ str0.remove_suffix(2);
+ if ( str0.data() != p)
+ return false;
+ if ( str0.length() != 10 )
+ return false;
+ if ( str0 != string_view{"olympus mo"} )
+ return false;
+
+ return true;
+}
+
+int
+main()
+{
+ test01();
+ static_assert( test02() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc b/gdb/unittests/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc
new file mode 100644
index 000000000000..0f94a092ad69
--- /dev/null
+++ b/gdb/unittests/basic_string_view/modifiers/remove_suffix/wchar_t/1.cc
@@ -0,0 +1,61 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ using std::wstring_view;
+
+ wstring_view str0{L"olympus mons"};
+ wstring_view::pointer p = str0.data();
+ str0.remove_suffix(2);
+ VERIFY( str0.data() == p);
+ VERIFY( str0.length() == 10 );
+ VERIFY( str0 == wstring_view{L"olympus mo"} );
+}
+
+constexpr bool
+test02()
+{
+ using std::wstring_view;
+
+ wstring_view str0{L"olympus mons"};
+ wstring_view::pointer p = str0.data();
+ str0.remove_suffix(2);
+ if ( str0.data() != p)
+ return false;
+ if ( str0.length() != 10 )
+ return false;
+ if ( str0 != wstring_view{L"olympus mo"} )
+ return false;
+
+ return true;
+}
+
+int
+main()
+{
+ test01();
+ static_assert( test02() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc b/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc
new file mode 100644
index 000000000000..90d26692599c
--- /dev/null
+++ b/gdb/unittests/basic_string_view/modifiers/swap/char/1.cc
@@ -0,0 +1,35 @@
+// Copyright (C) 2017-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <string_view>
+
+constexpr bool
+test01()
+{
+ using std::string_view;
+
+ string_view s1{"last"};
+ string_view s2{"first"};
+
+ s1.swap(s2);
+ return s1 == "first" && s2 == "last";
+}
+
+static_assert( test01() );
diff --git a/gdb/unittests/basic_string_view/modifiers/swap/wchar_t/1.cc b/gdb/unittests/basic_string_view/modifiers/swap/wchar_t/1.cc
new file mode 100644
index 000000000000..bd757ecfaa93
--- /dev/null
+++ b/gdb/unittests/basic_string_view/modifiers/swap/wchar_t/1.cc
@@ -0,0 +1,35 @@
+// Copyright (C) 2017-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <string_view>
+
+constexpr bool
+test01()
+{
+ using std::wstring_view;
+
+ wstring_view s1{L"last"};
+ wstring_view s2{L"first"};
+
+ s1.swap(s2);
+ return s1 == L"first" && s2 == L"last";
+}
+
+static_assert( test01() );
diff --git a/gdb/unittests/basic_string_view/operations/compare/char/1.cc b/gdb/unittests/basic_string_view/operations/compare/char/1.cc
new file mode 100644
index 000000000000..46691ebd52a1
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/compare/char/1.cc
@@ -0,0 +1,132 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::compare
+// int compare(const basic_string_view& str) const;
+// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
+// int compare(size_type pos1, size_type n1, const basic_string_view& str,
+// size_type pos2, size_type n2) const;
+// int compare(const charT* s) const;
+// int compare(size_type pos1, size_type n1,
+// const charT* s, size_type n2 = npos) const;
+
+// NB compare should be thought of as a lexographical compare, ie how
+// things would be sorted in a dictionary.
+
+#include <string_view>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+enum want_value {lt=0, z=1, gt=2};
+
+int
+test_value(int result, want_value expected);
+
+int
+test_value(int result, want_value expected)
+{
+ bool pass = false;
+
+ switch (expected) {
+ case lt:
+ if (result < 0)
+ pass = true;
+ break;
+ case z:
+ if (!result)
+ pass = true;
+ break;
+ case gt:
+ if (result > 0)
+ pass = true;
+ break;
+ default:
+ pass = false; //should not get here
+ }
+ VERIFY(pass);
+ return 0;
+}
+
+int
+test01()
+{
+ using std::string_view;
+
+ string_view str_0("costa rica");
+ string_view str_1("costa marbella");
+ string_view str_2;
+
+ //sanity check
+ test_value(strcmp("costa marbella", "costa rica"), lt);
+ test_value(strcmp("costa rica", "costa rica"), z);
+ test_value(strcmp(str_1.data(), str_0.data()), lt);
+ test_value(strcmp(str_0.data(), str_1.data()), gt);
+ test_value(strncmp(str_1.data(), str_0.data(), 6), z);
+ test_value(strncmp(str_1.data(), str_0.data(), 14), lt);
+ test_value(memcmp(str_1.data(), str_0.data(), 6), z);
+ test_value(memcmp(str_1.data(), str_0.data(), 10), lt);
+ test_value(memcmp("costa marbella", "costa rica", 10), lt);
+
+ // int compare(const basic_string_view& str) const;
+ test_value(str_0.compare(str_1), gt); //because r>m
+ test_value(str_1.compare(str_0), lt); //because m<r
+ str_2 = str_0;
+ test_value(str_2.compare(str_0), z);
+ str_2 = "cost";
+ test_value(str_2.compare(str_0), lt);
+ str_2 = "costa ricans";
+ test_value(str_2.compare(str_0), gt);
+
+ // int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
+ test_value(str_1.compare(0, 6, str_0), lt);
+ str_2 = "cost";
+ test_value(str_1.compare(0, 4, str_2), z);
+ test_value(str_1.compare(0, 5, str_2), gt);
+
+ // int compare(size_type pos1, size_type n1, const basic_string_view& str,
+ // size_type pos2, size_type n2) const;
+ test_value(str_1.compare(0, 6, str_0, 0, 6), z);
+ test_value(str_1.compare(0, 7, str_0, 0, 7), lt);
+ test_value(str_0.compare(0, 7, str_1, 0, 7), gt);
+
+ // int compare(const charT* s) const;
+ test_value(str_0.compare("costa marbella"), gt);
+ test_value(str_1.compare("costa rica"), lt);
+ str_2 = str_0;
+ test_value(str_2.compare("costa rica"), z);
+ test_value(str_2.compare("cost"), gt);
+ test_value(str_2.compare("costa ricans"), lt);
+
+ // int compare(size_type pos, size_type n1, const charT* str,
+ // size_type n2 = npos) const;
+ test_value(str_1.compare(0, 6, "costa rica", 0, 6), z);
+ test_value(str_1.compare(0, 7, "costa rica", 0, 7), lt);
+ test_value(str_0.compare(0, 7, "costa marbella", 0, 7), gt);
+
+ return 0;
+}
+
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/compare/char/13650.cc b/gdb/unittests/basic_string_view/operations/compare/char/13650.cc
new file mode 100644
index 000000000000..ef9df20e6eec
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/compare/char/13650.cc
@@ -0,0 +1,49 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::compare [lib.string_view::compare]
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// libstdc++/13650
+void
+test01()
+{
+ using std::string_view;
+
+ const char lit_01[]{ 'w', 'e', '\0', 'r', 'd' };
+ const char lit_02[]{ 'w', 'e', 'i', '\0', 'd' };
+
+ const char lit_ref_a[]{ 'w', 'e', '\0', 'q', 'd' };
+ const string_view str_a(lit_ref_a, 5);
+ VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 );
+
+ const char lit_ref_b[]{ 'w', 'e', 'i' };
+ const string_view str_b(lit_ref_b, 3);
+ VERIFY( str_b.compare(0, 3, lit_02, 5) < 0 );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/compare/char/2.cc b/gdb/unittests/basic_string_view/operations/compare/char/2.cc
new file mode 100644
index 000000000000..ad9945a4dc10
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/compare/char/2.cc
@@ -0,0 +1,30 @@
+// Copyright (C) 2017-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <string_view>
+
+constexpr char c1[] = "one";
+constexpr char c2[] = "two";
+
+constexpr std::string_view s1{c1};
+constexpr std::string_view s2{c2};
+
+constexpr int n1 = s1.compare(s1);
+constexpr int n2 = s1.compare(s2);
diff --git a/gdb/unittests/basic_string_view/operations/compare/char/70483.cc b/gdb/unittests/basic_string_view/operations/compare/char/70483.cc
new file mode 100644
index 000000000000..5954d570fdc4
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/compare/char/70483.cc
@@ -0,0 +1,89 @@
+// Copyright (C) 2017-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <string_view>
+
+struct constexpr_char_traits : std::char_traits<char>
+{
+ static constexpr size_t
+ length(const char* val)
+ {
+ size_t res = 0;
+ for (; val[res] != '\0'; ++res)
+ ;
+ return res;
+ }
+
+ static constexpr int
+ compare(const char* lhs, const char* rhs, std::size_t count)
+ {
+ for (size_t pos = 0; pos < count; ++pos)
+ {
+ if (lhs[pos] != rhs[pos])
+ return lhs[pos] - rhs[pos];
+ }
+ return 0;
+ }
+};
+
+using string_view = std::basic_string_view<char, constexpr_char_traits>;
+
+constexpr
+string_view get()
+{
+ string_view res = "x::";
+ string_view start_pattern = "x";
+ res = res.substr(res.find(start_pattern) + start_pattern.size());
+ res = res.substr(0, res.find_first_of(";]"));
+ res = res.substr(res.rfind("::"));
+ return res;
+}
+
+static_assert( get() == get() );
+
+using std::u16string_view;
+
+constexpr
+u16string_view get16()
+{
+ u16string_view res = u"x::";
+ u16string_view start_pattern = u"x";
+ res = res.substr(res.find(start_pattern) + start_pattern.size());
+ res = res.substr(0, res.find_first_of(u";]"));
+ res = res.substr(res.rfind(u"::"));
+ return res;
+}
+
+static_assert( get16() == get16() );
+
+using std::u32string_view;
+
+constexpr
+u32string_view get32()
+{
+ u32string_view res = U"x::";
+ u32string_view start_pattern = U"x";
+ res = res.substr(res.find(start_pattern) + start_pattern.size());
+ res = res.substr(0, res.find_first_of(U";]"));
+ res = res.substr(res.rfind(U"::"));
+ return res;
+}
+
+static_assert( get32() == get32() );
diff --git a/gdb/unittests/basic_string_view/operations/compare/wchar_t/1.cc b/gdb/unittests/basic_string_view/operations/compare/wchar_t/1.cc
new file mode 100644
index 000000000000..15de7ccca646
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/compare/wchar_t/1.cc
@@ -0,0 +1,133 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::compare
+// int compare(const basic_string_view& str) const;
+// int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
+// int compare(size_type pos1, size_type n1, const basic_string_view& str,
+// size_type pos2, size_type n2) const;
+// int compare(const charT* s) const;
+// int compare(size_type pos1, size_type n1,
+// const charT* s, size_type n2 = npos) const;
+
+// NB compare should be thought of as a lexographical compare, ie how
+// things would be sorted in a dictionary.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+enum want_value {lt=0, z=1, gt=2};
+
+int
+test_value(int result, want_value expected);
+
+int
+test_value(int result, want_value expected)
+{
+ bool pass = false;
+
+ switch (expected) {
+ case lt:
+ if (result < 0)
+ pass = true;
+ break;
+ case z:
+ if (!result)
+ pass = true;
+ break;
+ case gt:
+ if (result > 0)
+ pass = true;
+ break;
+ default:
+ pass = false; //should not get here
+ }
+
+ VERIFY(pass);
+ return 0;
+}
+
+
+int
+test01()
+{
+ using std::wstring_view;
+
+ wstring_view str_0(L"costa rica");
+ wstring_view str_1(L"costa marbella");
+ wstring_view str_2;
+
+ //sanity check
+ test_value(wcscmp(L"costa marbella", L"costa rica"), lt);
+ test_value(wcscmp(L"costa rica", L"costa rica"), z);
+ test_value(wcscmp(str_1.data(), str_0.data()), lt);
+ test_value(wcscmp(str_0.data(), str_1.data()), gt);
+ test_value(wcsncmp(str_1.data(), str_0.data(), 6), z);
+ test_value(wcsncmp(str_1.data(), str_0.data(), 14), lt);
+ test_value(wmemcmp(str_1.data(), str_0.data(), 6), z);
+ test_value(wmemcmp(str_1.data(), str_0.data(), 14), lt);
+ test_value(wmemcmp(L"costa marbella", L"costa rica", 14), lt);
+
+ // int compare(const basic_string_view& str) const;
+ test_value(str_0.compare(str_1), gt); //because r>m
+ test_value(str_1.compare(str_0), lt); //because m<r
+ str_2 = str_0;
+ test_value(str_2.compare(str_0), z);
+ str_2 = L"cost";
+ test_value(str_2.compare(str_0), lt);
+ str_2 = L"costa ricans";
+ test_value(str_2.compare(str_0), gt);
+
+ // int compare(size_type pos1, size_type n1, const basic_string_view& str) const;
+ test_value(str_1.compare(0, 6, str_0), lt);
+ str_2 = L"cost";
+ test_value(str_1.compare(0, 4, str_2), z);
+ test_value(str_1.compare(0, 5, str_2), gt);
+
+ // int compare(size_type pos1, size_type n1, const basic_string_view& str,
+ // size_type pos2, size_type n2) const;
+ test_value(str_1.compare(0, 6, str_0, 0, 6), z);
+ test_value(str_1.compare(0, 7, str_0, 0, 7), lt);
+ test_value(str_0.compare(0, 7, str_1, 0, 7), gt);
+
+ // int compare(const charT* s) const;
+ test_value(str_0.compare(L"costa marbella"), gt);
+ test_value(str_1.compare(L"costa rica"), lt);
+ str_2 = str_0;
+ test_value(str_2.compare(L"costa rica"), z);
+ test_value(str_2.compare(L"cost"), gt);
+ test_value(str_2.compare(L"costa ricans"), lt);
+
+ // int compare(size_type pos, size_type n1, const charT* str,
+ // size_type n2 = npos) const;
+ test_value(str_1.compare(0, 6, L"costa rica", 0, 6), z);
+ test_value(str_1.compare(0, 7, L"costa rica", 0, 7), lt);
+ test_value(str_0.compare(0, 7, L"costa marbella", 0, 7), gt);
+
+ return 0;
+}
+
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/compare/wchar_t/13650.cc b/gdb/unittests/basic_string_view/operations/compare/wchar_t/13650.cc
new file mode 100644
index 000000000000..dd19eb80665e
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/compare/wchar_t/13650.cc
@@ -0,0 +1,49 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::compare [lib.string_view::compare]
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// libstdc++/13650
+void
+test01()
+{
+ using std::wstring_view;
+
+ const wchar_t lit_01[] = { L'w', L'e', L'\0', L'r', L'd' };
+ const wchar_t lit_02[] = { L'w', L'e', L'i', L'\0', L'd' };
+
+ const wchar_t lit_ref_a[] = { L'w', L'e', L'\0', L'q', L'd' };
+ const wstring_view str_a(lit_ref_a, 5);
+ VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 );
+
+ const wchar_t lit_ref_b[] = { L'w', L'e', L'i' };
+ const wstring_view str_b(lit_ref_b, 3);
+ VERIFY( str_b.compare(0, 3, lit_02, 5) < 0 );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/compare/wchar_t/2.cc b/gdb/unittests/basic_string_view/operations/compare/wchar_t/2.cc
new file mode 100644
index 000000000000..250129c6c67a
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/compare/wchar_t/2.cc
@@ -0,0 +1,30 @@
+// Copyright (C) 2017-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <string_view>
+
+constexpr wchar_t c1[] = L"one";
+constexpr wchar_t c2[] = L"two";
+
+constexpr std::wstring_view s1{c1};
+constexpr std::wstring_view s2{c2};
+
+constexpr int n1 = s1.compare(s1);
+constexpr int n2 = s1.compare(s2);
diff --git a/gdb/unittests/basic_string_view/operations/copy/char/1.cc b/gdb/unittests/basic_string_view/operations/copy/char/1.cc
new file mode 100644
index 000000000000..6caf0e1507a6
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/copy/char/1.cc
@@ -0,0 +1,45 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::copy
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::string_view::size_type csize_type;
+
+ const char str_lit01[] = "123456789A";
+ const std::string_view str01(str_lit01);
+ char buffer[4] = { 0 };
+
+ csize_type len = str01.copy(buffer, sizeof(buffer), 8);
+ VERIFY( 2 == len );
+ VERIFY( '9' == buffer[0] );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/copy/wchar_t/1.cc b/gdb/unittests/basic_string_view/operations/copy/wchar_t/1.cc
new file mode 100644
index 000000000000..84f3208add62
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/copy/wchar_t/1.cc
@@ -0,0 +1,46 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::copy
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::wstring_view::size_type csize_type;
+ csize_type csz01;
+
+ const wchar_t str_lit01[] = L"123456789A";
+ const std::wstring_view str01(str_lit01);
+ wchar_t buffer[4] = { 0 };
+
+ csize_type len = str01.copy(buffer, sizeof(buffer), 8);
+ VERIFY( 2 == len );
+ VERIFY( L'9' == buffer[0] );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/data/char/1.cc b/gdb/unittests/basic_string_view/operations/data/char/1.cc
new file mode 100644
index 000000000000..18fc9f5fe888
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/data/char/1.cc
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// string_view operations
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+test01()
+{
+ std::string_view empty;
+
+ VERIFY( empty.size() == 0 );
+ const std::string_view::value_type* p = empty.data();
+ VERIFY( p == nullptr );
+
+ return 0;
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/data/wchar_t/1.cc b/gdb/unittests/basic_string_view/operations/data/wchar_t/1.cc
new file mode 100644
index 000000000000..6596db528996
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/data/wchar_t/1.cc
@@ -0,0 +1,43 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// string_view operations
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+int
+test01()
+{
+ std::wstring_view empty;
+
+ VERIFY( empty.size() == 0 );
+ const std::wstring_view::value_type* p = empty.data();
+ VERIFY( p == nullptr );
+
+ return 0;
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/find/char/1.cc b/gdb/unittests/basic_string_view/operations/find/char/1.cc
new file mode 100644
index 000000000000..d7d2f37706eb
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/find/char/1.cc
@@ -0,0 +1,164 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view find
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::string_view::size_type csize_type;
+ typedef std::string_view::const_reference cref;
+ typedef std::string_view::reference ref;
+ csize_type npos = std::string_view::npos;
+ csize_type csz01, csz02;
+
+ const char str_lit01[] = "mave";
+ const std::string_view str01("mavericks, santa cruz");
+ std::string_view str02(str_lit01);
+ std::string_view str03("s, s");
+ std::string_view str04;
+
+ // size_type find(const string_view&, size_type pos = 0) const;
+ csz01 = str01.find(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str01, 4);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str02, 3);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find(str03, 3);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find(str03, 12);
+ VERIFY( csz01 == npos );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ csz01 = str01.find(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str04, 5);
+ VERIFY( csz01 == 5 );
+ csz01 = str01.find(str04, str01.size());
+ VERIFY( csz01 == str01.size() );
+ csz01 = str01.find(str04, str01.size()+1);
+ VERIFY( csz01 == npos );
+
+ // size_type find(const char* s, size_type pos, size_type n) const;
+ csz01 = str01.find(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str_lit01, 3, 0);
+ VERIFY( csz01 == 3 );
+
+ // size_type find(const char* s, size_type pos = 0) const;
+ csz01 = str01.find(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str_lit01, 3);
+ VERIFY( csz01 == npos );
+
+ // size_type find(char c, size_type pos = 0) const;
+ csz01 = str01.find('z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+ csz01 = str01.find('/');
+ VERIFY( csz01 == npos );
+}
+
+constexpr bool
+test02()
+{
+ typedef std::string_view::size_type csize_type;
+ typedef std::string_view::const_reference cref;
+ typedef std::string_view::reference ref;
+ csize_type npos = std::string_view::npos;
+ csize_type csz01 = 0, csz02 = 0;
+
+ const char str_lit01[] = "mave";
+ const std::string_view str01("mavericks, santa cruz");
+ std::string_view str02(str_lit01);
+ std::string_view str03("s, s");
+ std::string_view str04;
+
+#undef VERIFY
+#define VERIFY(x) if(!(x)) return false
+
+ // size_type find(const string_view&, size_type pos = 0) const;
+ csz01 = str01.find(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str01, 4);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str02, 3);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find(str03, 3);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find(str03, 12);
+ VERIFY( csz01 == npos );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ csz01 = str01.find(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str04, 5);
+ VERIFY( csz01 == 5 );
+ csz01 = str01.find(str04, str01.size());
+ VERIFY( csz01 == str01.size() );
+ csz01 = str01.find(str04, str01.size()+1);
+ VERIFY( csz01 == npos );
+
+ // size_type find(const char* s, size_type pos, size_type n) const;
+ csz01 = str01.find(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str_lit01, 3, 0);
+ VERIFY( csz01 == 3 );
+
+ // size_type find(const char* s, size_type pos = 0) const;
+ csz01 = str01.find(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str_lit01, 3);
+ VERIFY( csz01 == npos );
+
+ // size_type find(char c, size_type pos = 0) const;
+ csz01 = str01.find('z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+ csz01 = str01.find('/');
+ VERIFY( csz01 == npos );
+
+ return true;
+}
+
+
+int
+main()
+{
+ test01();
+ static_assert( test02() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/find/char/2.cc b/gdb/unittests/basic_string_view/operations/find/char/2.cc
new file mode 100644
index 000000000000..af8a526d12c7
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/find/char/2.cc
@@ -0,0 +1,161 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view find_first_of
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test02()
+{
+ typedef std::string_view::size_type csize_type;
+ csize_type npos = std::string_view::npos;
+ csize_type csz01, csz02;
+
+ const char str_lit01[] = "mave";
+ const std::string_view str01("mavericks, santa cruz");
+ std::string_view str02(str_lit01);
+ std::string_view str03("s, s");
+ std::string_view str04;
+
+ // size_type find_first_of(const string_view&, size_type pos = 0) const;
+ std::string_view str05("xena rulez");
+ csz01 = str01.find_first_of(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str01, 4);
+ VERIFY( csz01 == 4 );
+ csz01 = str01.find_first_of(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str02, 3);
+ VERIFY( csz01 == 3 );
+ csz01 = str01.find_first_of(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_of(str03, 3);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_of(str03, 12);
+ VERIFY( csz01 == 16 );
+ csz01 = str01.find_first_of(str05, 0);
+ VERIFY( csz01 == 1 );
+ csz01 = str01.find_first_of(str05, 4);
+ VERIFY( csz01 == 4 );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ // However, str1.find_first_of(str2,pos) finds the first character in
+ // str1 (starting at pos) that exists in str2, which is none for empty str2
+ csz01 = str01.find_first_of(str04, 0);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_of(str04, 5);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_of(const char* s, size_type pos, size_type n) const;
+ csz01 = str01.find_first_of(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str_lit01, 3, 0);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_of(const char* s, size_type pos = 0) const;
+ csz01 = str01.find_first_of(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str_lit01, 3);
+ VERIFY( csz01 == 3 );
+
+ // size_type find_first_of(char c, size_type pos = 0) const;
+ csz01 = str01.find_first_of('z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+}
+
+constexpr bool
+test03()
+{
+ typedef std::string_view::size_type csize_type;
+ csize_type npos = std::string_view::npos;
+ csize_type csz01 = 0, csz02 = 0;
+
+ const char str_lit01[] = "mave";
+ const std::string_view str01("mavericks, santa cruz");
+ std::string_view str02(str_lit01);
+ std::string_view str03("s, s");
+ std::string_view str04;
+
+#undef VERIFY
+#define VERIFY(x) if(!(x)) return false
+
+ // size_type find_first_of(const string_view&, size_type pos = 0) const;
+ std::string_view str05("xena rulez");
+ csz01 = str01.find_first_of(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str01, 4);
+ VERIFY( csz01 == 4 );
+ csz01 = str01.find_first_of(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str02, 3);
+ VERIFY( csz01 == 3 );
+ csz01 = str01.find_first_of(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_of(str03, 3);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_of(str03, 12);
+ VERIFY( csz01 == 16 );
+ csz01 = str01.find_first_of(str05, 0);
+ VERIFY( csz01 == 1 );
+ csz01 = str01.find_first_of(str05, 4);
+ VERIFY( csz01 == 4 );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ // However, str1.find_first_of(str2,pos) finds the first character in
+ // str1 (starting at pos) that exists in str2, which is none for empty str2
+ csz01 = str01.find_first_of(str04, 0);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_of(str04, 5);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_of(const char* s, size_type pos, size_type n) const;
+ csz01 = str01.find_first_of(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str_lit01, 3, 0);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_of(const char* s, size_type pos = 0) const;
+ csz01 = str01.find_first_of(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str_lit01, 3);
+ VERIFY( csz01 == 3 );
+
+ // size_type find_first_of(char c, size_type pos = 0) const;
+ csz01 = str01.find_first_of('z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+
+ return true;
+}
+
+int
+main()
+{
+ test02();
+ static_assert( test03() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/find/char/3.cc b/gdb/unittests/basic_string_view/operations/find/char/3.cc
new file mode 100644
index 000000000000..5ec651ef3f93
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/find/char/3.cc
@@ -0,0 +1,161 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view find_first_not_of
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test03()
+{
+ typedef std::string_view::size_type csize_type;
+ csize_type npos = std::string_view::npos;
+ csize_type csz01;
+
+ const std::string_view str01("Bob Rock, per me");
+ const char str_lit01[] = "Bob Rock";
+ std::string_view str02("ovvero Trivi");
+ std::string_view str03(str_lit01);
+ std::string_view str04;
+
+ // size_type find_first_not_of(const string_view&, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(str01);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_not_of(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str02, 10);
+ VERIFY( csz01 == 10 );
+ csz01 = str01.find_first_not_of(str02, 12);
+ VERIFY( csz01 == 14 );
+ csz01 = str01.find_first_not_of(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_not_of(str03, 15);
+ VERIFY( csz01 == 15 );
+ csz01 = str01.find_first_not_of(str03, 16);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_not_of(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str04, 12);
+ VERIFY( csz01 == 12 );
+ csz01 = str03.find_first_not_of(str01, 0);
+ VERIFY( csz01 == npos );
+ csz01 = str04.find_first_not_of(str02, 0);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_not_of(const char* s, size_type pos, size_type n) const;
+ csz01 = str01.find_first_not_of(str_lit01, 0, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str_lit01, 0, 8);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_not_of(str_lit01, 10, 0);
+ VERIFY( csz01 == 10 );
+
+ // size_type find_first_not_of(const char* s, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(str_lit01);
+ VERIFY( csz01 == 8 );
+ csz01 = str02.find_first_not_of(str_lit01, 2);
+ VERIFY( csz01 == 2 );
+
+ // size_type find_first_not_of(char c, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of('B');
+ VERIFY( csz01 == 1 );
+ csz01 = str01.find_first_not_of('o', 1);
+ VERIFY( csz01 == 2 );
+ csz01 = str02.find_first_not_of('z');
+ VERIFY( csz01 == 0 );
+ csz01 = str04.find_first_not_of('S');
+ VERIFY( csz01 == npos );
+}
+
+constexpr bool
+test04()
+{
+ typedef std::string_view::size_type csize_type;
+ csize_type npos = std::string_view::npos;
+ csize_type csz01 = 0;
+
+ const std::string_view str01("Bob Rock, per me");
+ const char str_lit01[] = "Bob Rock";
+ std::string_view str02("ovvero Trivi");
+ std::string_view str03(str_lit01);
+ std::string_view str04;
+
+#undef VERIFY
+#define VERIFY(x) if(!(x)) return false
+
+ // size_type find_first_not_of(const string_view&, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(str01);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_not_of(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str02, 10);
+ VERIFY( csz01 == 10 );
+ csz01 = str01.find_first_not_of(str02, 12);
+ VERIFY( csz01 == 14 );
+ csz01 = str01.find_first_not_of(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_not_of(str03, 15);
+ VERIFY( csz01 == 15 );
+ csz01 = str01.find_first_not_of(str03, 16);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_not_of(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str04, 12);
+ VERIFY( csz01 == 12 );
+ csz01 = str03.find_first_not_of(str01, 0);
+ VERIFY( csz01 == npos );
+ csz01 = str04.find_first_not_of(str02, 0);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_not_of(const char* s, size_type pos, size_type n) const;
+ csz01 = str01.find_first_not_of(str_lit01, 0, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str_lit01, 0, 8);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_not_of(str_lit01, 10, 0);
+ VERIFY( csz01 == 10 );
+
+ // size_type find_first_not_of(const char* s, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(str_lit01);
+ VERIFY( csz01 == 8 );
+ csz01 = str02.find_first_not_of(str_lit01, 2);
+ VERIFY( csz01 == 2 );
+
+ // size_type find_first_not_of(char c, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of('B');
+ VERIFY( csz01 == 1 );
+ csz01 = str01.find_first_not_of('o', 1);
+ VERIFY( csz01 == 2 );
+ csz01 = str02.find_first_not_of('z');
+ VERIFY( csz01 == 0 );
+ csz01 = str04.find_first_not_of('S');
+ VERIFY( csz01 == npos );
+
+ return true;
+}
+
+int
+main()
+{
+ test03();
+ static_assert( test04() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/find/char/4.cc b/gdb/unittests/basic_string_view/operations/find/char/4.cc
new file mode 100644
index 000000000000..ca4b1f17db42
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/find/char/4.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view find
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// libstdc++/31401
+void
+test01()
+{
+ typedef std::string_view::size_type csize_type;
+ csize_type npos = std::string_view::npos;
+
+ std::string_view use = "anu";
+ csize_type pos1 = use.find("a", npos);
+
+ VERIFY( pos1 == npos );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/find/wchar_t/1.cc b/gdb/unittests/basic_string_view/operations/find/wchar_t/1.cc
new file mode 100644
index 000000000000..535b2d5e383a
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/find/wchar_t/1.cc
@@ -0,0 +1,163 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view find
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::wstring_view::size_type csize_type;
+ typedef std::wstring_view::const_reference cref;
+ typedef std::wstring_view::reference ref;
+ csize_type npos = std::wstring_view::npos;
+ csize_type csz01, csz02;
+
+ const wchar_t str_lit01[] = L"mave";
+ const std::wstring_view str01(L"mavericks, santa cruz");
+ std::wstring_view str02(str_lit01);
+ std::wstring_view str03(L"s, s");
+ std::wstring_view str04;
+
+ // size_type find(const wstring_view&, size_type pos = 0) const;
+ csz01 = str01.find(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str01, 4);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str02, 3);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find(str03, 3);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find(str03, 12);
+ VERIFY( csz01 == npos );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ csz01 = str01.find(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str04, 5);
+ VERIFY( csz01 == 5 );
+ csz01 = str01.find(str04, str01.size());
+ VERIFY( csz01 == str01.size() );
+ csz01 = str01.find(str04, str01.size()+1);
+ VERIFY( csz01 == npos );
+
+ // size_type find(const wchar_t* s, size_type pos, size_type n) const;
+ csz01 = str01.find(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str_lit01, 3, 0);
+ VERIFY( csz01 == 3 );
+
+ // size_type find(const wchar_t* s, size_type pos = 0) const;
+ csz01 = str01.find(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str_lit01, 3);
+ VERIFY( csz01 == npos );
+
+ // size_type find(wchar_t c, size_type pos = 0) const;
+ csz01 = str01.find(L'z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+ csz01 = str01.find(L'/');
+ VERIFY( csz01 == npos );
+}
+
+constexpr bool
+test02()
+{
+ typedef std::wstring_view::size_type csize_type;
+ typedef std::wstring_view::const_reference cref;
+ typedef std::wstring_view::reference ref;
+ csize_type npos = std::wstring_view::npos;
+ csize_type csz01 = 0, csz02 = 0;
+
+ const wchar_t str_lit01[] = L"mave";
+ const std::wstring_view str01(L"mavericks, santa cruz");
+ std::wstring_view str02(str_lit01);
+ std::wstring_view str03(L"s, s");
+ std::wstring_view str04;
+
+#undef VERIFY
+#define VERIFY(x) if(!(x)) return false
+
+ // size_type find(const wstring_view&, size_type pos = 0) const;
+ csz01 = str01.find(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str01, 4);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str02, 3);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find(str03, 3);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find(str03, 12);
+ VERIFY( csz01 == npos );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ csz01 = str01.find(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str04, 5);
+ VERIFY( csz01 == 5 );
+ csz01 = str01.find(str04, str01.size());
+ VERIFY( csz01 == str01.size() );
+ csz01 = str01.find(str04, str01.size()+1);
+ VERIFY( csz01 == npos );
+
+ // size_type find(const wchar_t* s, size_type pos, size_type n) const;
+ csz01 = str01.find(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str_lit01, 3, 0);
+ VERIFY( csz01 == 3 );
+
+ // size_type find(const wchar_t* s, size_type pos = 0) const;
+ csz01 = str01.find(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find(str_lit01, 3);
+ VERIFY( csz01 == npos );
+
+ // size_type find(wchar_t c, size_type pos = 0) const;
+ csz01 = str01.find(L'z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+ csz01 = str01.find(L'/');
+ VERIFY( csz01 == npos );
+
+ return true;
+}
+
+int
+main()
+{
+ test01();
+ static_assert( test02() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/find/wchar_t/2.cc b/gdb/unittests/basic_string_view/operations/find/wchar_t/2.cc
new file mode 100644
index 000000000000..2802bf4442cb
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/find/wchar_t/2.cc
@@ -0,0 +1,161 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view find_first_of
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test02()
+{
+ typedef std::wstring_view::size_type csize_type;
+ csize_type npos = std::wstring_view::npos;
+ csize_type csz01, csz02;
+
+ const wchar_t str_lit01[] = L"mave";
+ const std::wstring_view str01(L"mavericks, santa cruz");
+ std::wstring_view str02(str_lit01);
+ std::wstring_view str03(L"s, s");
+ std::wstring_view str04;
+
+ // size_type find_first_of(const wstring_view&, size_type pos = 0) const;
+ std::wstring_view str05(L"xena rulez");
+ csz01 = str01.find_first_of(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str01, 4);
+ VERIFY( csz01 == 4 );
+ csz01 = str01.find_first_of(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str02, 3);
+ VERIFY( csz01 == 3 );
+ csz01 = str01.find_first_of(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_of(str03, 3);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_of(str03, 12);
+ VERIFY( csz01 == 16 );
+ csz01 = str01.find_first_of(str05, 0);
+ VERIFY( csz01 == 1 );
+ csz01 = str01.find_first_of(str05, 4);
+ VERIFY( csz01 == 4 );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ // However, str1.find_first_of(str2,pos) finds the first character in
+ // str1 (starting at pos) that exists in str2, which is none for empty str2
+ csz01 = str01.find_first_of(str04, 0);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_of(str04, 5);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_of(const wchar_t* s, size_type pos, size_type n) const;
+ csz01 = str01.find_first_of(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str_lit01, 3, 0);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_of(const wchar_t* s, size_type pos = 0) const;
+ csz01 = str01.find_first_of(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str_lit01, 3);
+ VERIFY( csz01 == 3 );
+
+ // size_type find_first_of(wchar_t c, size_type pos = 0) const;
+ csz01 = str01.find_first_of(L'z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+}
+
+constexpr bool
+test04()
+{
+ typedef std::wstring_view::size_type csize_type;
+ csize_type npos = std::wstring_view::npos;
+ csize_type csz01 = 0, csz02 = 0;
+
+ const wchar_t str_lit01[] = L"mave";
+ const std::wstring_view str01(L"mavericks, santa cruz");
+ std::wstring_view str02(str_lit01);
+ std::wstring_view str03(L"s, s");
+ std::wstring_view str04;
+
+#undef VERIFY
+#define VERIFY(x) if(!(x)) return false
+
+ // size_type find_first_of(const wstring_view&, size_type pos = 0) const;
+ std::wstring_view str05(L"xena rulez");
+ csz01 = str01.find_first_of(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str01, 4);
+ VERIFY( csz01 == 4 );
+ csz01 = str01.find_first_of(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str02, 3);
+ VERIFY( csz01 == 3 );
+ csz01 = str01.find_first_of(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_of(str03, 3);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_of(str03, 12);
+ VERIFY( csz01 == 16 );
+ csz01 = str01.find_first_of(str05, 0);
+ VERIFY( csz01 == 1 );
+ csz01 = str01.find_first_of(str05, 4);
+ VERIFY( csz01 == 4 );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ // However, str1.find_first_of(str2,pos) finds the first character in
+ // str1 (starting at pos) that exists in str2, which is none for empty str2
+ csz01 = str01.find_first_of(str04, 0);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_of(str04, 5);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_of(const wchar_t* s, size_type pos, size_type n) const;
+ csz01 = str01.find_first_of(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str_lit01, 3, 0);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_of(const wchar_t* s, size_type pos = 0) const;
+ csz01 = str01.find_first_of(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_of(str_lit01, 3);
+ VERIFY( csz01 == 3 );
+
+ // size_type find_first_of(wchar_t c, size_type pos = 0) const;
+ csz01 = str01.find_first_of(L'z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+
+ return true;
+}
+
+int
+main()
+{
+ test02();
+ static_assert( test04() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/find/wchar_t/3.cc b/gdb/unittests/basic_string_view/operations/find/wchar_t/3.cc
new file mode 100644
index 000000000000..6623bbdfc39f
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/find/wchar_t/3.cc
@@ -0,0 +1,161 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view find_first_not_of
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test03()
+{
+ typedef std::wstring_view::size_type csize_type;
+ csize_type npos = std::wstring_view::npos;
+ csize_type csz01;
+
+ const std::wstring_view str01(L"Bob Rock, per me");
+ const wchar_t str_lit01[] = L"Bob Rock";
+ std::wstring_view str02(L"ovvero Trivi");
+ std::wstring_view str03(str_lit01);
+ std::wstring_view str04;
+
+ // size_type find_first_not_of(const string_view&, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(str01);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_not_of(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str02, 10);
+ VERIFY( csz01 == 10 );
+ csz01 = str01.find_first_not_of(str02, 12);
+ VERIFY( csz01 == 14 );
+ csz01 = str01.find_first_not_of(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_not_of(str03, 15);
+ VERIFY( csz01 == 15 );
+ csz01 = str01.find_first_not_of(str03, 16);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_not_of(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str04, 12);
+ VERIFY( csz01 == 12 );
+ csz01 = str03.find_first_not_of(str01, 0);
+ VERIFY( csz01 == npos );
+ csz01 = str04.find_first_not_of(str02, 0);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_not_of(const char* s, size_type pos, size_type n) const;
+ csz01 = str01.find_first_not_of(str_lit01, 0, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str_lit01, 0, 8);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_not_of(str_lit01, 10, 0);
+ VERIFY( csz01 == 10 );
+
+ // size_type find_first_not_of(const char* s, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(str_lit01);
+ VERIFY( csz01 == 8 );
+ csz01 = str02.find_first_not_of(str_lit01, 2);
+ VERIFY( csz01 == 2 );
+
+ // size_type find_first_not_of(char c, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(L'B');
+ VERIFY( csz01 == 1 );
+ csz01 = str01.find_first_not_of(L'o', 1);
+ VERIFY( csz01 == 2 );
+ csz01 = str02.find_first_not_of(L'z');
+ VERIFY( csz01 == 0 );
+ csz01 = str04.find_first_not_of(L'S');
+ VERIFY( csz01 == npos );
+}
+
+constexpr bool
+test04()
+{
+ typedef std::wstring_view::size_type csize_type;
+ csize_type npos = std::wstring_view::npos;
+ csize_type csz01 = 0;
+
+ const std::wstring_view str01(L"Bob Rock, per me");
+ const wchar_t str_lit01[] = L"Bob Rock";
+ std::wstring_view str02(L"ovvero Trivi");
+ std::wstring_view str03(str_lit01);
+ std::wstring_view str04;
+
+#undef VERIFY
+#define VERIFY(x) if(!(x)) return false
+
+ // size_type find_first_not_of(const string_view&, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(str01);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_not_of(str02, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str02, 10);
+ VERIFY( csz01 == 10 );
+ csz01 = str01.find_first_not_of(str02, 12);
+ VERIFY( csz01 == 14 );
+ csz01 = str01.find_first_not_of(str03, 0);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_not_of(str03, 15);
+ VERIFY( csz01 == 15 );
+ csz01 = str01.find_first_not_of(str03, 16);
+ VERIFY( csz01 == npos );
+ csz01 = str01.find_first_not_of(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str04, 12);
+ VERIFY( csz01 == 12 );
+ csz01 = str03.find_first_not_of(str01, 0);
+ VERIFY( csz01 == npos );
+ csz01 = str04.find_first_not_of(str02, 0);
+ VERIFY( csz01 == npos );
+
+ // size_type find_first_not_of(const char* s, size_type pos, size_type n) const;
+ csz01 = str01.find_first_not_of(str_lit01, 0, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.find_first_not_of(str_lit01, 0, 8);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.find_first_not_of(str_lit01, 10, 0);
+ VERIFY( csz01 == 10 );
+
+ // size_type find_first_not_of(const char* s, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(str_lit01);
+ VERIFY( csz01 == 8 );
+ csz01 = str02.find_first_not_of(str_lit01, 2);
+ VERIFY( csz01 == 2 );
+
+ // size_type find_first_not_of(char c, size_type pos = 0) const;
+ csz01 = str01.find_first_not_of(L'B');
+ VERIFY( csz01 == 1 );
+ csz01 = str01.find_first_not_of(L'o', 1);
+ VERIFY( csz01 == 2 );
+ csz01 = str02.find_first_not_of(L'z');
+ VERIFY( csz01 == 0 );
+ csz01 = str04.find_first_not_of(L'S');
+ VERIFY( csz01 == npos );
+
+ return true;
+}
+
+int
+main()
+{
+ test03();
+ static_assert( test04() );
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/find/wchar_t/4.cc b/gdb/unittests/basic_string_view/operations/find/wchar_t/4.cc
new file mode 100644
index 000000000000..213bf78cf937
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/find/wchar_t/4.cc
@@ -0,0 +1,44 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view find
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// libstdc++/31401
+void
+test01()
+{
+ typedef std::wstring_view::size_type csize_type;
+ csize_type npos = std::wstring_view::npos;
+
+ std::wstring_view use = L"anu";
+ csize_type pos1 = use.find(L"a", npos);
+
+ VERIFY( pos1 == npos );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/rfind/char/1.cc b/gdb/unittests/basic_string_view/operations/rfind/char/1.cc
new file mode 100644
index 000000000000..ef26688fd761
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/rfind/char/1.cc
@@ -0,0 +1,94 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// basic_string_view rfind
+
+void
+test01()
+{
+ typedef std::string_view::size_type csize_type;
+ typedef std::string_view::const_reference cref;
+ typedef std::string_view::reference ref;
+ csize_type npos = std::string_view::npos;
+ csize_type csz01, csz02;
+
+ const char str_lit01[] = "mave";
+ const std::string_view str01("mavericks, santa cruz");
+ std::string_view str02(str_lit01);
+ std::string_view str03("s, s");
+ std::string_view str04;
+
+ // size_type rfind(const string_view&, size_type pos = 0) const;
+ csz01 = str01.rfind(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str01, 4);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str02,3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str02);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str03);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.rfind(str03, 3);
+ VERIFY( csz01 == npos );
+ csz01 = str01.rfind(str03, 12);
+ VERIFY( csz01 == 8 );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ csz01 = str01.rfind(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str04, 5);
+ VERIFY( csz01 == 5 );
+ csz01 = str01.rfind(str04, str01.size());
+ VERIFY( csz01 == str01.size() );
+ csz01 = str01.rfind(str04, str01.size()+1);
+ VERIFY( csz01 == str01.size() );
+
+ // size_type rfind(const char* s, size_type pos, size_type n) const;
+ csz01 = str01.rfind(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str_lit01, 3, 0);
+ VERIFY( csz01 == 3 );
+
+ // size_type rfind(const char* s, size_type pos = 0) const;
+ csz01 = str01.rfind(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str_lit01, 3);
+ VERIFY( csz01 == 0 );
+
+ // size_type rfind(char c, size_type pos = 0) const;
+ csz01 = str01.rfind('z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+ csz01 = str01.rfind('/');
+ VERIFY( csz01 == npos );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/rfind/char/2.cc b/gdb/unittests/basic_string_view/operations/rfind/char/2.cc
new file mode 100644
index 000000000000..df37f8c7745b
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/rfind/char/2.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// basic_string_view::find_last_of
+
+void
+test02()
+{
+ std::string_view z("ab");
+ std::string_view::size_type pos;
+ pos = z.find_last_of("ab");
+ VERIFY( pos == 1 );
+ pos = z.find_last_of("Xa");
+ VERIFY( pos == 0 );
+ pos = z.find_last_of("Xb");
+ VERIFY( pos == 1 );
+ pos = z.find_last_of("XYZ");
+ VERIFY( pos == std::string_view::npos );
+ pos = z.find_last_of('a');
+ VERIFY( pos == 0 );
+ pos = z.find_last_of('b');
+ VERIFY( pos == 1 );
+ pos = z.find_last_of('X');
+ VERIFY( pos == std::string_view::npos );
+}
+
+int
+main()
+{
+ test02();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/rfind/char/3.cc b/gdb/unittests/basic_string_view/operations/rfind/char/3.cc
new file mode 100644
index 000000000000..37f01a28af7f
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/rfind/char/3.cc
@@ -0,0 +1,66 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// basic_string_view::find_last_not_of
+
+void
+test03()
+{
+ typedef std::string_view::size_type csize_type;
+ std::string_view::size_type pos;
+ csize_type npos = std::string_view::npos;
+
+ std::string_view x;
+ pos = x.find_last_not_of('X');
+ VERIFY( pos == npos );
+ pos = x.find_last_not_of("XYZ");
+ VERIFY( pos == npos );
+
+ std::string_view y("a");
+ pos = y.find_last_not_of('X');
+ VERIFY( pos == 0 );
+ pos = y.find_last_not_of('a');
+ VERIFY( pos == npos );
+ pos = y.find_last_not_of("XYZ");
+ VERIFY( pos == 0 );
+ pos = y.find_last_not_of("a");
+ VERIFY( pos == npos );
+
+ std::string_view z("ab");
+ pos = z.find_last_not_of('X');
+ VERIFY( pos == 1 );
+ pos = z.find_last_not_of("XYZ");
+ VERIFY( pos == 1 );
+ pos = z.find_last_not_of('b');
+ VERIFY( pos == 0 );
+ pos = z.find_last_not_of("Xb");
+ VERIFY( pos == 0 );
+ pos = z.find_last_not_of("Xa");
+ VERIFY( pos == 1 );
+}
+int
+main()
+{
+ test03();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/rfind/wchar_t/1.cc b/gdb/unittests/basic_string_view/operations/rfind/wchar_t/1.cc
new file mode 100644
index 000000000000..197515f9b6cc
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/rfind/wchar_t/1.cc
@@ -0,0 +1,94 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// basic_string_view rfind
+
+void
+test01()
+{
+ typedef std::wstring_view::size_type csize_type;
+ typedef std::wstring_view::const_reference cref;
+ typedef std::wstring_view::reference ref;
+ csize_type npos = std::wstring_view::npos;
+ csize_type csz01, csz02;
+
+ const wchar_t str_lit01[] = L"mave";
+ const std::wstring_view str01(L"mavericks, santa cruz");
+ std::wstring_view str02(str_lit01);
+ std::wstring_view str03(L"s, s");
+ std::wstring_view str04;
+
+ // size_type rfind(const wstring_view&, size_type pos = 0) const;
+ csz01 = str01.rfind(str01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str01, 4);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str02,3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str02);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str03);
+ VERIFY( csz01 == 8 );
+ csz01 = str01.rfind(str03, 3);
+ VERIFY( csz01 == npos );
+ csz01 = str01.rfind(str03, 12);
+ VERIFY( csz01 == 8 );
+
+ // An empty string_view consists of no characters
+ // therefore it should be found at every point in a string_view,
+ // except beyond the end
+ csz01 = str01.rfind(str04, 0);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str04, 5);
+ VERIFY( csz01 == 5 );
+ csz01 = str01.rfind(str04, str01.size());
+ VERIFY( csz01 == str01.size() );
+ csz01 = str01.rfind(str04, str01.size()+1);
+ VERIFY( csz01 == str01.size() );
+
+ // size_type rfind(const wchar_t* s, size_type pos, size_type n) const;
+ csz01 = str01.rfind(str_lit01, 0, 3);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str_lit01, 3, 0);
+ VERIFY( csz01 == 3 );
+
+ // size_type rfind(const wchar_t* s, size_type pos = 0) const;
+ csz01 = str01.rfind(str_lit01);
+ VERIFY( csz01 == 0 );
+ csz01 = str01.rfind(str_lit01, 3);
+ VERIFY( csz01 == 0 );
+
+ // size_type rfind(wchar_t c, size_type pos = 0) const;
+ csz01 = str01.rfind(L'z');
+ csz02 = str01.size() - 1;
+ VERIFY( csz01 == csz02 );
+ csz01 = str01.rfind(L'/');
+ VERIFY( csz01 == npos );
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/rfind/wchar_t/2.cc b/gdb/unittests/basic_string_view/operations/rfind/wchar_t/2.cc
new file mode 100644
index 000000000000..7fb7c6c328bb
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/rfind/wchar_t/2.cc
@@ -0,0 +1,52 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// basic_string_view::find_last_of
+
+void
+test02()
+{
+ std::wstring_view::size_type pos;
+ std::wstring_view z(L"ab");
+ pos = z.find_last_of(L"ab");
+ VERIFY( pos == 1 );
+ pos = z.find_last_of(L"Xa");
+ VERIFY( pos == 0 );
+ pos = z.find_last_of(L"Xb");
+ VERIFY( pos == 1 );
+ pos = z.find_last_of(L"XYZ");
+ VERIFY( pos == std::wstring_view::npos );
+ pos = z.find_last_of(L'a');
+ VERIFY( pos == 0 );
+ pos = z.find_last_of(L'b');
+ VERIFY( pos == 1 );
+ pos = z.find_last_of(L'X');
+ VERIFY( pos == std::wstring_view::npos );
+}
+
+int
+main()
+{
+ test02();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/rfind/wchar_t/3.cc b/gdb/unittests/basic_string_view/operations/rfind/wchar_t/3.cc
new file mode 100644
index 000000000000..ad34cd3df7cf
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/rfind/wchar_t/3.cc
@@ -0,0 +1,66 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// basic_string_view::find_last_not_of
+
+void
+test03()
+{
+ typedef std::wstring_view::size_type csize_type;
+ std::wstring_view::size_type pos;
+ csize_type npos = std::wstring_view::npos;
+
+ std::wstring_view x;
+ pos = x.find_last_not_of(L'X');
+ VERIFY( pos == npos );
+ pos = x.find_last_not_of(L"XYZ");
+ VERIFY( pos == npos );
+
+ std::wstring_view y(L"a");
+ pos = y.find_last_not_of(L'X');
+ VERIFY( pos == 0 );
+ pos = y.find_last_not_of(L'a');
+ VERIFY( pos == npos );
+ pos = y.find_last_not_of(L"XYZ");
+ VERIFY( pos == 0 );
+ pos = y.find_last_not_of(L"a");
+ VERIFY( pos == npos );
+
+ std::wstring_view z(L"ab");
+ pos = z.find_last_not_of(L'X');
+ VERIFY( pos == 1 );
+ pos = z.find_last_not_of(L"XYZ");
+ VERIFY( pos == 1 );
+ pos = z.find_last_not_of(L'b');
+ VERIFY( pos == 0 );
+ pos = z.find_last_not_of(L"Xb");
+ VERIFY( pos == 0 );
+ pos = z.find_last_not_of(L"Xa");
+ VERIFY( pos == 1 );
+}
+int
+main()
+{
+ test03();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/string_conversion/1.cc b/gdb/unittests/basic_string_view/operations/string_conversion/1.cc
new file mode 100644
index 000000000000..c6bfa0b79fe2
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/string_conversion/1.cc
@@ -0,0 +1,51 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2014-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::to_string
+
+#include <string_view>
+#include <string>
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+void
+test01()
+{
+ const char str_lit[] = "123456789A";
+ const std::string_view sv(str_lit);
+ char buffer[4] = { 0 };
+
+ std::string s1{sv};
+ VERIFY( s1 == str_lit );
+ using test_alloc = __gnu_test::tracker_allocator<char>;
+ std::basic_string<char, std::char_traits<char>, test_alloc>
+ s2{sv, test_alloc{}};
+ static_assert( std::is_same<decltype(s2)::allocator_type, test_alloc>::value,
+ "to_string() uses custom allocator" );
+ VERIFY( std::equal(s1.begin(), s1.end(), s2.begin(), s2.end()) );
+ auto s3 = static_cast<std::string>(sv);
+ VERIFY( s3 == s1 );
+}
+
+int
+main()
+{
+ test01();
+}
diff --git a/gdb/unittests/basic_string_view/operations/substr/char/1.cc b/gdb/unittests/basic_string_view/operations/substr/char/1.cc
new file mode 100644
index 000000000000..ac65c23c54be
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/substr/char/1.cc
@@ -0,0 +1,79 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::substr
+
+#include <string_view>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::string_view::size_type csize_type;
+ typedef std::string_view::const_reference cref;
+ typedef std::string_view::reference ref;
+ csize_type csz01;
+
+ const char str_lit01[] = "rockaway, pacifica";
+ const std::string_view str01(str_lit01);
+ std::string_view str02;
+
+ // basic_string_view<charT, _Traits, _Alloc>
+ // substr(size_type pos = 0, size_type n = npos) const;
+ csz01 = str01.size();
+ str02 = str01.substr(0, 1);
+ VERIFY( str02 == "r" );
+ str02 = str01.substr(10);
+ VERIFY( str02 == "pacifica" );
+
+ try
+ {
+ str02 = str01.substr(csz01 + 1);
+ VERIFY( false );
+ }
+ catch(std::out_of_range& fail)
+ {
+ VERIFY( true );
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+
+ try
+ {
+ str02 = str01.substr(csz01);
+ VERIFY( str02.size() == 0 );
+ VERIFY( str02.begin() == str01.end() );
+ VERIFY( true );
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operations/substr/wchar_t/1.cc b/gdb/unittests/basic_string_view/operations/substr/wchar_t/1.cc
new file mode 100644
index 000000000000..eb19ece2e79a
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operations/substr/wchar_t/1.cc
@@ -0,0 +1,79 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view::substr
+
+#include <string_view>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ typedef std::wstring_view::size_type csize_type;
+ typedef std::wstring_view::const_reference cref;
+ typedef std::wstring_view::reference ref;
+ csize_type csz01;
+
+ const wchar_t str_lit01[] = L"rockaway, pacifica";
+ const std::wstring_view str01(str_lit01);
+ std::wstring_view str02;
+
+ // basic_string_view<charT, _Traits, _Alloc>
+ // substr(size_type pos = 0, size_type n = npos) const;
+ csz01 = str01.size();
+ str02 = str01.substr(0, 1);
+ VERIFY( str02 == L"r" );
+ str02 = str01.substr(10);
+ VERIFY( str02 == L"pacifica" );
+
+ try
+ {
+ str02 = str01.substr(csz01 + 1);
+ VERIFY( false );
+ }
+ catch(std::out_of_range& fail)
+ {
+ VERIFY( true );
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+
+ try
+ {
+ str02 = str01.substr(csz01);
+ VERIFY( str02.size() == 0 );
+ VERIFY( str02.begin() == str01.end() );
+ VERIFY( true );
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+}
+
+int
+main()
+{
+ test01();
+
+ return 0;
+}
diff --git a/gdb/unittests/basic_string_view/operators/char/2.cc b/gdb/unittests/basic_string_view/operators/char/2.cc
new file mode 100644
index 000000000000..4be652daafb2
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operators/char/2.cc
@@ -0,0 +1,367 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string non-member functions
+
+// operator==
+/*
+template<class charT, class traits, class Allocator>
+ bool operator==(const basic_string<charT,traits,Allocator>& lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator==(const charT* lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator==(const basic_string<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+*/
+
+// operator!=
+/*
+template<class charT, class traits, class Allocator>
+ bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator!=(const charT* lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+*/
+
+// operator<
+/*
+template<class charT, class traits, class Allocator>
+ bool operator< (const basic_string<charT,traits,Allocator>& lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator< (const basic_string<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator< (const charT* lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+*/
+
+// operator>
+/*
+template<class charT, class traits, class Allocator>
+ bool operator> (const basic_string<charT,traits,Allocator>& lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator> (const basic_string<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator> (const charT* lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+*/
+
+// operator<=
+/*
+template<class charT, class traits, class Allocator>
+ bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator<=(const charT* lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+*/
+
+// operator>=
+/*
+template<class charT, class traits, class Allocator>
+ bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator>=(const charT* lhs,
+ const basic_string<charT,traits,Allocator>& rhs);
+*/
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::string_view str_0("costa rica");
+ std::string_view str_1("costa marbella");
+ std::string_view str_2("cost");
+ std::string_view str_3("costa ricans");
+ std::string_view str_4;
+
+ str_4 = str_0;
+ //comparisons between string objects
+ VERIFY( !(str_0 == str_1) );
+ VERIFY( !(str_0 == str_2) );
+ VERIFY( !(str_0 == str_3) );
+ VERIFY( !(str_1 == str_0) );
+ VERIFY( !(str_2 == str_0) );
+ VERIFY( !(str_3 == str_0) );
+ VERIFY( str_4 == str_0 );
+ VERIFY( str_0 == str_4 );
+
+ VERIFY( str_0 != str_1 );
+ VERIFY( str_0 != str_2 );
+ VERIFY( str_0 != str_3 );
+ VERIFY( str_1 != str_0 );
+ VERIFY( str_2 != str_0 );
+ VERIFY( str_3 != str_0 );
+ VERIFY( !(str_0 != str_4) );
+ VERIFY( !(str_4 != str_0) );
+
+ VERIFY( str_0 > str_1 ); //true cuz r>m
+ VERIFY( str_0 > str_2 );
+ VERIFY( !(str_0 > str_3) );
+ VERIFY( !(str_1 > str_0) ); //false cuz m<r
+ VERIFY( !(str_2 > str_0) );
+ VERIFY( str_3 > str_0 );
+ VERIFY( !(str_0 > str_4) );
+ VERIFY( !(str_4 > str_0) );
+
+ VERIFY( !(str_0 < str_1) ); //false cuz r>m
+ VERIFY( !(str_0 < str_2) );
+ VERIFY( str_0 < str_3 );
+ VERIFY( str_1 < str_0 ); //true cuz m<r
+ VERIFY( str_2 < str_0 );
+ VERIFY( !(str_3 < str_0) );
+ VERIFY( !(str_0 < str_4) );
+ VERIFY( !(str_4 < str_0) );
+
+ VERIFY( str_0 >= str_1 ); //true cuz r>m
+ VERIFY( str_0 >= str_2 );
+ VERIFY( !(str_0 >= str_3) );
+ VERIFY( !(str_1 >= str_0) );//false cuz m<r
+ VERIFY( !(str_2 >= str_0) );
+ VERIFY( str_3 >= str_0 );
+ VERIFY( str_0 >= str_4 );
+ VERIFY( str_4 >= str_0 );
+
+ VERIFY( !(str_0 <= str_1) );//false cuz r>m
+ VERIFY( !(str_0 <= str_2) );
+ VERIFY( str_0 <= str_3 );
+ VERIFY( str_1 <= str_0 );//true cuz m<r
+ VERIFY( str_2 <= str_0 );
+ VERIFY( !(str_3 <= str_0) );
+ VERIFY( str_0 <= str_4 );
+ VERIFY( str_4 <= str_0 );
+
+ //comparisons between string object and string literal
+ VERIFY( !(str_0 == "costa marbella") );
+ VERIFY( !(str_0 == "cost") );
+ VERIFY( !(str_0 == "costa ricans") );
+ VERIFY( !("costa marbella" == str_0) );
+ VERIFY( !("cost" == str_0) );
+ VERIFY( !("costa ricans" == str_0) );
+ VERIFY( "costa rica" == str_0 );
+ VERIFY( str_0 == "costa rica" );
+
+ VERIFY( str_0 != "costa marbella" );
+ VERIFY( str_0 != "cost" );
+ VERIFY( str_0 != "costa ricans" );
+ VERIFY( "costa marbella" != str_0 );
+ VERIFY( "cost" != str_0 );
+ VERIFY( "costa ricans" != str_0 );
+ VERIFY( !("costa rica" != str_0) );
+ VERIFY( !(str_0 != "costa rica") );
+
+ VERIFY( str_0 > "costa marbella" ); //true cuz r>m
+ VERIFY( str_0 > "cost" );
+ VERIFY( !(str_0 > "costa ricans") );
+ VERIFY( !("costa marbella" > str_0) );//false cuz m<r
+ VERIFY( !("cost" > str_0) );
+ VERIFY( "costa ricans" > str_0 );
+ VERIFY( !("costa rica" > str_0) );
+ VERIFY( !(str_0 > "costa rica") );
+
+ VERIFY( !(str_0 < "costa marbella") );//false cuz r>m
+ VERIFY( !(str_0 < "cost") );
+ VERIFY( str_0 < "costa ricans" );
+ VERIFY( "costa marbella" < str_0 );//true cuz m<r
+ VERIFY( "cost" < str_0 );
+ VERIFY( !("costa ricans" < str_0) );
+ VERIFY( !("costa rica" < str_0) );
+ VERIFY( !(str_0 < "costa rica") );
+
+ VERIFY( str_0 >= "costa marbella" );//true cuz r>m
+ VERIFY( str_0 >= "cost" );
+ VERIFY( !(str_0 >= "costa ricans") );
+ VERIFY( !("costa marbella" >= str_0) );//false cuz m<r
+ VERIFY( !("cost" >= str_0) );
+ VERIFY( "costa ricans" >= str_0 );
+ VERIFY( "costa rica" >= str_0 );
+ VERIFY( str_0 >= "costa rica" );
+
+ VERIFY( !(str_0 <= "costa marbella") );//false cuz r>m
+ VERIFY( !(str_0 <= "cost") );
+ VERIFY( str_0 <= "costa ricans" );
+ VERIFY( "costa marbella" <= str_0 );//true cuz m<r
+ VERIFY( "cost" <= str_0 );
+ VERIFY( !("costa ricans" <= str_0) );
+ VERIFY( "costa rica" <= str_0 );
+ VERIFY( str_0 <= "costa rica" );
+}
+
+constexpr bool
+test02()
+{
+ std::string_view str_0("costa rica");
+ std::string_view str_1("costa marbella");
+ std::string_view str_2("cost");
+ std::string_view str_3("costa ricans");
+ std::string_view str_4;
+
+#undef VERIFY
+#define VERIFY(x) if (!(x)) return false
+
+ str_4 = str_0;
+ //comparisons between string objects
+ VERIFY( !(str_0 == str_1) );
+ VERIFY( !(str_0 == str_2) );
+ VERIFY( !(str_0 == str_3) );
+ VERIFY( !(str_1 == str_0) );
+ VERIFY( !(str_2 == str_0) );
+ VERIFY( !(str_3 == str_0) );
+ VERIFY( str_4 == str_0 );
+ VERIFY( str_0 == str_4 );
+
+ VERIFY( str_0 != str_1 );
+ VERIFY( str_0 != str_2 );
+ VERIFY( str_0 != str_3 );
+ VERIFY( str_1 != str_0 );
+ VERIFY( str_2 != str_0 );
+ VERIFY( str_3 != str_0 );
+ VERIFY( !(str_0 != str_4) );
+ VERIFY( !(str_4 != str_0) );
+
+ VERIFY( str_0 > str_1 ); //true cuz r>m
+ VERIFY( str_0 > str_2 );
+ VERIFY( !(str_0 > str_3) );
+ VERIFY( !(str_1 > str_0) ); //false cuz m<r
+ VERIFY( !(str_2 > str_0) );
+ VERIFY( str_3 > str_0 );
+ VERIFY( !(str_0 > str_4) );
+ VERIFY( !(str_4 > str_0) );
+
+ VERIFY( !(str_0 < str_1) ); //false cuz r>m
+ VERIFY( !(str_0 < str_2) );
+ VERIFY( str_0 < str_3 );
+ VERIFY( str_1 < str_0 ); //true cuz m<r
+ VERIFY( str_2 < str_0 );
+ VERIFY( !(str_3 < str_0) );
+ VERIFY( !(str_0 < str_4) );
+ VERIFY( !(str_4 < str_0) );
+
+ VERIFY( str_0 >= str_1 ); //true cuz r>m
+ VERIFY( str_0 >= str_2 );
+ VERIFY( !(str_0 >= str_3) );
+ VERIFY( !(str_1 >= str_0) );//false cuz m<r
+ VERIFY( !(str_2 >= str_0) );
+ VERIFY( str_3 >= str_0 );
+ VERIFY( str_0 >= str_4 );
+ VERIFY( str_4 >= str_0 );
+
+ VERIFY( !(str_0 <= str_1) );//false cuz r>m
+ VERIFY( !(str_0 <= str_2) );
+ VERIFY( str_0 <= str_3 );
+ VERIFY( str_1 <= str_0 );//true cuz m<r
+ VERIFY( str_2 <= str_0 );
+ VERIFY( !(str_3 <= str_0) );
+ VERIFY( str_0 <= str_4 );
+ VERIFY( str_4 <= str_0 );
+
+ //comparisons between string object and string literal
+ VERIFY( !(str_0 == "costa marbella") );
+ VERIFY( !(str_0 == "cost") );
+ VERIFY( !(str_0 == "costa ricans") );
+ VERIFY( !("costa marbella" == str_0) );
+ VERIFY( !("cost" == str_0) );
+ VERIFY( !("costa ricans" == str_0) );
+ VERIFY( "costa rica" == str_0 );
+ VERIFY( str_0 == "costa rica" );
+
+ VERIFY( str_0 != "costa marbella" );
+ VERIFY( str_0 != "cost" );
+ VERIFY( str_0 != "costa ricans" );
+ VERIFY( "costa marbella" != str_0 );
+ VERIFY( "cost" != str_0 );
+ VERIFY( "costa ricans" != str_0 );
+ VERIFY( !("costa rica" != str_0) );
+ VERIFY( !(str_0 != "costa rica") );
+
+ VERIFY( str_0 > "costa marbella" ); //true cuz r>m
+ VERIFY( str_0 > "cost" );
+ VERIFY( !(str_0 > "costa ricans") );
+ VERIFY( !("costa marbella" > str_0) );//false cuz m<r
+ VERIFY( !("cost" > str_0) );
+ VERIFY( "costa ricans" > str_0 );
+ VERIFY( !("costa rica" > str_0) );
+ VERIFY( !(str_0 > "costa rica") );
+
+ VERIFY( !(str_0 < "costa marbella") );//false cuz r>m
+ VERIFY( !(str_0 < "cost") );
+ VERIFY( str_0 < "costa ricans" );
+ VERIFY( "costa marbella" < str_0 );//true cuz m<r
+ VERIFY( "cost" < str_0 );
+ VERIFY( !("costa ricans" < str_0) );
+ VERIFY( !("costa rica" < str_0) );
+ VERIFY( !(str_0 < "costa rica") );
+
+ VERIFY( str_0 >= "costa marbella" );//true cuz r>m
+ VERIFY( str_0 >= "cost" );
+ VERIFY( !(str_0 >= "costa ricans") );
+ VERIFY( !("costa marbella" >= str_0) );//false cuz m<r
+ VERIFY( !("cost" >= str_0) );
+ VERIFY( "costa ricans" >= str_0 );
+ VERIFY( "costa rica" >= str_0 );
+ VERIFY( str_0 >= "costa rica" );
+
+ VERIFY( !(str_0 <= "costa marbella") );//false cuz r>m
+ VERIFY( !(str_0 <= "cost") );
+ VERIFY( str_0 <= "costa ricans" );
+ VERIFY( "costa marbella" <= str_0 );//true cuz m<r
+ VERIFY( "cost" <= str_0 );
+ VERIFY( !("costa ricans" <= str_0) );
+ VERIFY( "costa rica" <= str_0 );
+ VERIFY( str_0 <= "costa rica" );
+
+ return true;
+}
+
+int
+main()
+{
+ test01();
+ static_assert( test02() );
+}
diff --git a/gdb/unittests/basic_string_view/operators/wchar_t/2.cc b/gdb/unittests/basic_string_view/operators/wchar_t/2.cc
new file mode 100644
index 000000000000..f4088c85b0b1
--- /dev/null
+++ b/gdb/unittests/basic_string_view/operators/wchar_t/2.cc
@@ -0,0 +1,367 @@
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// basic_string_view non-member functions
+
+// operator==
+/*
+template<class charT, class traits, class Allocator>
+ bool operator==(const basic_string_view<charT,traits,Allocator>& lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator==(const charT* lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator==(const basic_string_view<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+*/
+
+// operator!=
+/*
+template<class charT, class traits, class Allocator>
+ bool operator!=(const basic_string_view<charT,traits,Allocator>& lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator!=(const charT* lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator!=(const basic_string_view<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+*/
+
+// operator<
+/*
+template<class charT, class traits, class Allocator>
+ bool operator< (const basic_string_view<charT,traits,Allocator>& lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator< (const basic_string_view<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator< (const charT* lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+*/
+
+// operator>
+/*
+template<class charT, class traits, class Allocator>
+ bool operator> (const basic_string_view<charT,traits,Allocator>& lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator> (const basic_string_view<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator> (const charT* lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+*/
+
+// operator<=
+/*
+template<class charT, class traits, class Allocator>
+ bool operator<=(const basic_string_view<charT,traits,Allocator>& lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator<=(const basic_string_view<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator<=(const charT* lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+*/
+
+// operator>=
+/*
+template<class charT, class traits, class Allocator>
+ bool operator>=(const basic_string_view<charT,traits,Allocator>& lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator>=(const basic_string_view<charT,traits,Allocator>& lhs,
+ const charT* rhs);
+
+template<class charT, class traits, class Allocator>
+ bool operator>=(const charT* lhs,
+ const basic_string_view<charT,traits,Allocator>& rhs);
+*/
+
+#include <string_view>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ std::wstring_view str_0(L"costa rica");
+ std::wstring_view str_1(L"costa marbella");
+ std::wstring_view str_2(L"cost");
+ std::wstring_view str_3(L"costa ricans");
+ std::wstring_view str_4;
+
+ str_4 = str_0;
+ //comparisons between string_view objects
+ VERIFY( !(str_0 == str_1) );
+ VERIFY( !(str_0 == str_2) );
+ VERIFY( !(str_0 == str_3) );
+ VERIFY( !(str_1 == str_0) );
+ VERIFY( !(str_2 == str_0) );
+ VERIFY( !(str_3 == str_0) );
+ VERIFY( str_4 == str_0 );
+ VERIFY( str_0 == str_4 );
+
+ VERIFY( str_0 != str_1 );
+ VERIFY( str_0 != str_2 );
+ VERIFY( str_0 != str_3 );
+ VERIFY( str_1 != str_0 );
+ VERIFY( str_2 != str_0 );
+ VERIFY( str_3 != str_0 );
+ VERIFY( !(str_0 != str_4) );
+ VERIFY( !(str_4 != str_0) );
+
+ VERIFY( str_0 > str_1 ); //true cuz r>m
+ VERIFY( str_0 > str_2 );
+ VERIFY( !(str_0 > str_3) );
+ VERIFY( !(str_1 > str_0) ); //false cuz m<r
+ VERIFY( !(str_2 > str_0) );
+ VERIFY( str_3 > str_0 );
+ VERIFY( !(str_0 > str_4) );
+ VERIFY( !(str_4 > str_0) );
+
+ VERIFY( !(str_0 < str_1) ); //false cuz r>m
+ VERIFY( !(str_0 < str_2) );
+ VERIFY( str_0 < str_3 );
+ VERIFY( str_1 < str_0 ); //true cuz m<r
+ VERIFY( str_2 < str_0 );
+ VERIFY( !(str_3 < str_0) );
+ VERIFY( !(str_0 < str_4) );
+ VERIFY( !(str_4 < str_0) );
+
+ VERIFY( str_0 >= str_1 ); //true cuz r>m
+ VERIFY( str_0 >= str_2 );
+ VERIFY( !(str_0 >= str_3) );
+ VERIFY( !(str_1 >= str_0) );//false cuz m<r
+ VERIFY( !(str_2 >= str_0) );
+ VERIFY( str_3 >= str_0 );
+ VERIFY( str_0 >= str_4 );
+ VERIFY( str_4 >= str_0 );
+
+ VERIFY( !(str_0 <= str_1) );//false cuz r>m
+ VERIFY( !(str_0 <= str_2) );
+ VERIFY( str_0 <= str_3 );
+ VERIFY( str_1 <= str_0 );//true cuz m<r
+ VERIFY( str_2 <= str_0 );
+ VERIFY( !(str_3 <= str_0) );
+ VERIFY( str_0 <= str_4 );
+ VERIFY( str_4 <= str_0 );
+
+ //comparisons between string_view object and string_view literal
+ VERIFY( !(str_0 == L"costa marbella") );
+ VERIFY( !(str_0 == L"cost") );
+ VERIFY( !(str_0 == L"costa ricans") );
+ VERIFY( !(L"costa marbella" == str_0) );
+ VERIFY( !(L"cost" == str_0) );
+ VERIFY( !(L"costa ricans" == str_0) );
+ VERIFY( L"costa rica" == str_0 );
+ VERIFY( str_0 == L"costa rica" );
+
+ VERIFY( str_0 != L"costa marbella" );
+ VERIFY( str_0 != L"cost" );
+ VERIFY( str_0 != L"costa ricans" );
+ VERIFY( L"costa marbella" != str_0 );
+ VERIFY( L"cost" != str_0 );
+ VERIFY( L"costa ricans" != str_0 );
+ VERIFY( !(L"costa rica" != str_0) );
+ VERIFY( !(str_0 != L"costa rica") );
+
+ VERIFY( str_0 > L"costa marbella" ); //true cuz r>m
+ VERIFY( str_0 > L"cost" );
+ VERIFY( !(str_0 > L"costa ricans") );
+ VERIFY( !(L"costa marbella" > str_0) );//false cuz m<r
+ VERIFY( !(L"cost" > str_0) );
+ VERIFY( L"costa ricans" > str_0 );
+ VERIFY( !(L"costa rica" > str_0) );
+ VERIFY( !(str_0 > L"costa rica") );
+
+ VERIFY( !(str_0 < L"costa marbella") );//false cuz r>m
+ VERIFY( !(str_0 < L"cost") );
+ VERIFY( str_0 < L"costa ricans" );
+ VERIFY( L"costa marbella" < str_0 );//true cuz m<r
+ VERIFY( L"cost" < str_0 );
+ VERIFY( !(L"costa ricans" < str_0) );
+ VERIFY( !(L"costa rica" < str_0) );
+ VERIFY( !(str_0 < L"costa rica") );
+
+ VERIFY( str_0 >= L"costa marbella" );//true cuz r>m
+ VERIFY( str_0 >= L"cost" );
+ VERIFY( !(str_0 >= L"costa ricans") );
+ VERIFY( !(L"costa marbella" >= str_0) );//false cuz m<r
+ VERIFY( !(L"cost" >= str_0) );
+ VERIFY( L"costa ricans" >= str_0 );
+ VERIFY( L"costa rica" >= str_0 );
+ VERIFY( str_0 >= L"costa rica" );
+
+ VERIFY( !(str_0 <= L"costa marbella") );//false cuz r>m
+ VERIFY( !(str_0 <= L"cost") );
+ VERIFY( str_0 <= L"costa ricans" );
+ VERIFY( L"costa marbella" <= str_0 );//true cuz m<r
+ VERIFY( L"cost" <= str_0 );
+ VERIFY( !(L"costa ricans" <= str_0) );
+ VERIFY( L"costa rica" <= str_0 );
+ VERIFY( str_0 <= L"costa rica" );
+}
+
+constexpr bool
+test02()
+{
+ std::wstring_view str_0(L"costa rica");
+ std::wstring_view str_1(L"costa marbella");
+ std::wstring_view str_2(L"cost");
+ std::wstring_view str_3(L"costa ricans");
+ std::wstring_view str_4;
+
+#undef VERIFY
+#define VERIFY(x) if (!(x)) return false
+
+ str_4 = str_0;
+ //comparisons between string_view objects
+ VERIFY( !(str_0 == str_1) );
+ VERIFY( !(str_0 == str_2) );
+ VERIFY( !(str_0 == str_3) );
+ VERIFY( !(str_1 == str_0) );
+ VERIFY( !(str_2 == str_0) );
+ VERIFY( !(str_3 == str_0) );
+ VERIFY( str_4 == str_0 );
+ VERIFY( str_0 == str_4 );
+
+ VERIFY( str_0 != str_1 );
+ VERIFY( str_0 != str_2 );
+ VERIFY( str_0 != str_3 );
+ VERIFY( str_1 != str_0 );
+ VERIFY( str_2 != str_0 );
+ VERIFY( str_3 != str_0 );
+ VERIFY( !(str_0 != str_4) );
+ VERIFY( !(str_4 != str_0) );
+
+ VERIFY( str_0 > str_1 ); //true cuz r>m
+ VERIFY( str_0 > str_2 );
+ VERIFY( !(str_0 > str_3) );
+ VERIFY( !(str_1 > str_0) ); //false cuz m<r
+ VERIFY( !(str_2 > str_0) );
+ VERIFY( str_3 > str_0 );
+ VERIFY( !(str_0 > str_4) );
+ VERIFY( !(str_4 > str_0) );
+
+ VERIFY( !(str_0 < str_1) ); //false cuz r>m
+ VERIFY( !(str_0 < str_2) );
+ VERIFY( str_0 < str_3 );
+ VERIFY( str_1 < str_0 ); //true cuz m<r
+ VERIFY( str_2 < str_0 );
+ VERIFY( !(str_3 < str_0) );
+ VERIFY( !(str_0 < str_4) );
+ VERIFY( !(str_4 < str_0) );
+
+ VERIFY( str_0 >= str_1 ); //true cuz r>m
+ VERIFY( str_0 >= str_2 );
+ VERIFY( !(str_0 >= str_3) );
+ VERIFY( !(str_1 >= str_0) );//false cuz m<r
+ VERIFY( !(str_2 >= str_0) );
+ VERIFY( str_3 >= str_0 );
+ VERIFY( str_0 >= str_4 );
+ VERIFY( str_4 >= str_0 );
+
+ VERIFY( !(str_0 <= str_1) );//false cuz r>m
+ VERIFY( !(str_0 <= str_2) );
+ VERIFY( str_0 <= str_3 );
+ VERIFY( str_1 <= str_0 );//true cuz m<r
+ VERIFY( str_2 <= str_0 );
+ VERIFY( !(str_3 <= str_0) );
+ VERIFY( str_0 <= str_4 );
+ VERIFY( str_4 <= str_0 );
+
+ //comparisons between string_view object and string_view literal
+ VERIFY( !(str_0 == L"costa marbella") );
+ VERIFY( !(str_0 == L"cost") );
+ VERIFY( !(str_0 == L"costa ricans") );
+ VERIFY( !(L"costa marbella" == str_0) );
+ VERIFY( !(L"cost" == str_0) );
+ VERIFY( !(L"costa ricans" == str_0) );
+ VERIFY( L"costa rica" == str_0 );
+ VERIFY( str_0 == L"costa rica" );
+
+ VERIFY( str_0 != L"costa marbella" );
+ VERIFY( str_0 != L"cost" );
+ VERIFY( str_0 != L"costa ricans" );
+ VERIFY( L"costa marbella" != str_0 );
+ VERIFY( L"cost" != str_0 );
+ VERIFY( L"costa ricans" != str_0 );
+ VERIFY( !(L"costa rica" != str_0) );
+ VERIFY( !(str_0 != L"costa rica") );
+
+ VERIFY( str_0 > L"costa marbella" ); //true cuz r>m
+ VERIFY( str_0 > L"cost" );
+ VERIFY( !(str_0 > L"costa ricans") );
+ VERIFY( !(L"costa marbella" > str_0) );//false cuz m<r
+ VERIFY( !(L"cost" > str_0) );
+ VERIFY( L"costa ricans" > str_0 );
+ VERIFY( !(L"costa rica" > str_0) );
+ VERIFY( !(str_0 > L"costa rica") );
+
+ VERIFY( !(str_0 < L"costa marbella") );//false cuz r>m
+ VERIFY( !(str_0 < L"cost") );
+ VERIFY( str_0 < L"costa ricans" );
+ VERIFY( L"costa marbella" < str_0 );//true cuz m<r
+ VERIFY( L"cost" < str_0 );
+ VERIFY( !(L"costa ricans" < str_0) );
+ VERIFY( !(L"costa rica" < str_0) );
+ VERIFY( !(str_0 < L"costa rica") );
+
+ VERIFY( str_0 >= L"costa marbella" );//true cuz r>m
+ VERIFY( str_0 >= L"cost" );
+ VERIFY( !(str_0 >= L"costa ricans") );
+ VERIFY( !(L"costa marbella" >= str_0) );//false cuz m<r
+ VERIFY( !(L"cost" >= str_0) );
+ VERIFY( L"costa ricans" >= str_0 );
+ VERIFY( L"costa rica" >= str_0 );
+ VERIFY( str_0 >= L"costa rica" );
+
+ VERIFY( !(str_0 <= L"costa marbella") );//false cuz r>m
+ VERIFY( !(str_0 <= L"cost") );
+ VERIFY( str_0 <= L"costa ricans" );
+ VERIFY( L"costa marbella" <= str_0 );//true cuz m<r
+ VERIFY( L"cost" <= str_0 );
+ VERIFY( !(L"costa ricans" <= str_0) );
+ VERIFY( L"costa rica" <= str_0 );
+ VERIFY( str_0 <= L"costa rica" );
+
+ return true;
+}
+
+int
+main()
+{
+ test01();
+ static_assert( test02() );
+}
diff --git a/gdb/unittests/basic_string_view/range_access/char/1.cc b/gdb/unittests/basic_string_view/range_access/char/1.cc
new file mode 100644
index 000000000000..162ddeec24e3
--- /dev/null
+++ b/gdb/unittests/basic_string_view/range_access/char/1.cc
@@ -0,0 +1,47 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// C++17 27.7, range access [iterator.range]
+
+#include <string_view>
+
+void
+test01()
+{
+ std::string_view s("Hello, World!");
+ std::begin(s);
+ std::end(s);
+ std::rbegin(s);
+ std::rend(s);
+}
+
+void
+test02()
+{
+ constexpr std::string_view s("Hello, World!");
+ [[maybe_unused]] constexpr auto b = std::begin(s);
+ [[maybe_unused]] constexpr auto e = std::end(s);
+ [[maybe_unused]] constexpr auto cb = std::cbegin(s);
+ [[maybe_unused]] constexpr auto ce = std::cend(s);
+ [[maybe_unused]] constexpr auto rb = std::rbegin(s);
+ [[maybe_unused]] constexpr auto re = std::rend(s);
+ [[maybe_unused]] constexpr auto crb = std::crbegin(s);
+ [[maybe_unused]] constexpr auto cre = std::crend(s);
+}
diff --git a/gdb/unittests/basic_string_view/range_access/wchar_t/1.cc b/gdb/unittests/basic_string_view/range_access/wchar_t/1.cc
new file mode 100644
index 000000000000..6584d253fea8
--- /dev/null
+++ b/gdb/unittests/basic_string_view/range_access/wchar_t/1.cc
@@ -0,0 +1,47 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// C++17 27.7, range access [iterator.range]
+
+#include <string_view>
+
+void
+test01()
+{
+ std::wstring_view ws(L"Hello, World!");
+ std::begin(ws);
+ std::end(ws);
+ std::rbegin(ws);
+ std::rend(ws);
+}
+
+void
+test02()
+{
+ constexpr std::wstring_view ws(L"Hello, World!");
+ [[maybe_unused]] constexpr auto b = std::begin(ws);
+ [[maybe_unused]] constexpr auto e = std::end(ws);
+ [[maybe_unused]] constexpr auto cb = std::cbegin(ws);
+ [[maybe_unused]] constexpr auto ce = std::cend(ws);
+ [[maybe_unused]] constexpr auto rb = std::rbegin(ws);
+ [[maybe_unused]] constexpr auto re = std::rend(ws);
+ [[maybe_unused]] constexpr auto crb = std::crbegin(ws);
+ [[maybe_unused]] constexpr auto cre = std::crend(ws);
+}
diff --git a/gdb/unittests/basic_string_view/requirements/explicit_instantiation/1.cc b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/1.cc
new file mode 100644
index 000000000000..a29d6beb7d2a
--- /dev/null
+++ b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/1.cc
@@ -0,0 +1,26 @@
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+// This file tests explicit instantiation of basic_string
+
+#include <string_view>
+
+// { dg-do compile }
+// { dg-options "-std=gnu++17" }
+
+template class std::basic_string_view<int, std::char_traits<int>>;
diff --git a/gdb/unittests/basic_string_view/requirements/explicit_instantiation/char/1.cc b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/char/1.cc
new file mode 100644
index 000000000000..6f3fca9286d6
--- /dev/null
+++ b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/char/1.cc
@@ -0,0 +1,23 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+
+template class std::basic_string_view<char>;
diff --git a/gdb/unittests/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc
new file mode 100644
index 000000000000..46e8e15130d4
--- /dev/null
+++ b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/char16_t/1.cc
@@ -0,0 +1,24 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++17" }
+// { dg-require-cstdint "" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+
+template class std::basic_string_view<char16_t>;
diff --git a/gdb/unittests/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc
new file mode 100644
index 000000000000..031fd4c8ecf1
--- /dev/null
+++ b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/char32_t/1.cc
@@ -0,0 +1,24 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++17" }
+// { dg-require-cstdint "" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+
+template class std::basic_string_view<char32_t>;
diff --git a/gdb/unittests/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc
new file mode 100644
index 000000000000..8c9ef863a673
--- /dev/null
+++ b/gdb/unittests/basic_string_view/requirements/explicit_instantiation/wchar_t/1.cc
@@ -0,0 +1,23 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++17" }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+
+template class std::basic_string_view<wchar_t>;
diff --git a/gdb/unittests/basic_string_view/requirements/typedefs.cc b/gdb/unittests/basic_string_view/requirements/typedefs.cc
new file mode 100644
index 000000000000..bdbcfa10ce86
--- /dev/null
+++ b/gdb/unittests/basic_string_view/requirements/typedefs.cc
@@ -0,0 +1,47 @@
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+#include <testsuite_containers.h>
+
+namespace __gnu_test
+{
+ template<typename _Tp1, typename _Tp2>
+ struct traits<std::basic_string_view<_Tp1, _Tp2>> : public traits_base
+ {
+ typedef std::true_type is_container;
+ typedef std::true_type is_reversible;
+ };
+}
+
+#include <testsuite_containers.h>
+
+// Check container for required typedefs.
+
+__gnu_test::basic_types<std::string_view> t1b;
+__gnu_test::reversible_types<std::string_view> t1r;
+typedef typename std::string_view::traits_type traits_type1;
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+__gnu_test::basic_types<std::wstring_view> t2b;
+__gnu_test::reversible_types<std::wstring_view> t2r;
+typedef typename std::wstring_view::traits_type traits_type2;
+#endif
diff --git a/gdb/unittests/basic_string_view/typedefs.cc b/gdb/unittests/basic_string_view/typedefs.cc
new file mode 100644
index 000000000000..d1269db2b762
--- /dev/null
+++ b/gdb/unittests/basic_string_view/typedefs.cc
@@ -0,0 +1,36 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+// Copyright (C) 2014-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <string_view>
+
+template<typename C, typename T>
+ using check1_t = std::basic_string_view<C, T>;
+
+using check2_t = std::string_view;
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+using check3_t = std::u16string_view;
+using check4_t = std::u32string_view;
+#endif
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+using check5_t = std::wstring_view;
+#endif
+
diff --git a/gdb/unittests/basic_string_view/types/1.cc b/gdb/unittests/basic_string_view/types/1.cc
new file mode 100644
index 000000000000..3914053311f4
--- /dev/null
+++ b/gdb/unittests/basic_string_view/types/1.cc
@@ -0,0 +1,43 @@
+//
+// Copyright (C) 2013-2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+//
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile }
+
+#include <string_view>
+
+struct T
+{
+ typedef std::string_view String_view;
+ typedef String_view::iterator iterator;
+ typedef String_view::const_iterator const_iterator;
+
+ char t(iterator f) { return *f; }
+ char t(const_iterator f) const { return *f; }
+};
+
+void
+f()
+{
+ std::string_view s;
+ T t;
+ T::const_iterator i = s.begin();
+
+ t.t(i);
+}
--
2.16.3
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 3/5] Add gdb::string_view
2018-04-07 13:26 ` [PATCH v3 3/5] Add gdb::string_view Simon Marchi
@ 2018-04-09 13:44 ` Pedro Alves
2018-04-09 17:28 ` Simon Marchi
2018-04-09 18:28 ` Simon Marchi
0 siblings, 2 replies; 17+ messages in thread
From: Pedro Alves @ 2018-04-09 13:44 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 04/07/2018 02:26 PM, Simon Marchi wrote:
> New in v3:
>
> * Base on the implementation in experimental/, since it is easier to
> adapt to the c++ standard we follow (c++11). I didn't see any
> significant fix to import from the std/ version.
>
> * Tested against clang and clang+libc++ to make sure we don't rely on
> anything internal and specific to libstdc++. This caught a few
> issues.
>
> * Remove hash helpers, operator<<, operator ""sv.
We can always add hash support later, but I suspect it won't be
long until we will miss it, when we try to use string_view with
e.g., an std::unordered_map.
> * Make gdb::string_view an alias of std::string_view when building
> with >= c++17.
>
> * Remove a bunch of constexpr, because they are not valid in c++11
> (e.g. they are not a single return line).
I think I'd prefer to leave the "constexpr"'s in place, but commented out,
instead of just removing it, like '/*constexpr*/', as a clearer marker that
we've removed something that normally would otherwise be there, since for
a future reader, simply removing is indistinguishable with missing/forgetting
a constexpr.
> * Remove hash helpers, because they use libstdc++ internal functions.
> If we need them we always import them later.
Ah, hash helpers mentioned twice. :-)
Technically, the use of uglified (double-underscore or
underscore-followed-by-uppercase) names is undefined behavior for
being reserved to the implementation, but I think that in practice
it's harmless, we should be able to deal with any conflict if it
ever happens. At this stage, I think fewer local changes outweighs
the very small potential for trouble.
LGTM.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 2/5] Copy string_view files from libstdc++
2018-04-07 13:26 ` [PATCH v3 2/5] Copy string_view files from libstdc++ Simon Marchi
@ 2018-04-09 13:44 ` Pedro Alves
2018-04-09 17:23 ` Simon Marchi
0 siblings, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2018-04-09 13:44 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 04/07/2018 02:26 PM, Simon Marchi wrote:
> This patch copies the following files from libstdc++ (commit
> 02a4441f002c):
>
> ${gcc}/include/std/string_view -> ${binutils-gdb}/gdb/common/gdb_string_view.h
> ${gcc}/include/bits/string_view.tcc -> ${binutils-gdb}/gdb/common/gdb_string_view.tcc
Nit: the source filenames here should be updated. Maybe commit as well, if applicable.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 5/5] Adapt and integrate string_view tests
2018-04-07 13:26 ` [PATCH v3 5/5] Adapt and integrate string_view tests Simon Marchi
@ 2018-04-09 13:45 ` Pedro Alves
0 siblings, 0 replies; 17+ messages in thread
From: Pedro Alves @ 2018-04-09 13:45 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 04/07/2018 02:26 PM, Simon Marchi wrote:
> New in v3:
LGTM.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4
2018-04-07 13:26 [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Simon Marchi
` (3 preceding siblings ...)
2018-04-07 13:37 ` [PATCH v3 4/5] Copy string_view tests " Simon Marchi
@ 2018-04-09 13:46 ` Pedro Alves
2018-04-09 18:27 ` Simon Marchi
5 siblings, 0 replies; 17+ messages in thread
From: Pedro Alves @ 2018-04-09 13:46 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 04/07/2018 02:26 PM, Simon Marchi wrote:
> This file provides the AX_CXX_COMPILE_STDCXX macro. In the context of
> the following patch, I wanted to build and test GDB in c++17 mode. The
> version of the macro we have in the repo does not support detecting
> c++17 compilers, but the upstream version has been updated to do so.
>
> Since we have local modifications to the file, I had to reconcile our
> modifications and the updated upstream version (which was relatively
> straightforward).
OK.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 4/5] Copy string_view tests from libstdc++
2018-04-07 13:37 ` [PATCH v3 4/5] Copy string_view tests " Simon Marchi
@ 2018-04-09 13:47 ` Pedro Alves
0 siblings, 0 replies; 17+ messages in thread
From: Pedro Alves @ 2018-04-09 13:47 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 04/07/2018 02:26 PM, Simon Marchi wrote:
> This patch copies the string_view tests from the gcc repository (commit
> 02a4441f002c).
>
> ${gcc}/libstdc++-v3/testsuite/21_strings/basic_string_view ->
> ${binutils-gdb}/gdb/unittests/basic_string_view
>
> The local modifications are done in the following patch, so that it's
> easier to review them.
>
For completeness... :-) ... OK.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 2/5] Copy string_view files from libstdc++
2018-04-09 13:44 ` Pedro Alves
@ 2018-04-09 17:23 ` Simon Marchi
2018-04-09 17:39 ` Pedro Alves
0 siblings, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2018-04-09 17:23 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On 2018-04-09 09:44, Pedro Alves wrote:
> On 04/07/2018 02:26 PM, Simon Marchi wrote:
>
>> This patch copies the following files from libstdc++ (commit
>> 02a4441f002c):
>>
>> ${gcc}/include/std/string_view ->
>> ${binutils-gdb}/gdb/common/gdb_string_view.h
>> ${gcc}/include/bits/string_view.tcc ->
>> ${binutils-gdb}/gdb/common/gdb_string_view.tcc
>
> Nit: the source filenames here should be updated. Maybe commit as
> well, if applicable.
>
> Thanks,
> Pedro Alves
Oops, I'm missing "libstdc++-v3" in the source names. Is there anything
else wrong with the paths? What about the commit?
Simno
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 3/5] Add gdb::string_view
2018-04-09 13:44 ` Pedro Alves
@ 2018-04-09 17:28 ` Simon Marchi
2018-04-09 17:30 ` Simon Marchi
2018-04-09 18:28 ` Simon Marchi
1 sibling, 1 reply; 17+ messages in thread
From: Simon Marchi @ 2018-04-09 17:28 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On 2018-04-09 09:44, Pedro Alves wrote:
> On 04/07/2018 02:26 PM, Simon Marchi wrote:
>> New in v3:
>>
>> * Base on the implementation in experimental/, since it is easier to
>> adapt to the c++ standard we follow (c++11). I didn't see any
>> significant fix to import from the std/ version.
>>
>> * Tested against clang and clang+libc++ to make sure we don't rely
>> on
>> anything internal and specific to libstdc++. This caught a few
>> issues.
>>
>> * Remove hash helpers, operator<<, operator ""sv.
>
> We can always add hash support later, but I suspect it won't be
> long until we will miss it, when we try to use string_view with
> e.g., an std::unordered_map.
Ok. I'd still like to keep it out of this patch, as it will probably be
a bit involved.
>
>> * Make gdb::string_view an alias of std::string_view when building
>> with >= c++17.
>>
>> * Remove a bunch of constexpr, because they are not valid in c++11
>> (e.g. they are not a single return line).
>
> I think I'd prefer to leave the "constexpr"'s in place, but commented
> out,
> instead of just removing it, like '/*constexpr*/', as a clearer marker
> that
> we've removed something that normally would otherwise be there, since
> for
> a future reader, simply removing is indistinguishable with
> missing/forgetting
> a constexpr.
Done.
>> * Remove hash helpers, because they use libstdc++ internal
>> functions.
>> If we need them we always import them later.
>
> Ah, hash helpers mentioned twice. :-)
Woops.
> Technically, the use of uglified (double-underscore or
> underscore-followed-by-uppercase) names is undefined behavior for
> being reserved to the implementation, but I think that in practice
> it's harmless, we should be able to deal with any conflict if it
> ever happens. At this stage, I think fewer local changes outweighs
> the very small potential for trouble.
>
> LGTM.
Thanks!
Simon
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 3/5] Add gdb::string_view
2018-04-09 17:28 ` Simon Marchi
@ 2018-04-09 17:30 ` Simon Marchi
0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2018-04-09 17:30 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On 2018-04-09 13:28, Simon Marchi wrote:
>>> * Remove hash helpers, because they use libstdc++ internal
>>> functions.
>>> If we need them we always import them later.
>>
>> Ah, hash helpers mentioned twice. :-)
>
> Woops.
Ah, but the first mention was in the "New in v3" list, which shouldn't
end up in the committed patch.
Simon
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 2/5] Copy string_view files from libstdc++
2018-04-09 17:23 ` Simon Marchi
@ 2018-04-09 17:39 ` Pedro Alves
2018-04-09 18:20 ` Simon Marchi
0 siblings, 1 reply; 17+ messages in thread
From: Pedro Alves @ 2018-04-09 17:39 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
On 04/09/2018 06:23 PM, Simon Marchi wrote:
> On 2018-04-09 09:44, Pedro Alves wrote:
>> On 04/07/2018 02:26 PM, Simon Marchi wrote:
>>
>>> This patch copies the following files from libstdc++ (commit
>>> 02a4441f002c):
>>>
>>> Â ${gcc}/include/std/string_view -> ${binutils-gdb}/gdb/common/gdb_string_view.h
>>> Â ${gcc}/include/bits/string_view.tcc -> ${binutils-gdb}/gdb/common/gdb_string_view.tcc
>>
>> Nit: the source filenames here should be updated. Maybe commit as
>> well, if applicable.
>
> Oops, I'm missing "libstdc++-v3" in the source names. Is there anything else wrong with the paths? What about the commit?
That too, but I was actually thinking that the files in this revision were
copied from:
include/experimental/string_view
include/experimental/bits/string_view.tcc
instead?
The commit looks fine.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 2/5] Copy string_view files from libstdc++
2018-04-09 17:39 ` Pedro Alves
@ 2018-04-09 18:20 ` Simon Marchi
0 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2018-04-09 18:20 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On 2018-04-09 13:39, Pedro Alves wrote:
> On 04/09/2018 06:23 PM, Simon Marchi wrote:
>> On 2018-04-09 09:44, Pedro Alves wrote:
>>> On 04/07/2018 02:26 PM, Simon Marchi wrote:
>>>
>>>> This patch copies the following files from libstdc++ (commit
>>>> 02a4441f002c):
>>>>
>>>> Â ${gcc}/include/std/string_view ->
>>>> ${binutils-gdb}/gdb/common/gdb_string_view.h
>>>> Â ${gcc}/include/bits/string_view.tcc ->
>>>> ${binutils-gdb}/gdb/common/gdb_string_view.tcc
>>>
>>> Nit: the source filenames here should be updated. Maybe commit as
>>> well, if applicable.
>>
>> Oops, I'm missing "libstdc++-v3" in the source names. Is there
>> anything else wrong with the paths? What about the commit?
>
> That too, but I was actually thinking that the files in this revision
> were
> copied from:
>
> include/experimental/string_view
> include/experimental/bits/string_view.tcc
>
> instead?
Ahh of course, thanks. Fixed locally.
Simon
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4
2018-04-07 13:26 [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Simon Marchi
` (4 preceding siblings ...)
2018-04-09 13:46 ` [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Pedro Alves
@ 2018-04-09 18:27 ` Simon Marchi
5 siblings, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2018-04-09 18:27 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves
On 2018-04-07 09:26, Simon Marchi wrote:
> This file provides the AX_CXX_COMPILE_STDCXX macro. In the context of
> the following patch, I wanted to build and test GDB in c++17 mode. The
> version of the macro we have in the repo does not support detecting
> c++17 compilers, but the upstream version has been updated to do so.
>
> Since we have local modifications to the file, I had to reconcile our
> modifications and the updated upstream version (which was relatively
> straightforward).
I pushed this series, fixed with the small changes suggested by Pedro.
Simon
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v3 3/5] Add gdb::string_view
2018-04-09 13:44 ` Pedro Alves
2018-04-09 17:28 ` Simon Marchi
@ 2018-04-09 18:28 ` Simon Marchi
1 sibling, 0 replies; 17+ messages in thread
From: Simon Marchi @ 2018-04-09 18:28 UTC (permalink / raw)
To: Pedro Alves, Simon Marchi, gdb-patches
For completeness, here is what I pushed:
From 10907ddb20428acfe22964f9f9fb7855c6fca932 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@polymtl.ca>
Date: Mon, 9 Apr 2018 13:31:04 -0400
Subject: [PATCH] Add gdb::string_view
We had a few times the need for a data structure that does essentially
what C++17's std::string_view does, which is to give an std::string-like
interface (only the read-only operations) to an arbitrary character
buffer.
This patch adapts the files copied from libstdc++ by the previous patch
to integrate them with GDB. Here's a summary of the changes:
* Remove things related to wstring_view, u16string_view and
u32string_view (I don't think we need them, but we can always add them
later).
* Remove usages of _GLIBCXX_BEGIN_NAMESPACE_VERSION and
_GLIBCXX_END_NAMESPACE_VERSION.
* Put the code in the gdb namespace. I had to add a few "std::" in
front of std type usages.
* Change __throw_out_of_range_fmt() for error().
* Make gdb::string_view an alias of std::string_view when building
with >= c++17.
* Remove a bunch of constexpr, because they are not valid in c++11
(e.g. they are not a single return line).
* Use std::common_type<_Tp>::type instead of std::common_type_t<_Tp>,
because c++11 doesn't have the later.
* Remove the #pragma GCC system_header, since that silences some
warnings that we might want to have if we're doing something not
correctly.
* Remove operator ""sv. It would need a lot of work to make all
supported compilers happy, and we can easily live without it.
* Remove operator<<. It is implemented using __ostream_insert (a
libstdc++ internal). Bringing it in might be possible, but I don't
think that would be worth the effort, since we don't really use
streams at the moment.
* Replace internal libstdc++ asserts ( __glibcxx_assert and
__glibcxx_requires_string_len) with gdb_assert.
* Remove hash helpers, because they use libstdc++ internal functions.
If we need them we always import them later.
The string_view class in cli/cli-script.c is removed and its usage
replaced with the new gdb::string_view.
gdb/ChangeLog:
* common/gdb_string_view.h: Remove libstdc++ implementation
details, adjust to gdb reality.
* common/gdb_string_view.tcc: Likewise.
* cli/cli-script.c (struct string_view): Remove.
(user_args) <m_args>: Change element type to gdb::string_view.
(user_args::insert_args): Adjust.
---
gdb/ChangeLog | 9 ++
gdb/cli/cli-script.c | 17 +--
gdb/common/gdb_string_view.h | 298 ++++++++++++-----------------------------
gdb/common/gdb_string_view.tcc | 62 ++++-----
4 files changed, 126 insertions(+), 260 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 631f15a..462fc7d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@
2018-04-09 Simon Marchi <simon.marchi@polymtl.ca>
+ * common/gdb_string_view.h: Remove libstdc++ implementation
+ details, adjust to gdb reality.
+ * common/gdb_string_view.tcc: Likewise.
+ * cli/cli-script.c (struct string_view): Remove.
+ (user_args) <m_args>: Change element type to gdb::string_view.
+ (user_args::insert_args): Adjust.
+
+2018-04-09 Simon Marchi <simon.marchi@polymtl.ca>
+
* common/gdb_string_view.h: New file.
* common/gdb_string_view.tcc: New file.
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 366c422..cdfda11 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -32,6 +32,7 @@
#include "extension.h"
#include "interps.h"
#include "compile/compile.h"
+#include "common/gdb_string_view.h"
#include <vector>
@@ -54,18 +55,6 @@ static int command_nest_depth = 1;
/* This is to prevent certain commands being printed twice. */
static int suppress_next_print_command_trace = 0;
-/* A non-owning slice of a string. */
-
-struct string_view
-{
- string_view (const char *str_, size_t len_)
- : str (str_), len (len_)
- {}
-
- const char *str;
- size_t len;
-};
-
/* Structure for arguments to user defined functions. */
class user_args
@@ -91,7 +80,7 @@ private:
std::string m_command_line;
/* The arguments. Each element points inside M_COMMAND_LINE. */
- std::vector<string_view> m_args;
+ std::vector<gdb::string_view> m_args;
};
/* The stack of arguments passed to user defined functions. We need a
@@ -827,7 +816,7 @@ user_args::insert_args (const char *line) const
error (_("Missing argument %ld in user function."), i);
else
{
- new_line.append (m_args[i].str, m_args[i].len);
+ new_line.append (m_args[i].data (), m_args[i].length ());
line = tmp;
}
}
diff --git a/gdb/common/gdb_string_view.h b/gdb/common/gdb_string_view.h
index e42d5ac..545109c 100644
--- a/gdb/common/gdb_string_view.h
+++ b/gdb/common/gdb_string_view.h
@@ -1,5 +1,8 @@
// Components for manipulating non-owning sequences of characters -*- C++ -*-
+// Note: This file has been stolen from the gcc repo
+// (libstdc++-v3/include/experimental/string_view) and has local modifications.
+
// Copyright (C) 2013-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -22,34 +25,27 @@
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
-/** @file experimental/string_view
- * This is a TS C++ Library header.
- */
-
//
// N3762 basic_string_view library
//
-#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW
-#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW 1
+#ifndef GDB_STRING_VIEW_H
+#define GDB_STRING_VIEW_H 1
+
+#if __cplusplus >= 201703L
-#pragma GCC system_header
+#include <string_view>
-#if __cplusplus >= 201402L
+namespace gdb {
+ using string_view = std::string_view;
+} /* namespace gdb */
+
+#else /* __cplusplus < 201703L */
#include <string>
#include <limits>
-#include <experimental/bits/lfts_config.h>
-
-namespace std _GLIBCXX_VISIBILITY(default)
-{
-_GLIBCXX_BEGIN_NAMESPACE_VERSION
-namespace experimental
-{
-inline namespace fundamentals_v1
-{
-#define __cpp_lib_experimental_string_view 201411
+namespace gdb {
/**
* @class basic_string_view <experimental/string_view>
@@ -100,12 +96,12 @@ inline namespace fundamentals_v1
constexpr basic_string_view(const basic_string_view&) noexcept = default;
template<typename _Allocator>
- basic_string_view(const basic_string<_CharT, _Traits,
+ basic_string_view(const std::basic_string<_CharT, _Traits,
_Allocator>& __str) noexcept
: _M_len{__str.length()}, _M_str{__str.data()}
{ }
- constexpr basic_string_view(const _CharT* __str)
+ /*constexpr*/ basic_string_view(const _CharT* __str)
: _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
_M_str{__str}
{ }
@@ -188,10 +184,10 @@ inline namespace fundamentals_v1
{
return __pos < this->_M_len
? *(this->_M_str + __pos)
- : (__throw_out_of_range_fmt(__N("basic_string_view::at: __pos "
- "(which is %zu) >= this->size() "
- "(which is %zu)"),
- __pos, this->size()),
+ : (error (_("basic_string_view::at: __pos "
+ "(which is %zu) >= this->size() "
+ "(which is %zu)"),
+ __pos, this->size()),
*this->_M_str);
}
@@ -217,19 +213,19 @@ inline namespace fundamentals_v1
// [string.view.modifiers], modifiers:
- constexpr void
+ /*constexpr*/ void
remove_prefix(size_type __n)
{
- __glibcxx_assert(this->_M_len >= __n);
+ gdb_assert (this->_M_len >= __n);
this->_M_str += __n;
this->_M_len -= __n;
}
- constexpr void
+ /*constexpr*/ void
remove_suffix(size_type __n)
{ this->_M_len -= __n; }
- constexpr void
+ /*constexpr*/ void
swap(basic_string_view& __sv) noexcept
{
auto __tmp = *this;
@@ -241,13 +237,13 @@ inline namespace fundamentals_v1
// [string.view.ops], string operations:
template<typename _Allocator>
- explicit operator basic_string<_CharT, _Traits, _Allocator>() const
+ explicit operator std::basic_string<_CharT, _Traits, _Allocator>() const
{
return { this->_M_str, this->_M_len };
}
template<typename _Allocator = std::allocator<_CharT>>
- basic_string<_CharT, _Traits, _Allocator>
+ std::basic_string<_CharT, _Traits, _Allocator>
to_string(const _Allocator& __alloc = _Allocator()) const
{
return { this->_M_str, this->_M_len, __alloc };
@@ -256,12 +252,12 @@ inline namespace fundamentals_v1
size_type
copy(_CharT* __str, size_type __n, size_type __pos = 0) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
if (__pos > this->_M_len)
- __throw_out_of_range_fmt(__N("basic_string_view::copy: __pos "
- "(which is %zu) > this->size() "
- "(which is %zu)"),
- __pos, this->size());
+ error (_("basic_string_view::copy: __pos "
+ "(which is %zu) > this->size() "
+ "(which is %zu)"),
+ __pos, this->size());
size_type __rlen{std::min(__n, size_type{this->_M_len - __pos})};
for (auto __begin = this->_M_str + __pos,
__end = __begin + __rlen; __begin != __end;)
@@ -272,19 +268,19 @@ inline namespace fundamentals_v1
// [string.view.ops], string operations:
- constexpr basic_string_view
+ /*constexpr*/ basic_string_view
substr(size_type __pos, size_type __n=npos) const
{
return __pos <= this->_M_len
? basic_string_view{this->_M_str + __pos,
std::min(__n, size_type{this->_M_len - __pos})}
- : (__throw_out_of_range_fmt(__N("basic_string_view::substr: __pos "
- "(which is %zu) > this->size() "
- "(which is %zu)"),
- __pos, this->size()), basic_string_view{});
+ : (error (_("basic_string_view::substr: __pos "
+ "(which is %zu) > this->size() "
+ "(which is %zu)"),
+ __pos, this->size()), basic_string_view{});
}
- constexpr int
+ /*constexpr*/ int
compare(basic_string_view __str) const noexcept
{
int __ret = traits_type::compare(this->_M_str, __str._M_str,
@@ -294,24 +290,24 @@ inline namespace fundamentals_v1
return __ret;
}
- constexpr int
+ /*constexpr*/ int
compare(size_type __pos1, size_type __n1, basic_string_view __str) const
{ return this->substr(__pos1, __n1).compare(__str); }
- constexpr int
+ /*constexpr*/ int
compare(size_type __pos1, size_type __n1,
basic_string_view __str, size_type __pos2, size_type __n2) const
{ return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }
- constexpr int
+ /*constexpr*/ int
compare(const _CharT* __str) const noexcept
{ return this->compare(basic_string_view{__str}); }
- constexpr int
+ /*constexpr*/ int
compare(size_type __pos1, size_type __n1, const _CharT* __str) const
{ return this->substr(__pos1, __n1).compare(basic_string_view{__str}); }
- constexpr int
+ /*constexpr*/ int
compare(size_type __pos1, size_type __n1,
const _CharT* __str, size_type __n2) const
{
@@ -319,97 +315,97 @@ inline namespace fundamentals_v1
.compare(basic_string_view(__str, __n2));
}
- constexpr size_type
+ /*constexpr*/ size_type
find(basic_string_view __str, size_type __pos = 0) const noexcept
{ return this->find(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ /*constexpr*/ size_type
find(_CharT __c, size_type __pos=0) const noexcept;
- constexpr size_type
+ /*constexpr*/ size_type
find(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
- constexpr size_type
+ /*constexpr*/ size_type
find(const _CharT* __str, size_type __pos=0) const noexcept
{ return this->find(__str, __pos, traits_type::length(__str)); }
- constexpr size_type
+ /*constexpr*/ size_type
rfind(basic_string_view __str, size_type __pos = npos) const noexcept
{ return this->rfind(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ /*constexpr*/ size_type
rfind(_CharT __c, size_type __pos = npos) const noexcept;
- constexpr size_type
+ /*constexpr*/ size_type
rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept;
- constexpr size_type
+ /*constexpr*/ size_type
rfind(const _CharT* __str, size_type __pos = npos) const noexcept
{ return this->rfind(__str, __pos, traits_type::length(__str)); }
- constexpr size_type
+ /*constexpr*/ size_type
find_first_of(basic_string_view __str, size_type __pos = 0) const noexcept
{ return this->find_first_of(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ /*constexpr*/ size_type
find_first_of(_CharT __c, size_type __pos = 0) const noexcept
{ return this->find(__c, __pos); }
- constexpr size_type
+ /*constexpr*/ size_type
find_first_of(const _CharT* __str, size_type __pos, size_type __n) const;
- constexpr size_type
+ /*constexpr*/ size_type
find_first_of(const _CharT* __str, size_type __pos = 0) const noexcept
{ return this->find_first_of(__str, __pos, traits_type::length(__str)); }
- constexpr size_type
+ /*constexpr*/ size_type
find_last_of(basic_string_view __str,
size_type __pos = npos) const noexcept
{ return this->find_last_of(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ size_type
find_last_of(_CharT __c, size_type __pos=npos) const noexcept
{ return this->rfind(__c, __pos); }
- constexpr size_type
+ /*constexpr*/ size_type
find_last_of(const _CharT* __str, size_type __pos, size_type __n) const;
- constexpr size_type
+ /*constexpr*/ size_type
find_last_of(const _CharT* __str, size_type __pos = npos) const noexcept
{ return this->find_last_of(__str, __pos, traits_type::length(__str)); }
- constexpr size_type
+ /*constexpr*/ size_type
find_first_not_of(basic_string_view __str,
size_type __pos = 0) const noexcept
{ return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ /*constexpr*/ size_type
find_first_not_of(_CharT __c, size_type __pos = 0) const noexcept;
- constexpr size_type
+ /*constexpr*/ size_type
find_first_not_of(const _CharT* __str,
size_type __pos, size_type __n) const;
- constexpr size_type
+ /*constexpr*/ size_type
find_first_not_of(const _CharT* __str, size_type __pos = 0) const noexcept
{
return this->find_first_not_of(__str, __pos,
traits_type::length(__str));
}
- constexpr size_type
+ /*constexpr*/ size_type
find_last_not_of(basic_string_view __str,
size_type __pos = npos) const noexcept
{ return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
- constexpr size_type
+ /*constexpr*/ size_type
find_last_not_of(_CharT __c, size_type __pos = npos) const noexcept;
- constexpr size_type
+ /*constexpr*/ size_type
find_last_not_of(const _CharT* __str,
size_type __pos, size_type __n) const;
- constexpr size_type
+ /*constexpr*/ size_type
find_last_not_of(const _CharT* __str,
size_type __pos = npos) const noexcept
{
@@ -441,240 +437,124 @@ inline namespace fundamentals_v1
// argument participates in template argument deduction and the other
// argument gets implicitly converted to the deduced type. See n3766.html.
template<typename _Tp>
- using __idt = common_type_t<_Tp>;
+ using __idt = typename std::common_type<_Tp>::type;
}
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator==(basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.size() == __y.size() && __x.compare(__y) == 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator==(basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.size() == __y.size() && __x.compare(__y) == 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator==(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.size() == __y.size() && __x.compare(__y) == 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator!=(basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return !(__x == __y); }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator!=(basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return !(__x == __y); }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator!=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return !(__x == __y); }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator< (basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) < 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator< (basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.compare(__y) < 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator< (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) < 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator> (basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) > 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator> (basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.compare(__y) > 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator> (__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) > 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator<=(basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) <= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator<=(basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.compare(__y) <= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator<=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) <= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator>=(basic_string_view<_CharT, _Traits> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) >= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator>=(basic_string_view<_CharT, _Traits> __x,
__detail::__idt<basic_string_view<_CharT, _Traits>> __y) noexcept
{ return __x.compare(__y) >= 0; }
template<typename _CharT, typename _Traits>
- constexpr bool
+ /*constexpr*/ bool
operator>=(__detail::__idt<basic_string_view<_CharT, _Traits>> __x,
basic_string_view<_CharT, _Traits> __y) noexcept
{ return __x.compare(__y) >= 0; }
- // [string.view.io], Inserters and extractors
- template<typename _CharT, typename _Traits>
- inline basic_ostream<_CharT, _Traits>&
- operator<<(basic_ostream<_CharT, _Traits>& __os,
- basic_string_view<_CharT,_Traits> __str)
- { return __ostream_insert(__os, __str.data(), __str.size()); }
-
-
// basic_string_view typedef names
using string_view = basic_string_view<char>;
-#ifdef _GLIBCXX_USE_WCHAR_T
- using wstring_view = basic_string_view<wchar_t>;
-#endif
-#ifdef _GLIBCXX_USE_C99_STDINT_TR1
- using u16string_view = basic_string_view<char16_t>;
- using u32string_view = basic_string_view<char32_t>;
-#endif
-} // namespace fundamentals_v1
-} // namespace experimental
-
-
- // [string.view.hash], hash support:
- template<typename _Tp>
- struct hash;
-
- template<>
- struct hash<experimental::string_view>
- : public __hash_base<size_t, experimental::string_view>
- {
- size_t
- operator()(const experimental::string_view& __str) const noexcept
- { return std::_Hash_impl::hash(__str.data(), __str.length()); }
- };
-
- template<>
- struct __is_fast_hash<hash<experimental::string_view>> : std::false_type
- { };
+} /* namespace gdb */
-#ifdef _GLIBCXX_USE_WCHAR_T
- template<>
- struct hash<experimental::wstring_view>
- : public __hash_base<size_t, wstring>
- {
- size_t
- operator()(const experimental::wstring_view& __s) const noexcept
- { return std::_Hash_impl::hash(__s.data(),
- __s.length() * sizeof(wchar_t)); }
- };
-
- template<>
- struct __is_fast_hash<hash<experimental::wstring_view>> : std::false_type
- { };
-#endif
-
-#ifdef _GLIBCXX_USE_C99_STDINT_TR1
- template<>
- struct hash<experimental::u16string_view>
- : public __hash_base<size_t, experimental::u16string_view>
- {
- size_t
- operator()(const experimental::u16string_view& __s) const noexcept
- { return std::_Hash_impl::hash(__s.data(),
- __s.length() * sizeof(char16_t)); }
- };
+#include "gdb_string_view.tcc"
- template<>
- struct __is_fast_hash<hash<experimental::u16string_view>> : std::false_type
- { };
+#endif // __cplusplus < 201703L
- template<>
- struct hash<experimental::u32string_view>
- : public __hash_base<size_t, experimental::u32string_view>
- {
- size_t
- operator()(const experimental::u32string_view& __s) const noexcept
- { return std::_Hash_impl::hash(__s.data(),
- __s.length() * sizeof(char32_t)); }
- };
-
- template<>
- struct __is_fast_hash<hash<experimental::u32string_view>> : std::false_type
- { };
-#endif
-
-namespace experimental
-{
- // I added these EMSR.
- inline namespace literals
- {
- inline namespace string_view_literals
- {
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wliteral-suffix"
- inline constexpr basic_string_view<char>
- operator""sv(const char* __str, size_t __len) noexcept
- { return basic_string_view<char>{__str, __len}; }
-
-#ifdef _GLIBCXX_USE_WCHAR_T
- inline constexpr basic_string_view<wchar_t>
- operator""sv(const wchar_t* __str, size_t __len) noexcept
- { return basic_string_view<wchar_t>{__str, __len}; }
-#endif
-
-#ifdef _GLIBCXX_USE_C99_STDINT_TR1
- inline constexpr basic_string_view<char16_t>
- operator""sv(const char16_t* __str, size_t __len) noexcept
- { return basic_string_view<char16_t>{__str, __len}; }
-
- inline constexpr basic_string_view<char32_t>
- operator""sv(const char32_t* __str, size_t __len) noexcept
- { return basic_string_view<char32_t>{__str, __len}; }
-#endif
-#pragma GCC diagnostic pop
- } // namespace string_literals
- } // namespace literals
-} // namespace experimental
-
-_GLIBCXX_END_NAMESPACE_VERSION
-} // namespace std
-
-#include <experimental/bits/string_view.tcc>
-
-#endif // __cplusplus <= 201103L
-
-#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW
+#endif /* GDB_STRING_VIEW_H */
diff --git a/gdb/common/gdb_string_view.tcc b/gdb/common/gdb_string_view.tcc
index 579ecec..7df567a 100644
--- a/gdb/common/gdb_string_view.tcc
+++ b/gdb/common/gdb_string_view.tcc
@@ -1,5 +1,9 @@
// Components for manipulating non-owning sequences of characters -*- C++ -*-
+// Note: This file has been stolen from the gcc repo
+// (libstdc++-v3/include/experimental/bits/string_view.tcc) and has local
+// modifications.
+
// Copyright (C) 2013-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -31,27 +35,17 @@
// N3762 basic_string_view library
//
-#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC
-#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC 1
-
-#pragma GCC system_header
-
-#if __cplusplus >= 201402L
-
-namespace std _GLIBCXX_VISIBILITY(default)
-{
-_GLIBCXX_BEGIN_NAMESPACE_VERSION
+#ifndef GDB_STRING_VIEW_TCC
+#define GDB_STRING_VIEW_TCC 1
-namespace experimental
-{
-inline namespace fundamentals_v1
+namespace gdb
{
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find(const _CharT* __str, size_type __pos, size_type __n) const noexcept
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
if (__n == 0)
return __pos <= this->_M_len ? __pos : npos;
@@ -68,7 +62,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find(_CharT __c, size_type __pos) const noexcept
{
@@ -84,11 +78,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
rfind(const _CharT* __str, size_type __pos, size_type __n) const noexcept
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
if (__n <= this->_M_len)
{
@@ -104,7 +98,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
rfind(_CharT __c, size_type __pos) const noexcept
{
@@ -121,11 +115,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_of(const _CharT* __str, size_type __pos, size_type __n) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
for (; __n && __pos < this->_M_len; ++__pos)
{
const _CharT* __p = traits_type::find(__str, __n,
@@ -137,11 +131,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_of(const _CharT* __str, size_type __pos, size_type __n) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
size_type __size = this->size();
if (__size && __n)
{
@@ -158,11 +152,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_not_of(const _CharT* __str, size_type __pos, size_type __n) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
for (; __pos < this->_M_len; ++__pos)
if (!traits_type::find(__str, __n, this->_M_str[__pos]))
return __pos;
@@ -170,7 +164,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_first_not_of(_CharT __c, size_type __pos) const noexcept
{
@@ -181,11 +175,11 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_not_of(const _CharT* __str, size_type __pos, size_type __n) const
{
- __glibcxx_requires_string_len(__str, __n);
+ gdb_assert (__str != nullptr || __n == 0);
size_type __size = this->_M_len;
if (__size)
{
@@ -202,7 +196,7 @@ inline namespace fundamentals_v1
}
template<typename _CharT, typename _Traits>
- constexpr typename basic_string_view<_CharT, _Traits>::size_type
+ /*constexpr*/ typename basic_string_view<_CharT, _Traits>::size_type
basic_string_view<_CharT, _Traits>::
find_last_not_of(_CharT __c, size_type __pos) const noexcept
{
@@ -220,12 +214,6 @@ inline namespace fundamentals_v1
}
return npos;
}
-} // namespace fundamentals_v1
-} // namespace experimental
-
-_GLIBCXX_END_NAMESPACE_VERSION
-} // namespace std
-
-#endif // __cplusplus <= 201103L
+} // namespace gdb
-#endif // _GLIBCXX_EXPERIMENTAL_STRING_VIEW_TCC
+#endif // GDB_STRING_VIEW_TCC
--
2.7.4
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2018-04-09 18:28 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-07 13:26 [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Simon Marchi
2018-04-07 13:26 ` [PATCH v3 3/5] Add gdb::string_view Simon Marchi
2018-04-09 13:44 ` Pedro Alves
2018-04-09 17:28 ` Simon Marchi
2018-04-09 17:30 ` Simon Marchi
2018-04-09 18:28 ` Simon Marchi
2018-04-07 13:26 ` [PATCH v3 5/5] Adapt and integrate string_view tests Simon Marchi
2018-04-09 13:45 ` Pedro Alves
2018-04-07 13:26 ` [PATCH v3 2/5] Copy string_view files from libstdc++ Simon Marchi
2018-04-09 13:44 ` Pedro Alves
2018-04-09 17:23 ` Simon Marchi
2018-04-09 17:39 ` Pedro Alves
2018-04-09 18:20 ` Simon Marchi
2018-04-07 13:37 ` [PATCH v3 4/5] Copy string_view tests " Simon Marchi
2018-04-09 13:47 ` Pedro Alves
2018-04-09 13:46 ` [PATCH v3 1/5] Update ax_cv_cxx_compile_cxx.m4 Pedro Alves
2018-04-09 18:27 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).