diff options
author | Eric Fiselier <eric@efcs.ca> | 2018-01-12 00:09:37 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2018-01-12 00:09:37 +0000 |
commit | 1af6c114cc3675866d229e3c1d496f2128744482 (patch) | |
tree | ce554d48bcb8e3b286e297937228651424bf738a /llvm/lib/Object/WasmObjectFile.cpp | |
parent | cd65f698082b6055d9b3383c119f6da3d6559643 (diff) | |
download | llvm-1af6c114cc3675866d229e3c1d496f2128744482.zip llvm-1af6c114cc3675866d229e3c1d496f2128744482.tar.gz llvm-1af6c114cc3675866d229e3c1d496f2128744482.tar.bz2 |
Add `__reference_binds_to_temporary` trait for checking safe reference initialization.
Summary:
The STL types `std::pair` and `std::tuple` can both store reference types. However their constructors cannot adequately check if the initialization of reference types is safe. For example:
```
std::tuple<std::tuple<int> const&> t = 42;
// The stored reference is already dangling.
```
Libc++ has a best effort attempts in tuple to diagnose this, but they're not able to handle all valid cases (If I'm not mistaken). For example initialization of a reference from the result of a class's conversion operator. Libc++ would benefit from having a builtin traits which can provide a much better implementation.
This patch introduce the `__reference_binds_to_temporary(T, U)` trait that determines whether a reference of type `T` bound to an expression of type `U` would bind to a materialized temporary object.
Note that the trait simply returns false if `T` is not a reference type instead of reporting it as an error.
```
static_assert(__is_constructible(int const&, long));
static_assert(__reference_binds_to_temporary(int const&, long));
```
Reviewers: majnemer, rsmith
Reviewed By: rsmith
Subscribers: compnerd, cfe-commits
Differential Revision: https://reviews.llvm.org/D29930
llvm-svn: 322334
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
0 files changed, 0 insertions, 0 deletions