Can someone at least make a linter that ensures you only use a "safe" subset of C++?
:8:16: warning: passing a dangling pointer as argument [-Wlifetime]
std::cout :7:38: note: temporary was destroyed at the end of the full expression
std::string_view sv = s + "World\n";
^
And cppcheck will catch the second example: :7:12: warning: Returning lambda that captures local variable 'x' that will be invalid when returning. [returnDanglingLifetime]
return [&]() { return *x; };
^
:7:28: note: Lambda captures variable by reference here.
return [&]() { return *x; };
^
:6:49: note: Variable created here.
std::function f(std::shared_ptr x) {
^
:7:12: note: Returning lambda that captures local variable 'x' that will be invalid when returning.
return [&]() { return *x; };
^
Cppcheck could probably catch all the examples, but it needs to be updated to understand the newer classes in C++.