1 // RUN: %clangxx_asan %stdcxx11 -O1 -fsanitize-address-use-after-scope %s -o %t && \ 2 // RUN: not %run %t 2>&1 | FileCheck %s 3 4 5 struct IntHolder { 6 __attribute__((noinline)) const IntHolder &Self() const { 7 return *this; 8 } 9 int val = 3; 10 }; 11 12 const IntHolder *saved; 13 14 int main(int argc, char *argv[]) { 15 saved = &IntHolder().Self(); 16 int x = saved->val; // BOOM 17 // CHECK: ERROR: AddressSanitizer: stack-use-after-scope 18 // CHECK: #0 0x{{.*}} in main {{.*}}use-after-scope-temp2.cpp:[[@LINE-2]] 19 return x; 20 } 21