xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/use-after-scope-capture.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1 // RUN: %clangxx_asan -std=c++11 -O1 -fsanitize-address-use-after-scope %s -o %t && \
2 // RUN:     not %run %t 2>&1 | FileCheck %s
3 
4 #include <functional>
5 
main()6 int main() {
7   std::function<int()> f;
8   {
9     int x = 0;
10     f = [&x]() {
11       return x;  // BOOM
12       // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
13       // CHECK: #0 0x{{.*}} in {{.*}}use-after-scope-capture.cc:[[@LINE-2]]
14     };
15   }
16   return f();  // BOOM
17 }
18