summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/experimental/string_view
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2014-06-01 18:23:41 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2014-06-01 18:23:41 +0100
commit16545743c6c5e1766eac9f896040c50993e77dfd (patch)
tree4f41e7bc2578a1bc38d4d94bab70ebff13a39843 /libstdc++-v3/testsuite/experimental/string_view
parent6041d142c48fc03e72d132a29439121e7978e4f3 (diff)
downloadgcc-16545743c6c5e1766eac9f896040c50993e77dfd.tar.gz
re PR libstdc++/61374 (string_view::operator string() is buggy)
PR libstdc++/61374 * include/experimental/string_view (operator basic_string): Correct order of arguments. (to_string): Replace with member function. Add inline specifiers. Remove unused header. Remove _S_empty_rep and allow _M_str to be null. * testsuite/experimental/string_view/cons/char/1.cc: Adjust to new default constructor semantics. * testsuite/experimental/string_view/cons/wchar_t/1.cc: Likewise. * testsuite/experimental/string_view/operations/copy/char/1.cc: Fix copyright dates. Remove unused header. * testsuite/experimental/string_view/operations/copy/wchar_t/1.cc: Likewise. * testsuite/experimental/string_view/operations/data/char/1.cc: Fix copyright dates. Adjust to new default constructor semantics. * testsuite/experimental/string_view/operations/data/wchar_t/1.cc: Likewise. * testsuite/experimental/string_view/operations/to_string/1.cc: New. From-SVN: r211113
Diffstat (limited to 'libstdc++-v3/testsuite/experimental/string_view')
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/cons/char/1.cc7
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/1.cc7
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/operations/copy/char/1.cc3
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/operations/copy/wchar_t/1.cc3
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/operations/data/char/1.cc5
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/operations/data/wchar_t/1.cc5
-rw-r--r--libstdc++-v3/testsuite/experimental/string_view/operations/to_string/1.cc53
7 files changed, 61 insertions, 22 deletions
diff --git a/libstdc++-v3/testsuite/experimental/string_view/cons/char/1.cc b/libstdc++-v3/testsuite/experimental/string_view/cons/char/1.cc
index c879cc7e00e..a443b0ac7e0 100644
--- a/libstdc++-v3/testsuite/experimental/string_view/cons/char/1.cc
+++ b/libstdc++-v3/testsuite/experimental/string_view/cons/char/1.cc
@@ -33,7 +33,7 @@ test01()
// basic_string_view()
const std::experimental::string_view str00{};
VERIFY( str00.length() == 0 );
- VERIFY( str00.data() != nullptr );
+ VERIFY( str00.data() == nullptr );
// basic_string_view(const char*)
const char str_lit01[] = "rodeo beach, marin";
@@ -54,11 +54,6 @@ test01()
VERIFY( str05.length() == len_lit01 );
VERIFY( str05.data() == str_lit01 );
- // basic_string_view(const char* s, std::size_t l)
- std::experimental::string_view str06{nullptr, len_lit01};
- VERIFY( str06.length() == 0 );
- VERIFY( str06.data() != nullptr );
-
// basic_string_view(basic_string& s)
std::string istr07(10, 'z');
std::experimental::string_view str07{istr07};
diff --git a/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/1.cc
index 12db72f2865..9ba9b84a180 100644
--- a/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/1.cc
@@ -33,7 +33,7 @@ test01()
// basic_string_view()
const std::experimental::wstring_view str00{};
VERIFY( str00.length() == 0 );
- VERIFY( str00.data() != nullptr );
+ VERIFY( str00.data() == nullptr );
// basic_string_view(const char*)
const wchar_t str_lit01[] = L"rodeo beach, marin";
@@ -54,11 +54,6 @@ test01()
VERIFY( str05.length() == len_lit01 );
VERIFY( str05.data() == str_lit01 );
- // basic_string_view(const wchar_t* s, std::size_t l)
- std::experimental::wstring_view str06{nullptr, len_lit01};
- VERIFY( str06.length() == 0 );
- VERIFY( str06.data() != nullptr );
-
// basic_string_view(basic_string& s)
std::wstring istr07(10, L'z');
std::experimental::wstring_view str07{istr07};
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/copy/char/1.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/copy/char/1.cc
index 25b2af133d3..d0f3e8d6901 100644
--- a/libstdc++-v3/testsuite/experimental/string_view/operations/copy/char/1.cc
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/copy/char/1.cc
@@ -1,6 +1,6 @@
// { dg-options "-std=gnu++1y" }
-// Copyright (C) 2013 Free Software Foundation, Inc.
+// 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
@@ -20,7 +20,6 @@
// basic_string_view::copy
#include <experimental/string_view>
-#include <stdexcept>
#include <testsuite_hooks.h>
bool
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/copy/wchar_t/1.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/copy/wchar_t/1.cc
index 0348e1f98fc..bf3f14b14bd 100644
--- a/libstdc++-v3/testsuite/experimental/string_view/operations/copy/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/copy/wchar_t/1.cc
@@ -1,6 +1,6 @@
// { dg-options "-std=gnu++1y" }
-// Copyright (C) 2013 Free Software Foundation, Inc.
+// 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
@@ -20,7 +20,6 @@
// basic_string_view::copy
#include <experimental/string_view>
-#include <stdexcept>
#include <testsuite_hooks.h>
bool
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/data/char/1.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/data/char/1.cc
index be75de91791..a34492606ad 100644
--- a/libstdc++-v3/testsuite/experimental/string_view/operations/data/char/1.cc
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/data/char/1.cc
@@ -1,6 +1,6 @@
// { dg-options "-std=gnu++1y" }
-// Copyright (C) 2013 Free Software Foundation, Inc.
+// 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
@@ -29,10 +29,9 @@ test01()
std::experimental::string_view empty;
- // data() for size == 0 is non-NULL.
VERIFY( empty.size() == 0 );
const std::experimental::string_view::value_type* p = empty.data();
- VERIFY( p );
+ VERIFY( p == nullptr );
return 0;
}
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/data/wchar_t/1.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/data/wchar_t/1.cc
index 5e00b00b601..41d2d1411d9 100644
--- a/libstdc++-v3/testsuite/experimental/string_view/operations/data/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/data/wchar_t/1.cc
@@ -1,6 +1,6 @@
// { dg-options "-std=gnu++1y" }
-// Copyright (C) 2013 Free Software Foundation, Inc.
+// 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
@@ -29,10 +29,9 @@ test01()
std::experimental::wstring_view empty;
- // data() for size == 0 is non-NULL.
VERIFY( empty.size() == 0 );
const std::experimental::wstring_view::value_type* p = empty.data();
- VERIFY( p );
+ VERIFY( p == nullptr );
return 0;
}
diff --git a/libstdc++-v3/testsuite/experimental/string_view/operations/to_string/1.cc b/libstdc++-v3/testsuite/experimental/string_view/operations/to_string/1.cc
new file mode 100644
index 00000000000..c0a5734c675
--- /dev/null
+++ b/libstdc++-v3/testsuite/experimental/string_view/operations/to_string/1.cc
@@ -0,0 +1,53 @@
+// { dg-options "-std=gnu++1y" }
+
+// Copyright (C) 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/>.
+
+// basic_string_view::to_string
+
+#include <experimental/string_view>
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+bool
+test01()
+{
+ bool test [[gnu::unused]] = true;
+
+ const char str_lit[] = "123456789A";
+ const std::experimental::string_view sv(str_lit);
+ char buffer[4] = { 0 };
+
+ auto s1 = sv.to_string();
+ VERIFY( s1 == str_lit );
+ using test_alloc = __gnu_test::tracker_allocator<char>;
+ auto s2 = sv.to_string( 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 );
+
+ return test;
+}
+
+int
+main()
+{
+ test01();
+}