diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-11-25 15:18:28 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-11-25 15:18:33 +0100 |
commit | 5c0aebfcd42a3effe2496ecef623302da64cd9a3 (patch) | |
tree | 0a1276c85dd0ec832abcda36c447cde246d4bb26 /src/Makefile.bench.include | |
parent | afdfd3c8c1ce96adae11809e3989de381137fee9 (diff) | |
parent | e3e7446305329ce96e9cf5f5161658eb2e1ea888 (diff) |
Merge #19387: span: update constructors to match c++20 draft spec and add lifetimebound attribute
e3e7446305329ce96e9cf5f5161658eb2e1ea888 Add lifetimebound to attributes for general-purpose usage (Cory Fields)
1d58cc7cb040a70f768b632f294db4e0797d3a34 span: add lifetimebound attribute (Cory Fields)
62733fee874bfe7e833e71380eb8efd6a3126fbd span: (almost) match std::span's constructor behavior (Cory Fields)
Pull request description:
Replaces #19382 with a different approach. See [this comment](https://github.com/bitcoin/bitcoin/pull/19382#discussion_r446332852) for the reasoning behind the switch.
--
Description from #19382:
See [here](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0936r0.pdf) 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:
```c++
Span<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<const int> bad(std::vector<int>{1,2,3});
```
ACKs for top commit:
sipa:
ACK e3e7446305329ce96e9cf5f5161658eb2e1ea888
ajtowns:
ACK e3e7446305329ce96e9cf5f5161658eb2e1ea888 (drive by; only a quick skim of code and some basic sanity checks)
MarcoFalke:
review ACK e3e7446305329ce96e9cf5f5161658eb2e1ea888 🔗
jonatack:
ACK e3e7446 change since last review is adding `[[clang::lifetimebound]]` as `LIFETIMEBOUND` to src/attributes.h as suggested in https://github.com/bitcoin/bitcoin/pull/19387#issuecomment-650752959.
Tree-SHA512: 05a3440ee595ef0e8d693a2820b360707695c016a68e15df47c20cd8d053646cc6c8cca8addd7db40e72b3fce208879a41c8102ba7ae9223e4366e5de1175211
Diffstat (limited to 'src/Makefile.bench.include')
0 files changed, 0 insertions, 0 deletions