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// UNSUPPORTED: c++03
9
10// <vector>
11
12// vector()
13// noexcept(is_nothrow_default_constructible<allocator_type>::value);
14
15// This *was* a conforming extension, but it was adopted in N4258.
16
17#include <vector>
18#include <cassert>
19
20#include "test_macros.h"
21#include "MoveOnly.h"
22#include "test_allocator.h"
23
24template <class T>
25struct some_alloc {
26 typedef T value_type;
27 some_alloc(const some_alloc&);
28 void allocate(std::size_t);
29};
30
31TEST_CONSTEXPR_CXX20 bool tests() {
32 {
33 typedef std::vector<MoveOnly> C;
34 static_assert(std::is_nothrow_default_constructible<C>::value, "");
35 }
36 {
37 typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C;
38 static_assert(std::is_nothrow_default_constructible<C>::value, "");
39 }
40 {
41 typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C;
42 static_assert(!std::is_nothrow_default_constructible<C>::value, "");
43 }
44 {
45 typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C;
46 static_assert(!std::is_nothrow_default_constructible<C>::value, "");
47 }
48
49 return true;
50}
51
52int main(int, char**) {
53 tests();
54#if TEST_STD_VER > 17
55 static_assert(tests());
56#endif
57 return 0;
58}
59

source code of libcxx/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp