libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

construct_default.pass.cpp (3079B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <vector>
     11 
     12 // vector();
     13 // vector(const Alloc&);
     14 
     15 #include <vector>
     16 #include <cassert>
     17 
     18 #include "test_macros.h"
     19 #include "test_allocator.h"
     20 #include "../../../NotConstructible.h"
     21 #include "test_allocator.h"
     22 #include "min_allocator.h"
     23 #include "asan_testing.h"
     24 
     25 template <class C>
     26 void
     27 test0()
     28 {
     29 #if TEST_STD_VER > 14
     30     static_assert((noexcept(C{})), "" );
     31 #elif TEST_STD_VER >= 11
     32     static_assert((noexcept(C()) == noexcept(typename C::allocator_type())), "" );
     33 #endif
     34     C c;
     35     LIBCPP_ASSERT(c.__invariants());
     36     assert(c.empty());
     37     assert(c.get_allocator() == typename C::allocator_type());
     38     LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
     39 #if TEST_STD_VER >= 11
     40     C c1 = {};
     41     LIBCPP_ASSERT(c1.__invariants());
     42     assert(c1.empty());
     43     assert(c1.get_allocator() == typename C::allocator_type());
     44     LIBCPP_ASSERT(is_contiguous_container_asan_correct(c1));
     45 #endif
     46 }
     47 
     48 template <class C>
     49 void
     50 test1(const typename C::allocator_type& a)
     51 {
     52 #if TEST_STD_VER > 14
     53     static_assert((noexcept(C{typename C::allocator_type{}})), "" );
     54 #elif TEST_STD_VER >= 11
     55     static_assert((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" );
     56 #endif
     57     C c(a);
     58     LIBCPP_ASSERT(c.__invariants());
     59     assert(c.empty());
     60     assert(c.get_allocator() == a);
     61     LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
     62 }
     63 
     64 int main()
     65 {
     66     {
     67     test0<std::vector<int> >();
     68     test0<std::vector<NotConstructible> >();
     69     test1<std::vector<int, test_allocator<int> > >(test_allocator<int>(3));
     70     test1<std::vector<NotConstructible, test_allocator<NotConstructible> > >
     71         (test_allocator<NotConstructible>(5));
     72     }
     73     {
     74         std::vector<int, limited_allocator<int, 10> > v;
     75         assert(v.empty());
     76     }
     77 #if TEST_STD_VER >= 11
     78     {
     79     test0<std::vector<int, min_allocator<int>> >();
     80     test0<std::vector<NotConstructible, min_allocator<NotConstructible>> >();
     81     test1<std::vector<int, min_allocator<int> > >(min_allocator<int>{});
     82     test1<std::vector<NotConstructible, min_allocator<NotConstructible> > >
     83         (min_allocator<NotConstructible>{});
     84     }
     85     {
     86         std::vector<int, min_allocator<int> > v;
     87         assert(v.empty());
     88     }
     89 
     90     {
     91     test0<std::vector<int, explicit_allocator<int>> >();
     92     test0<std::vector<NotConstructible, explicit_allocator<NotConstructible>> >();
     93     test1<std::vector<int, explicit_allocator<int> > >(explicit_allocator<int>{});
     94     test1<std::vector<NotConstructible, explicit_allocator<NotConstructible> > >
     95         (explicit_allocator<NotConstructible>{});
     96     }
     97     {
     98         std::vector<int, explicit_allocator<int> > v;
     99         assert(v.empty());
    100     }
    101 #endif
    102 }