1// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2
3#include "defines.h"
4#include <functional>
5
6int main() {
7 std::function<int()> f;
8 {
9 int x = 0;
10 f = [&x]() ATTRIBUTE_NOINLINE {
11 return x; // BOOM
12 // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
13 // We cannot assert the line, after the argument promotion pass this crashes
14 // in the BOOM line below instead, when the ref gets turned into a value.
15 // CHECK: #0 0x{{.*}} in {{.*}}use-after-scope-capture.cpp
16 };
17 }
18 return f(); // BOOM
19}
20

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of compiler-rt/test/asan/TestCases/use-after-scope-capture.cpp