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 // <string>
10 
11 // const charT& front() const;
12 //       charT& front();
13 
14 #ifdef _LIBCPP_DEBUG
15 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
16 #endif
17 
18 #include <string>
19 #include <cassert>
20 
21 #include "min_allocator.h"
22 
23 template <class S>
24 void
25 test(S s)
26 {
27     const S& cs = s;
28     assert(&cs.front() == &cs[0]);
29     assert(&s.front() == &s[0]);
30     s.front() = typename S::value_type('z');
31     assert(s.front() == typename S::value_type('z'));
32 }
33 
34 int main(int, char**)
35 {
36     {
37     typedef std::string S;
38     test(S("1"));
39     test(S("1234567890123456789012345678901234567890"));
40     }
41 #if TEST_STD_VER >= 11
42     {
43     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
44     test(S("1"));
45     test(S("1234567890123456789012345678901234567890"));
46     }
47 #endif
48 #ifdef _LIBCPP_DEBUG
49     {
50         std::string s;
51         char c = s.front();
52         assert(false);
53     }
54 #endif
55 
56   return 0;
57 }
58