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 // UNSUPPORTED: no-exceptions 10 11 // <string> 12 13 // size_type max_size() const; // constexpr since C++20 14 15 #include <string> 16 #include <cassert> 17 #include <stdexcept> 18 19 #include "test_macros.h" 20 #include "min_allocator.h" 21 22 template <class S> test(const S & s)23void test(const S& s) { 24 assert(s.max_size() >= s.size()); 25 S s2(s); 26 const std::size_t sz = s2.max_size() + 1; 27 try { 28 s2.resize(sz, 'x'); 29 } catch (const std::length_error&) { 30 return; 31 } 32 assert(false); 33 } 34 35 template <class S> test_string()36void test_string() { 37 test(S()); 38 test(S("123")); 39 test(S("12345678901234567890123456789012345678901234567890")); 40 } 41 test()42bool test() { 43 test_string<std::string>(); 44 #if TEST_STD_VER >= 11 45 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>(); 46 #endif 47 48 return true; 49 } 50 main(int,char **)51int main(int, char**) { 52 test(); 53 54 return 0; 55 } 56