Something went wrong. Try again.
A Tour of C++ for experienced programmers, as if C++26 is the only version that ever existed.
Something went wrong. Try again.
12345678910111213141516171819// DEMO: deliberately wrong. This file exists to produce a diagnostic.// The function returns a pointer to a dead local. The lifetime-safety// analysis and the plain -Wreturn-stack-address warning both catch it.//// examples/ch01/ch01_dangling.cpp:9:13: warning: address of stack memory// associated with local variable 'x' returned [-Wreturn-stack-address]// 9 | return &x;// | ^
int* bad() { int x = 42; return &x;}
int main() { int* p = bad(); return *p;}