From 53e6927367683761193f3bb6a7009f8ba04572ff Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 26 Apr 2019 16:02:02 +0100 Subject: [PATCH] Fix tests that fail with _GLIBCXX_USE_CXX11_ABI=0 The pmr::string typedef isn't available for the old COW string, so some tests that use it were failing. * testsuite/20_util/variant/run.cc: Use a new Hashable type to test hashing, because pmr::string depends on _GLIBCXX_USE_CXX11_ABI==1. * testsuite/21_strings/basic_string/hash/hash.cc [!_GLIBCXX_USE_CXX11_ABI]: Don't test pmr strings. * testsuite/21_strings/basic_string/hash/hash_char8_t.cc [!_GLIBCXX_USE_CXX11_ABI]: Likewise. From-SVN: r270604 --- libstdc++-v3/ChangeLog | 7 +++++ libstdc++-v3/testsuite/20_util/variant/run.cc | 28 ++++++++++++++++--- .../21_strings/basic_string/hash/hash.cc | 16 +++++++++-- .../basic_string/hash/hash_char8_t.cc | 4 ++- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 61841e87ce8..78626838d4f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2019-04-26 Jonathan Wakely + * testsuite/20_util/variant/run.cc: Use a new Hashable type to test + hashing, because pmr::string depends on _GLIBCXX_USE_CXX11_ABI==1. + * testsuite/21_strings/basic_string/hash/hash.cc + [!_GLIBCXX_USE_CXX11_ABI]: Don't test pmr strings. + * testsuite/21_strings/basic_string/hash/hash_char8_t.cc + [!_GLIBCXX_USE_CXX11_ABI]: Likewise. + * config/abi/pre/gnu.ver (GLIBCXX_3.4): Replace wildcard that matches wstring::_M_replace_dispatch with more specific patterns. * include/bits/fs_path.h (path::_S_convert_loc<_InputIterator>): diff --git a/libstdc++-v3/testsuite/20_util/variant/run.cc b/libstdc++-v3/testsuite/20_util/variant/run.cc index f7353ad96b6..0416fbac12a 100644 --- a/libstdc++-v3/testsuite/20_util/variant/run.cc +++ b/libstdc++-v3/testsuite/20_util/variant/run.cc @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -433,9 +432,30 @@ void test_visit() } } +struct Hashable +{ + Hashable(const char* s) : s(s) { } + // Non-trivial special member functions: + Hashable(const Hashable&) { } + Hashable(Hashable&&) noexcept { } + ~Hashable() { } + + string s; + + bool operator==(const Hashable& rhs) const noexcept + { return s == rhs.s; } +}; + +namespace std { + template<> struct hash { + size_t operator()(const Hashable& h) const noexcept + { return hash()(h.s); } + }; +} + void test_hash() { - unordered_set> s; + unordered_set> s; VERIFY(s.emplace(3).second); VERIFY(s.emplace("asdf").second); VERIFY(s.emplace().second); @@ -447,12 +467,12 @@ void test_hash() { struct A { - operator pmr::string() + operator Hashable() { throw nullptr; } }; - variant v; + variant v; try { v.emplace<1>(A{}); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/hash/hash.cc b/libstdc++-v3/testsuite/21_strings/basic_string/hash/hash.cc index 9bdf9bd41ab..413c22bd16b 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/hash/hash.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/hash/hash.cc @@ -39,19 +39,29 @@ void test01() { VERIFY( test(std::string("a narrow string")) ); - VERIFY( test(std::pmr::string("a narrow string, but with PMR!")) ); VERIFY( test(std::u16string(u"a utf-16 string")) ); - VERIFY( test(std::pmr::u16string(u"a utf-16 string, but with PMR!")) ); VERIFY( test(std::u32string(U"a utf-32 string")) ); - VERIFY( test(std::pmr::u32string(U"a utf-32 string, but with PMR!")) ); #if _GLIBCXX_USE_WCHAR_T VERIFY( test(std::wstring(L"a wide string")) ); +#endif +} + +void +test02() +{ +#if _GLIBCXX_USE_CXX11_ABI + VERIFY( test(std::pmr::string("a narrow string, but with PMR!")) ); + VERIFY( test(std::pmr::u16string(u"a utf-16 string, but with PMR!")) ); + VERIFY( test(std::pmr::u32string(U"a utf-32 string, but with PMR!")) ); +#if _GLIBCXX_USE_WCHAR_T VERIFY( test(std::pmr::wstring(L"a wide string, but with PMR!")) ); #endif +#endif } int main() { test01(); + test02(); } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/hash/hash_char8_t.cc b/libstdc++-v3/testsuite/21_strings/basic_string/hash/hash_char8_t.cc index 0e4cfae4b76..ad02fcc98ec 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/hash/hash_char8_t.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/hash/hash_char8_t.cc @@ -39,9 +39,11 @@ void test01() { VERIFY( test(std::string("a narrow string")) ); - VERIFY( test(std::pmr::string("a narrow string, but with PMR!")) ); VERIFY( test(std::u8string(u8"a utf-8 string")) ); +#if _GLIBCXX_USE_CXX11_ABI + VERIFY( test(std::pmr::string("a narrow string, but with PMR!")) ); VERIFY( test(std::pmr::u8string(u8"a utf-8 string, but with PMR!")) ); +#endif } void -- 2.30.2