Replaces #19382 with a different approach. See this comment for the reasoning behind the switch.
–
Description from #19382:
See here for more detail on lifetimebound.
This is implemented using preprocesor macros rather than configure checks in order to keep span.h self-contained.
The [[clang::lifetimebound]]
syntax was chosen over __attribute__((lifetimebound))
because the former is more flexible and works to guard this
as well as function parameters, and also because at least for now, it’s available only in clang.
There are currently no violations in our codebase, but this can easily be tested by inserting one like this somewhere and compiling with a modern clang:
0Span<const int> bad(std::vector<int>{1,2,3});
The result:
warning: temporary whose address is used as value of local variable ‘bad’ will be destroyed at the end of the full-expression [-Wdangling] Span bad(std::vector{1,2,3});