@@ -103,8 +103,10 @@ class ABSL_MUST_USE_RESULT PosixErrorOr {
103103 bool ok () const ;
104104
105105 // Returns a reference to our current value, or CHECK-fails if !this->ok().
106- const T& ValueOrDie () const ;
107- T& ValueOrDie ();
106+ const T& ValueOrDie () const &;
107+ T& ValueOrDie () &;
108+ const T&& ValueOrDie() const &&;
109+ T&& ValueOrDie() &&;
108110
109111 // Ignores any errors. This method does nothing except potentially suppress
110112 // complaints from any tools that are checking that errors are not dropped on
@@ -179,17 +181,29 @@ bool PosixErrorOr<T>::ok() const {
179181}
180182
181183template <typename T>
182- const T& PosixErrorOr<T>::ValueOrDie() const {
184+ const T& PosixErrorOr<T>::ValueOrDie() const & {
183185 TEST_CHECK (absl::holds_alternative<T>(value_));
184186 return absl::get<T>(value_);
185187}
186188
187189template <typename T>
188- T& PosixErrorOr<T>::ValueOrDie() {
190+ T& PosixErrorOr<T>::ValueOrDie() & {
189191 TEST_CHECK (absl::holds_alternative<T>(value_));
190192 return absl::get<T>(value_);
191193}
192194
195+ template <typename T>
196+ const T&& PosixErrorOr<T>::ValueOrDie() const && {
197+ TEST_CHECK (absl::holds_alternative<T>(value_));
198+ return std::move (absl::get<T>(value_));
199+ }
200+
201+ template <typename T>
202+ T&& PosixErrorOr<T>::ValueOrDie() && {
203+ TEST_CHECK (absl::holds_alternative<T>(value_));
204+ return std::move (absl::get<T>(value_));
205+ }
206+
193207extern ::std::ostream& operator <<(::std::ostream& os, const PosixError& e);
194208
195209template <typename T>
@@ -399,7 +413,7 @@ IsPosixErrorOkAndHolds(InnerMatcher&& inner_matcher) {
399413 if (!posixerroror.ok()) { \
400414 return (posixerroror.error ()); \
401415 } \
402- lhs = std::move(posixerroror.ValueOrDie() )
416+ lhs = std::move(posixerroror) .ValueOrDie()
403417
404418#define EXPECT_NO_ERRNO (expression ) \
405419 EXPECT_THAT (expression, IsPosixErrorOkMatcher())
@@ -419,7 +433,7 @@ IsPosixErrorOkAndHolds(InnerMatcher&& inner_matcher) {
419433 ({ \
420434 auto _expr_result = (expr); \
421435 ASSERT_NO_ERRNO (_expr_result); \
422- std::move (_expr_result.ValueOrDie () ); \
436+ std::move (_expr_result) .ValueOrDie (); \
423437 })
424438
425439} // namespace testing
0 commit comments