1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5
14 // reference operator[](size_type n);
20 #include "asan_testing.h"
21 #include "min_allocator.h"
22 #include "test_iterators.h"
23 #include "test_macros.h"
25 #ifndef _LIBCPP_HAS_NO_ASAN
26 extern "C" void __sanitizer_set_death_callback(void (*callback)(void));
34 #if TEST_STD_VER >= 11
37 typedef std::vector<T, min_allocator<T>> C;
38 const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
39 C c(std::begin(t), std::end(t));
40 c.reserve(2*c.size());
41 volatile T foo = c[c.size()]; // bad, but not caught by ASAN
47 typedef input_iterator<int*> MyInputIter;
48 // Sould not trigger ASan.
52 v.insert(v.begin(), MyInputIter(i), MyInputIter(i + 1));
54 assert(is_contiguous_container_asan_correct(v));
57 __sanitizer_set_death_callback(do_exit);
60 typedef std::vector<T> C;
61 const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
62 C c(std::begin(t), std::end(t));
63 c.reserve(2*c.size());
64 assert(is_contiguous_container_asan_correct(c));
65 assert(!__sanitizer_verify_contiguous_container( c.data(), c.data() + 1, c.data() + c.capacity()));
66 volatile T foo = c[c.size()]; // should trigger ASAN. Use volatile to prevent being optimized away.
67 assert(false); // if we got here, ASAN didn't trigger
72 int main () { return 0; }