1cddeb751SMarshall Clow //===----------------------------------------------------------------------===//
2cddeb751SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6cddeb751SMarshall Clow //
7cddeb751SMarshall Clow //===----------------------------------------------------------------------===//
8cddeb751SMarshall Clow 
9*4fc50236SJoe Loser // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10*4fc50236SJoe Loser 
11cddeb751SMarshall Clow // <string_view>
12cddeb751SMarshall Clow 
13cddeb751SMarshall Clow // constexpr basic_string_view& operator=(const basic_string_view &) noexcept = default;
14cddeb751SMarshall Clow 
15cddeb751SMarshall Clow #include <string_view>
16cddeb751SMarshall Clow #include <cassert>
17cddeb751SMarshall Clow 
18cddeb751SMarshall Clow #include "test_macros.h"
19cddeb751SMarshall Clow 
20cddeb751SMarshall Clow template<typename T>
21cddeb751SMarshall Clow #if TEST_STD_VER > 11
22cddeb751SMarshall Clow constexpr
23cddeb751SMarshall Clow #endif
test(T sv0)24cddeb751SMarshall Clow bool test (T sv0)
25cddeb751SMarshall Clow     {
26cddeb751SMarshall Clow     T sv1;
27cddeb751SMarshall Clow     sv1 = sv0;
28cddeb751SMarshall Clow //  We can't just say "sv0 == sv1" here because string_view::compare
29cddeb751SMarshall Clow //  isn't constexpr until C++17, and we want to support back to C++14
30cddeb751SMarshall Clow     return sv0.size() == sv1.size() && sv0.data() == sv1.data();
31cddeb751SMarshall Clow     }
32cddeb751SMarshall Clow 
main(int,char **)332df59c50SJF Bastien int main(int, char**) {
34cddeb751SMarshall Clow 
35cddeb751SMarshall Clow     assert( test<std::string_view>    (  "1234"));
367dad0bd6SMarshall Clow #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
377dad0bd6SMarshall Clow     assert( test<std::u8string_view>  (u8"1234"));
387dad0bd6SMarshall Clow #endif
3971f1ec7eSMarshall Clow #if TEST_STD_VER >= 11
40cddeb751SMarshall Clow     assert( test<std::u16string_view> ( u"1234"));
41cddeb751SMarshall Clow     assert( test<std::u32string_view> ( U"1234"));
42cddeb751SMarshall Clow #endif
43f4c1258dSLouis Dionne #ifndef TEST_HAS_NO_WIDE_CHARACTERS
44cddeb751SMarshall Clow     assert( test<std::wstring_view>   ( L"1234"));
45f4c1258dSLouis Dionne #endif
46cddeb751SMarshall Clow 
47cddeb751SMarshall Clow #if TEST_STD_VER > 11
48cddeb751SMarshall Clow     static_assert( test<std::string_view>    ({  "abc", 3}), "");
497dad0bd6SMarshall Clow #   if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
507dad0bd6SMarshall Clow     static_assert( test<std::u8string_view>  ({u8"abc", 3}), "");
517dad0bd6SMarshall Clow #   endif
52cddeb751SMarshall Clow     static_assert( test<std::u16string_view> ({ u"abc", 3}), "");
53cddeb751SMarshall Clow     static_assert( test<std::u32string_view> ({ U"abc", 3}), "");
54f4c1258dSLouis Dionne #   ifndef TEST_HAS_NO_WIDE_CHARACTERS
55cddeb751SMarshall Clow     static_assert( test<std::wstring_view>   ({ L"abc", 3}), "");
56cddeb751SMarshall Clow #   endif
57f4c1258dSLouis Dionne #endif
582df59c50SJF Bastien 
592df59c50SJF Bastien   return 0;
60cddeb751SMarshall Clow }
61