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 // void shrink_to_fit(); 13 14 #include <vector> 15 #include <cassert> 16 #include "../../../stack_allocator.h" 17 #include "min_allocator.h" 18 #include "asan_testing.h" 19 main()20int main() 21 { 22 { 23 std::vector<int> v(100); 24 v.push_back(1); 25 assert(is_contiguous_container_asan_correct(v)); 26 v.shrink_to_fit(); 27 assert(v.capacity() == 101); 28 assert(v.size() == 101); 29 assert(is_contiguous_container_asan_correct(v)); 30 } 31 { 32 std::vector<int, stack_allocator<int, 401> > v(100); 33 v.push_back(1); 34 assert(is_contiguous_container_asan_correct(v)); 35 v.shrink_to_fit(); 36 assert(v.capacity() == 101); 37 assert(v.size() == 101); 38 assert(is_contiguous_container_asan_correct(v)); 39 } 40 #ifndef _LIBCPP_NO_EXCEPTIONS 41 { 42 std::vector<int, stack_allocator<int, 400> > v(100); 43 v.push_back(1); 44 assert(is_contiguous_container_asan_correct(v)); 45 v.shrink_to_fit(); 46 assert(v.capacity() == 200); 47 assert(v.size() == 101); 48 assert(is_contiguous_container_asan_correct(v)); 49 } 50 #endif 51 #if __cplusplus >= 201103L 52 { 53 std::vector<int, min_allocator<int>> v(100); 54 v.push_back(1); 55 assert(is_contiguous_container_asan_correct(v)); 56 v.shrink_to_fit(); 57 assert(v.capacity() == 101); 58 assert(v.size() == 101); 59 assert(is_contiguous_container_asan_correct(v)); 60 } 61 #endif 62 } 63