gcc/testsuite/g++.dg/asan/use-after-scope-types.h
raw| 1 | #include <stdlib.h> |
| 2 | #include <string> |
| 3 | #include <vector> |
| 4 | |
| 5 | template <class T> struct Ptr { |
| 6 | void Store(T *ptr) { t = ptr; } |
| 7 | |
| 8 | void Access() { *t = {}; } |
| 9 | |
| 10 | T *t; |
| 11 | }; |
| 12 | |
| 13 | template <class T, size_t N> struct Ptr<T[N]> { |
| 14 | using Type = T[N]; |
| 15 | void Store(Type *ptr) { t = *ptr; } |
| 16 | |
| 17 | void Access() { *t = {}; } |
| 18 | |
| 19 | T *t; |
| 20 | }; |
| 21 | |
| 22 | template <class T> __attribute__((noinline)) void test() { |
| 23 | Ptr<T> ptr; |
| 24 | { |
| 25 | T x; |
| 26 | ptr.Store(&x); |
| 27 | } |
| 28 | |
| 29 | ptr.Access(); |
| 30 | } |