Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.capacity / over_max_size.pass.cpp
blob0b459f9625689e76a6bb39a3fb7557eeaa748f42
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-exceptions
10 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|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: stdlib=apple-libc++ && target=arm64-apple-macosx{{11.0|12.0}}
17 // <string>
19 // size_type max_size() const; // constexpr since C++20
21 #include <string>
22 #include <cassert>
23 #include <stdexcept>
25 #include "test_macros.h"
26 #include "min_allocator.h"
28 template <class S>
29 void test(const S& s) {
30 assert(s.max_size() >= s.size());
31 S s2(s);
32 const std::size_t sz = s2.max_size() + 1;
33 try {
34 s2.resize(sz, 'x');
35 } catch (const std::length_error&) {
36 return;
38 assert(false);
41 template <class S>
42 void test_string() {
43 test(S());
44 test(S("123"));
45 test(S("12345678901234567890123456789012345678901234567890"));
48 bool test() {
49 test_string<std::string>();
50 #if TEST_STD_VER >= 11
51 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char>>>();
52 #endif
54 return true;
57 int main(int, char**) {
58 test();
60 return 0;