about summary refs log tree commit diff
path: root/absl/types
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-01-23T17·07-0800
committerJohn Olson <jolson@google.com>2018-01-23T23·05-0500
commitdcf112f07409003c325f9cbd4b1dda509acc2359 (patch)
treeefba63881185cc623d34b3bc18ff254b084e8d96 /absl/types
parent787891a3882795cee0364e8a0f0dda315578d155 (diff)
Changes imported from Abseil "staging" branch:
  - d7810aa3eadf258776b9c4914df3b3db68791829 absl::optional<T>::value_or(U) now enforces copy/move by Matt Armstrong <marmstrong@google.com>
  - 3cc15e447c1851a91dd88e537e5f74faece605a3 Use ABSL_EXCEPTIONS_FLAG instead of -fexceptions in absl/... by Jon Cohen <cohenjon@google.com>

GitOrigin-RevId: d7810aa3eadf258776b9c4914df3b3db68791829
Change-Id: Ib40e22678944b633e734af790449871630f0eeab
Diffstat (limited to 'absl/types')
-rw-r--r--absl/types/optional.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/absl/types/optional.h b/absl/types/optional.h
index ef8255915746..9858a9749766 100644
--- a/absl/types/optional.h
+++ b/absl/types/optional.h
@@ -849,12 +849,20 @@ class optional : private optional_internal::optional_data<T>,
   // is empty.
   template <typename U>
   constexpr T value_or(U&& v) const& {
+    static_assert(std::is_copy_constructible<value_type>::value,
+                  "optional<T>::value_or: T must by copy constructible");
+    static_assert(std::is_convertible<U&&, value_type>::value,
+                  "optional<T>::value_or: U must be convertible to T");
     return static_cast<bool>(*this)
                ? **this
                : static_cast<T>(absl::forward<U>(v));
   }
   template <typename U>
   T value_or(U&& v) && {  // NOLINT(build/c++11)
+    static_assert(std::is_move_constructible<value_type>::value,
+                  "optional<T>::value_or: T must by copy constructible");
+    static_assert(std::is_convertible<U&&, value_type>::value,
+                  "optional<T>::value_or: U must be convertible to T");
     return static_cast<bool>(*this) ? std::move(**this)
                                     : static_cast<T>(std::forward<U>(v));
   }