1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
13 // ~basic_string() // implied noexcept; // constexpr since C++20
18 #include "test_macros.h"
19 #include "test_allocator.h"
22 struct throwing_alloc
{
24 throwing_alloc(const throwing_alloc
&);
25 T
* allocate(std::size_t);
26 ~throwing_alloc() noexcept(false);
29 // Test that it's possible to take the address of basic_string's destructors
30 // by creating globals which will register their destructors with cxa_atexit.
31 std::string unused_string
;
32 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
33 std::wstring unused_wide_string
;
36 static_assert(std::is_nothrow_destructible
<std::string
>::value
, "");
38 std::is_nothrow_destructible
< std::basic_string
<char, std::char_traits
<char>, test_allocator
<char>>>::value
, "");
40 !std::is_nothrow_destructible
< std::basic_string
<char, std::char_traits
<char>, throwing_alloc
<char>>>::value
, "");
42 TEST_CONSTEXPR_CXX20
bool test() {
43 test_allocator_statistics alloc_stats
;
45 std::basic_string
<char, std::char_traits
<char>, test_allocator
<char>> str2((test_allocator
<char>(&alloc_stats
)));
46 str2
= "long long string so no SSO";
47 assert(alloc_stats
.alloc_count
> 0);
48 LIBCPP_ASSERT(alloc_stats
.alloc_count
== 1);
50 assert(alloc_stats
.alloc_count
== 0);
55 int main(int, char**) {
58 static_assert(test());