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 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11}} 11 12 // Prior to http://llvm.org/D123580, there was a bug with how the max_size() 13 // was calculated. That was inlined into some functions in the dylib, which leads 14 // to failures when running this test against an older system dylib. 15 // XFAIL: use_system_cxx_lib && target=arm64-apple-macosx{{11.0|12.0}} 16 17 // <string> 18 19 // size_type max_size() const; // constexpr since C++20 20 21 #include <string> 22 #include <cassert> 23 #include <stdexcept> 24 25 #include "test_macros.h" 26 #include "min_allocator.h" 27 28 template <class S> 29 void test(const S & s)30test(const S& s) 31 { 32 assert(s.max_size() >= s.size()); 33 S s2(s); 34 const size_t sz = s2.max_size() + 1; 35 try { s2.resize(sz, 'x'); } 36 catch ( const std::length_error & ) { return ; } 37 assert ( false ); 38 } 39 test()40bool test() { 41 { 42 typedef std::string S; 43 test(S()); 44 test(S("123")); 45 test(S("12345678901234567890123456789012345678901234567890")); 46 } 47 #if TEST_STD_VER >= 11 48 { 49 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 50 test(S()); 51 test(S("123")); 52 test(S("12345678901234567890123456789012345678901234567890")); 53 } 54 #endif 55 56 return true; 57 } 58 main(int,char **)59int main(int, char**) 60 { 61 test(); 62 63 return 0; 64 } 65