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