Debian Codegraph @

gcc/testsuite/g++.dg/analyzer/pr93212.C

raw
1 // { dg-do compile { target c++14 } }
2 // { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } }
3
4 #include <iostream>
5 auto lol()
6 {
7 int aha = 3;
8 return [&aha] {
9 return aha; // { dg-warning "dereferencing pointer '.*' to within stale stack frame" }
10 };
11 /* TODO: may be worth special-casing the reporting of dangling
12 references from lambdas, to highlight the declaration, and maybe fix
13 the wording (it's a reference, not a pointer, for one thing). */
14 }
15
16 int main()
17 {
18 auto lambda = lol();
19 std::cout << lambda() << std::endl;
20 return 0;
21 }