xref: /llvm-project/libcxx/test/std/strings/basic.string/string.cons/default.pass.cpp (revision 628fcfd5204cf87a733ede91a648bed4c20eb21a)
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 // <string>
10 
11 // basic_string() noexcept(is_nothrow_default_constructible<allocator_type>::value);
12 
13 #include <cassert>
14 #include <string>
15 
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 
19 #if TEST_STD_VER >= 11
20 // Test the noexcept specification, which is a conforming extension
21 LIBCPP_STATIC_ASSERT(std::is_nothrow_default_constructible<std::string>::value, "");
22 LIBCPP_STATIC_ASSERT(std::is_nothrow_default_constructible<
23                      std::basic_string<char, std::char_traits<char>, test_allocator<char>>>::value, "");
24 LIBCPP_STATIC_ASSERT(!std::is_nothrow_default_constructible<
25                      std::basic_string<char, std::char_traits<char>, limited_allocator<char, 10>>>::value, "");
26 #endif
27 
28 bool test() {
29   std::string str;
30   assert(str.empty());
31 
32   return true;
33 }
34 
35 int main(int, char**)
36 {
37   test();
38 #if TEST_STD_VER > 17
39   // static_assert(test());
40 #endif
41 
42   return 0;
43 }
44