Commit ac96eb79 authored by Marshall Cline's avatar Marshall Cline Committed by Facebook Github Bot

improve compile-time errmsg for f.get()

Summary:
We have seen some caller-confusion after removing the lvalue-qualified Future::get().

Goal of this is to improve/clarify the compile-time error-msg for `future.get()`.

The resulting error-messages are compiler-dependent, but generally they are more explicit, indicating an explicit deletion of the lvalue-qualified method, and in some cases also displaying the deprecation-message:

* Clang:
  * old: 'this' argument to member function 'get' is an lvalue, but function has rvalue ref-qualifier
  * new: call to deleted member function 'get': must be rvalue-qualified, e.g., std::move(future).get()
* gcc:
  * old: error: passing 'Future<int>' as 'this' argument discards qualifiers [-fpermissive]
  * new: use of deleted function 'T Future<T>::get() & [with T = int]'
* MS VC:
  * old: 'int Future<int>::get(void) &&': cannot convert 'this' pointer from 'Future<int>' to 'Future<int> &&'
  * new: 'int Future<int>::get(void) &': attempting to reference a deleted function
* icc:
  * old: function "Future<T>::get [with T=int]" (declared at line 6) cannot be called on an lvalue
  * new: function "Future<T>::get() & [with T=int]" (declared at line 9) was declared deprecated ("must be rvalue-qualified, e.g., std::move(future).get()")

Reviewed By: yfeldblum

Differential Revision: D9071064

fbshipit-source-id: a40712ce94fd10bc153cb74a7d6d6a0539e07a15
parent 359eb495
...@@ -578,6 +578,9 @@ class SemiFuture : private futures::detail::FutureBase<T> { ...@@ -578,6 +578,9 @@ class SemiFuture : private futures::detail::FutureBase<T> {
/// - `valid() == false` /// - `valid() == false`
T get() &&; T get() &&;
[[deprecated("must be rvalue-qualified, e.g., std::move(future).get()")]] T
get() & = delete;
/// Blocks until the semifuture is fulfilled, or until `dur` elapses. Returns /// Blocks until the semifuture is fulfilled, or until `dur` elapses. Returns
/// the value (moved-out), or throws the exception (which might be a /// the value (moved-out), or throws the exception (which might be a
/// FutureTimeout exception). /// FutureTimeout exception).
...@@ -591,6 +594,9 @@ class SemiFuture : private futures::detail::FutureBase<T> { ...@@ -591,6 +594,9 @@ class SemiFuture : private futures::detail::FutureBase<T> {
/// - `valid() == false` /// - `valid() == false`
T get(Duration dur) &&; T get(Duration dur) &&;
[[deprecated("must be rvalue-qualified, e.g., std::move(future).get(dur)")]] T
get(Duration dur) & = delete;
/// Blocks until the future is fulfilled. Returns the Try of the result /// Blocks until the future is fulfilled. Returns the Try of the result
/// (moved-out). /// (moved-out).
/// ///
...@@ -1562,6 +1568,9 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1562,6 +1568,9 @@ class Future : private futures::detail::FutureBase<T> {
/// - `valid() == false` /// - `valid() == false`
T get() &&; T get() &&;
[[deprecated("must be rvalue-qualified, e.g., std::move(future).get()")]] T
get() & = delete;
/// Blocks until the future is fulfilled, or until `dur` elapses. Returns the /// Blocks until the future is fulfilled, or until `dur` elapses. Returns the
/// value (moved-out), or throws the exception (which might be a FutureTimeout /// value (moved-out), or throws the exception (which might be a FutureTimeout
/// exception). /// exception).
...@@ -1575,6 +1584,9 @@ class Future : private futures::detail::FutureBase<T> { ...@@ -1575,6 +1584,9 @@ class Future : private futures::detail::FutureBase<T> {
/// - `valid() == false` /// - `valid() == false`
T get(Duration dur) &&; T get(Duration dur) &&;
[[deprecated("must be rvalue-qualified, e.g., std::move(future).get(dur)")]] T
get(Duration dur) & = delete;
/// A reference to the Try of the value /// A reference to the Try of the value
/// ///
/// Preconditions: /// Preconditions:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment