diff --git a/libcxx/include/string_view b/libcxx/include/string_view --- a/libcxx/include/string_view +++ b/libcxx/include/string_view @@ -323,10 +323,7 @@ !is_convertible_v<_Range, const _CharT*> && (!requires(remove_cvref_t<_Range>& __d) { __d.operator _VSTD::basic_string_view<_CharT, _Traits>(); - }) && - (!requires { - typename remove_reference_t<_Range>::traits_type; - } || is_same_v::traits_type, _Traits>) + }) ) constexpr explicit _LIBCPP_HIDE_FROM_ABI basic_string_view(_Range&& __r) : __data_(ranges::data(__r)), __size_(ranges::size(__r)) {} diff --git a/libcxx/test/std/strings/string.view/string.view.cons/from_range.pass.cpp b/libcxx/test/std/strings/string.view/string.view.cons/from_range.pass.cpp --- a/libcxx/test/std/strings/string.view/string.view.cons/from_range.pass.cpp +++ b/libcxx/test/std/strings/string.view/string.view.cons/from_range.pass.cpp @@ -107,6 +107,15 @@ assert(sv == "test"); } + // Different trait types + { + struct OtherTraits : std::char_traits {}; + std::basic_string_view sv1{"hello"}; + std::basic_string_view sv2(sv1); + assert(sv1.size() == sv2.size()); + assert(sv1.data() == sv2.data()); + } + return true; } @@ -135,25 +144,7 @@ static_assert(std::is_constructible_v); // lvalue static_assert(std::is_constructible_v); // const lvalue -static_assert(std::is_constructible_v); // rvalue - -template -struct WithTraitsType { - typename CharTraits::char_type* begin() const; - typename CharTraits::char_type* end() const; - using traits_type = CharTraits; -}; - -using CCT = constexpr_char_traits; -static_assert(std::is_constructible_v>>); -#ifndef TEST_HAS_NO_WIDE_CHARACTERS -static_assert(std::is_constructible_v>>); -#endif -static_assert(std::is_constructible_v, WithTraitsType>); -static_assert(!std::is_constructible_v>); // wrong traits type -#ifndef TEST_HAS_NO_WIDE_CHARACTERS -static_assert(!std::is_constructible_v>>); // wrong traits type -#endif +static_assert(std::is_constructible_v); // rvalue #ifndef TEST_HAS_NO_EXCEPTIONS void test_throwing() { diff --git a/libcxx/test/std/strings/string.view/string.view.cons/from_string1.compile.fail.cpp b/libcxx/test/std/strings/string.view/string.view.cons/from_string1.compile.fail.cpp deleted file mode 100644 --- a/libcxx/test/std/strings/string.view/string.view.cons/from_string1.compile.fail.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14) - -// - -// template -// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept - -#include -#include -#include - -struct dummy_char_traits : public std::char_traits {}; - -int main(int, char**) { - using string_view = std::basic_string_view; - using string = std:: basic_string ; - - { - string s{"QBCDE"}; - string_view sv1 ( s ); - assert ( sv1.size() == s.size()); - assert ( sv1.data() == s.data()); - } - - return 0; -} diff --git a/libcxx/test/std/strings/string.view/string.view.cons/from_string2.compile.fail.cpp b/libcxx/test/std/strings/string.view/string.view.cons/from_string2.compile.fail.cpp deleted file mode 100644 --- a/libcxx/test/std/strings/string.view/string.view.cons/from_string2.compile.fail.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14) - -// - -// template -// basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept - -#include -#include -#include - -struct dummy_char_traits : public std::char_traits {}; - -int main(int, char**) { - using string_view = std::basic_string_view; - using string = std:: basic_string ; - - { - string s{"QBCDE"}; - string_view sv1 ( s ); - assert ( sv1.size() == s.size()); - assert ( sv1.data() == s.data()); - } - - return 0; -}