15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier
95a83710eSEric Fiselier // vector<bool>
105a83710eSEric Fiselier
11655fb4a7SMarshall Clow // vector();
12655fb4a7SMarshall Clow // vector(const Alloc&);
13655fb4a7SMarshall Clow
14655fb4a7SMarshall Clow // This tests a conforming extension
15655fb4a7SMarshall Clow // For vector<>, this was added to the standard by N4258,
16655fb4a7SMarshall Clow // but vector<bool> was not changed.
17655fb4a7SMarshall Clow
185a83710eSEric Fiselier
195a83710eSEric Fiselier #include <vector>
205a83710eSEric Fiselier #include <cassert>
215a83710eSEric Fiselier
22a8ae3927SMarshall Clow #include "test_macros.h"
235a83710eSEric Fiselier #include "test_allocator.h"
245a83710eSEric Fiselier #include "min_allocator.h"
255a83710eSEric Fiselier
265a83710eSEric Fiselier template <class C>
test0()27*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 void test0()
285a83710eSEric Fiselier {
29a8ae3927SMarshall Clow #if TEST_STD_VER > 14
30655fb4a7SMarshall Clow LIBCPP_STATIC_ASSERT((noexcept(C{})), "" );
31a8ae3927SMarshall Clow #elif TEST_STD_VER >= 11
32655fb4a7SMarshall Clow LIBCPP_STATIC_ASSERT((noexcept(C()) == noexcept(typename C::allocator_type())), "" );
33a8ae3927SMarshall Clow #endif
345a83710eSEric Fiselier C c;
351f4231f8SEric Fiselier LIBCPP_ASSERT(c.__invariants());
365a83710eSEric Fiselier assert(c.empty());
375a83710eSEric Fiselier assert(c.get_allocator() == typename C::allocator_type());
38a8ae3927SMarshall Clow #if TEST_STD_VER >= 11
395a83710eSEric Fiselier C c1 = {};
401f4231f8SEric Fiselier LIBCPP_ASSERT(c1.__invariants());
415a83710eSEric Fiselier assert(c1.empty());
425a83710eSEric Fiselier assert(c1.get_allocator() == typename C::allocator_type());
435a83710eSEric Fiselier #endif
445a83710eSEric Fiselier }
455a83710eSEric Fiselier
465a83710eSEric Fiselier template <class C>
test1(const typename C::allocator_type & a)47*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 void test1(const typename C::allocator_type& a)
485a83710eSEric Fiselier {
49a8ae3927SMarshall Clow #if TEST_STD_VER > 14
50655fb4a7SMarshall Clow LIBCPP_STATIC_ASSERT((noexcept(C{typename C::allocator_type{}})), "" );
51a8ae3927SMarshall Clow #elif TEST_STD_VER >= 11
52655fb4a7SMarshall Clow LIBCPP_STATIC_ASSERT((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" );
53a8ae3927SMarshall Clow #endif
545a83710eSEric Fiselier C c(a);
551f4231f8SEric Fiselier LIBCPP_ASSERT(c.__invariants());
565a83710eSEric Fiselier assert(c.empty());
575a83710eSEric Fiselier assert(c.get_allocator() == a);
585a83710eSEric Fiselier }
595a83710eSEric Fiselier
tests()60*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 bool tests()
615a83710eSEric Fiselier {
625a83710eSEric Fiselier {
635a83710eSEric Fiselier test0<std::vector<bool> >();
645a83710eSEric Fiselier test1<std::vector<bool, test_allocator<bool> > >(test_allocator<bool>(3));
655a83710eSEric Fiselier }
66a8ae3927SMarshall Clow #if TEST_STD_VER >= 11
675a83710eSEric Fiselier {
685a83710eSEric Fiselier test0<std::vector<bool, min_allocator<bool>> >();
695a83710eSEric Fiselier test1<std::vector<bool, min_allocator<bool> > >(min_allocator<bool>());
705a83710eSEric Fiselier }
712a10c960SMarshall Clow {
722a10c960SMarshall Clow test0<std::vector<bool, explicit_allocator<bool>> >();
732a10c960SMarshall Clow test1<std::vector<bool, explicit_allocator<bool> > >(explicit_allocator<bool>());
742a10c960SMarshall Clow }
755a83710eSEric Fiselier #endif
762df59c50SJF Bastien
77*c74059c5SNikolas Klauser return true;
78*c74059c5SNikolas Klauser }
79*c74059c5SNikolas Klauser
main(int,char **)80*c74059c5SNikolas Klauser int main(int, char**)
81*c74059c5SNikolas Klauser {
82*c74059c5SNikolas Klauser tests();
83*c74059c5SNikolas Klauser #if TEST_STD_VER > 17
84*c74059c5SNikolas Klauser static_assert(tests());
85*c74059c5SNikolas Klauser #endif
862df59c50SJF Bastien return 0;
875a83710eSEric Fiselier }
88