Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <string> |
| 10 | |
| 11 | // const charT& front() const; |
| 12 | // charT& front(); |
| 13 | |
Howard Hinnant | 145afa1 | 2013-08-23 20:10:18 +0000 | [diff] [blame] | 14 | #ifdef _LIBCPP_DEBUG |
Howard Hinnant | fc88dbd | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 15 | #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) |
| 16 | #endif |
| 17 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 18 | #include <string> |
| 19 | #include <cassert> |
| 20 | |
Marshall Clow | 7fc6a55 | 2019-05-31 18:35:30 +0000 | [diff] [blame] | 21 | #include "test_macros.h" |
Marshall Clow | e34f6f6 | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 22 | #include "min_allocator.h" |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 23 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | template <class S> |
| 25 | void |
| 26 | test(S s) |
| 27 | { |
| 28 | const S& cs = s; |
Marshall Clow | 9ea0e47 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 29 | ASSERT_SAME_TYPE(decltype( s.front()), typename S::reference); |
| 30 | ASSERT_SAME_TYPE(decltype(cs.front()), typename S::const_reference); |
| 31 | LIBCPP_ASSERT_NOEXCEPT( s.front()); |
| 32 | LIBCPP_ASSERT_NOEXCEPT( cs.front()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 33 | assert(&cs.front() == &cs[0]); |
| 34 | assert(&s.front() == &s[0]); |
| 35 | s.front() = typename S::value_type('z'); |
| 36 | assert(s.front() == typename S::value_type('z')); |
| 37 | } |
| 38 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 39 | int main(int, char**) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | { |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 41 | { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | typedef std::string S; |
| 43 | test(S("1")); |
| 44 | test(S("1234567890123456789012345678901234567890")); |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 45 | } |
Eric Fiselier | f2f2a63 | 2016-06-14 21:31:42 +0000 | [diff] [blame] | 46 | #if TEST_STD_VER >= 11 |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 47 | { |
| 48 | typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |
| 49 | test(S("1")); |
| 50 | test(S("1234567890123456789012345678901234567890")); |
| 51 | } |
| 52 | #endif |
Howard Hinnant | 145afa1 | 2013-08-23 20:10:18 +0000 | [diff] [blame] | 53 | #ifdef _LIBCPP_DEBUG |
Howard Hinnant | fc88dbd | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 54 | { |
| 55 | std::string s; |
Marshall Clow | ccbe567 | 2019-05-01 11:25:58 +0000 | [diff] [blame] | 56 | (void) s.front(); |
Howard Hinnant | fc88dbd | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 57 | assert(false); |
| 58 | } |
| 59 | #endif |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 60 | |
| 61 | return 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | } |