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 //===----------------------------------------------------------------------===//
8 
9 // XFAIL: LIBCXX-AIX-FIXME
10 
11 // <string>
12 
13 // const charT& back() const; // constexpr since C++20
14 //       charT& back(); // constexpr since C++20
15 
16 #include <string>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "min_allocator.h"
21 
22 template <class S>
23 TEST_CONSTEXPR_CXX20 void
24 test(S s)
25 {
26     const S& cs = s;
27     ASSERT_SAME_TYPE(decltype( s.back()), typename S::reference);
28     ASSERT_SAME_TYPE(decltype(cs.back()), typename S::const_reference);
29     LIBCPP_ASSERT_NOEXCEPT(    s.back());
30     LIBCPP_ASSERT_NOEXCEPT(   cs.back());
31     assert(&cs.back() == &cs[cs.size()-1]);
32     assert(&s.back() == &s[cs.size()-1]);
33     s.back() = typename S::value_type('z');
34     assert(s.back() == typename S::value_type('z'));
35 }
36 
37 TEST_CONSTEXPR_CXX20 bool test() {
38   {
39     typedef std::string S;
40     test(S("1"));
41     test(S("1234567890123456789012345678901234567890"));
42   }
43 #if TEST_STD_VER >= 11
44   {
45     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
46     test(S("1"));
47     test(S("1234567890123456789012345678901234567890"));
48   }
49 #endif
50 
51   return true;
52 }
53 
54 int main(int, char**)
55 {
56   test();
57 #if TEST_STD_VER > 17
58   static_assert(test());
59 #endif
60 
61   return 0;
62 }
63