1// RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \
2// RUN:     %run %t 2>&1 | FileCheck %s
3//
4// Lifetime for temporaries is not emitted yet.
5// XFAIL: *
6
7#include <stdio.h>
8
9struct IntHolder {
10  explicit IntHolder(int val) : val(val) {
11    printf("IntHolder: %d\n", val);
12  }
13  int val;
14};
15
16const IntHolder *saved;
17
18void save(const IntHolder &holder) {
19  saved = &holder;
20}
21
22int main(int argc, char *argv[]) {
23  save(IntHolder(10));
24  int x = saved->val;  // BOOM
25  // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
26  // CHECK:  #0 0x{{.*}} in main {{.*}}use-after-scope-temp.cc:[[@LINE-2]]
27  printf("saved value: %d\n", x);
28  return 0;
29}
30