Without this, stack-use-after-scope can only be detected at runtime with ASan or code review, both of which are expensive.
Use LIFETIMEBOUND
to turn this error into a compile warning.
See https://releases.llvm.org/12.0.0/tools/clang/docs/AttributeReference.html#lifetimebound
Example:
0const CScript a{WITH_LOCK(::cs_main, return CScript{} << OP_0 << OP_1)};
Before: (no warning) After:
0warning: returning reference to local temporary object [-Wreturn-stack-address]
1 const CScript a{WITH_LOCK(::cs_main, return CScript{} << OP_0 << OP_1)};
2 ^~~~~~~~~
3./sync.h:276:65: note: expanded from macro 'WITH_LOCK'
4#define WITH_LOCK(cs, code) [&]() -> decltype(auto) { LOCK(cs); code; }()
5 ^~~~