[VPlan] Add and use debug location for VPScalarCastRecipe.
[llvm-project.git] / libcxx / test / std / strings / string.view / string.view.cons / from_literal.pass.cpp
blobd48c2f9dc728d245852e5706240a9eae0ae65275
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
11 // <string_view>
13 // constexpr basic_string_view(const _CharT* _s)
14 // : __data (_s), __size(_Traits::length(_s)) {}
16 #include <string_view>
17 #include <string>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "constexpr_char_traits.h"
23 template <typename CharT>
24 size_t StrLen(const CharT* s) {
25 std::size_t retVal = 0;
26 while (*s != 0) {
27 ++retVal;
28 ++s;
30 return retVal;
33 template <typename CharT>
34 void test(const CharT* s) {
35 typedef std::basic_string_view<CharT> SV;
36 // I'd love to do this, but it would require traits::length() to be noexcept
37 // LIBCPP_ASSERT_NOEXCEPT(SV(s));
39 SV sv1(s);
40 assert(sv1.size() == StrLen(s));
41 assert(sv1.data() == s);
44 int main(int, char**) {
45 test("QBCDE");
46 test("A");
47 test("");
49 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
50 test(L"QBCDE");
51 test(L"A");
52 test(L"");
53 #endif
55 #if TEST_STD_VER >= 11
56 test(u"QBCDE");
57 test(u"A");
58 test(u"");
60 test(U"QBCDE");
61 test(U"A");
62 test(U"");
63 #endif
65 #if TEST_STD_VER > 11
67 constexpr std::basic_string_view<char, constexpr_char_traits<char>> sv1("ABCDE");
68 static_assert(sv1.size() == 5, "");
70 #endif
72 return 0;