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>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // pointer data();
125a83710eSEric Fiselier 
135a83710eSEric Fiselier #include <vector>
145a83710eSEric Fiselier #include <cassert>
155a83710eSEric Fiselier 
167fc6a556SMarshall Clow #include "test_macros.h"
175a83710eSEric Fiselier #include "min_allocator.h"
185a83710eSEric Fiselier #include "asan_testing.h"
195a83710eSEric Fiselier 
2081fce972SMarshall Clow struct Nasty {
NastyNasty21*c74059c5SNikolas Klauser     TEST_CONSTEXPR Nasty() : i_(0) {}
NastyNasty22*c74059c5SNikolas Klauser     TEST_CONSTEXPR Nasty(int i) : i_(i) {}
~NastyNasty23*c74059c5SNikolas Klauser     TEST_CONSTEXPR_CXX20 ~Nasty() {}
2481fce972SMarshall Clow 
operator &Nasty2581fce972SMarshall Clow     Nasty * operator&() const { assert(false); return nullptr; }
2681fce972SMarshall Clow     int i_;
2781fce972SMarshall Clow };
2881fce972SMarshall Clow 
tests()29*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 bool tests()
305a83710eSEric Fiselier {
315a83710eSEric Fiselier     {
325a83710eSEric Fiselier         std::vector<int> v;
335a83710eSEric Fiselier         assert(v.data() == 0);
345a83710eSEric Fiselier         assert(is_contiguous_container_asan_correct(v));
355a83710eSEric Fiselier     }
365a83710eSEric Fiselier     {
375a83710eSEric Fiselier         std::vector<int> v(100);
3881fce972SMarshall Clow         assert(v.data() == std::addressof(v.front()));
3981fce972SMarshall Clow         assert(is_contiguous_container_asan_correct(v));
4081fce972SMarshall Clow     }
4181fce972SMarshall Clow     {
4281fce972SMarshall Clow         std::vector<Nasty> v(100);
4381fce972SMarshall Clow         assert(v.data() == std::addressof(v.front()));
445a83710eSEric Fiselier         assert(is_contiguous_container_asan_correct(v));
455a83710eSEric Fiselier     }
46f2f2a639SEric Fiselier #if TEST_STD_VER >= 11
475a83710eSEric Fiselier     {
485a83710eSEric Fiselier         std::vector<int, min_allocator<int>> v;
495a83710eSEric Fiselier         assert(v.data() == 0);
505a83710eSEric Fiselier         assert(is_contiguous_container_asan_correct(v));
515a83710eSEric Fiselier     }
525a83710eSEric Fiselier     {
535a83710eSEric Fiselier         std::vector<int, min_allocator<int>> v(100);
5481fce972SMarshall Clow         assert(v.data() == std::addressof(v.front()));
5581fce972SMarshall Clow         assert(is_contiguous_container_asan_correct(v));
5681fce972SMarshall Clow     }
5781fce972SMarshall Clow     {
5881fce972SMarshall Clow         std::vector<Nasty, min_allocator<Nasty>> v(100);
5981fce972SMarshall Clow         assert(v.data() == std::addressof(v.front()));
605a83710eSEric Fiselier         assert(is_contiguous_container_asan_correct(v));
615a83710eSEric Fiselier     }
625a83710eSEric Fiselier #endif
632df59c50SJF Bastien 
64*c74059c5SNikolas Klauser     return true;
65*c74059c5SNikolas Klauser }
66*c74059c5SNikolas Klauser 
main(int,char **)67*c74059c5SNikolas Klauser int main(int, char**)
68*c74059c5SNikolas Klauser {
69*c74059c5SNikolas Klauser     tests();
70*c74059c5SNikolas Klauser #if TEST_STD_VER > 17
71*c74059c5SNikolas Klauser     static_assert(tests());
72*c74059c5SNikolas Klauser #endif
732df59c50SJF Bastien     return 0;
745a83710eSEric Fiselier }
75