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 // <vector>
10 
11 // pointer data();
12 
13 #include <vector>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 #include "min_allocator.h"
18 #include "asan_testing.h"
19 
20 struct Nasty {
21     Nasty() : i_(0) {}
22     Nasty(int i) : i_(i) {}
23     ~Nasty() {}
24 
25     Nasty * operator&() const { assert(false); return nullptr; }
26     int i_;
27     };
28 
29 int main(int, char**)
30 {
31     {
32         std::vector<int> v;
33         assert(v.data() == 0);
34         assert(is_contiguous_container_asan_correct(v));
35     }
36     {
37         std::vector<int> v(100);
38         assert(v.data() == std::addressof(v.front()));
39         assert(is_contiguous_container_asan_correct(v));
40     }
41     {
42         std::vector<Nasty> v(100);
43         assert(v.data() == std::addressof(v.front()));
44         assert(is_contiguous_container_asan_correct(v));
45     }
46 #if TEST_STD_VER >= 11
47     {
48         std::vector<int, min_allocator<int>> v;
49         assert(v.data() == 0);
50         assert(is_contiguous_container_asan_correct(v));
51     }
52     {
53         std::vector<int, min_allocator<int>> v(100);
54         assert(v.data() == std::addressof(v.front()));
55         assert(is_contiguous_container_asan_correct(v));
56     }
57     {
58         std::vector<Nasty, min_allocator<Nasty>> v(100);
59         assert(v.data() == std::addressof(v.front()));
60         assert(is_contiguous_container_asan_correct(v));
61     }
62 #endif
63 
64   return 0;
65 }
66