From dcf112f07409003c325f9cbd4b1dda509acc2359 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 23 Jan 2018 09:07:44 -0800 Subject: Changes imported from Abseil "staging" branch: - d7810aa3eadf258776b9c4914df3b3db68791829 absl::optional::value_or(U) now enforces copy/move by Matt Armstrong - 3cc15e447c1851a91dd88e537e5f74faece605a3 Use ABSL_EXCEPTIONS_FLAG instead of -fexceptions in absl/... by Jon Cohen GitOrigin-RevId: d7810aa3eadf258776b9c4914df3b3db68791829 Change-Id: Ib40e22678944b633e734af790449871630f0eeab --- absl/types/optional.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'absl/types/optional.h') diff --git a/absl/types/optional.h b/absl/types/optional.h index ef82559..9858a97 100644 --- a/absl/types/optional.h +++ b/absl/types/optional.h @@ -849,12 +849,20 @@ class optional : private optional_internal::optional_data, // is empty. template constexpr T value_or(U&& v) const& { + static_assert(std::is_copy_constructible::value, + "optional::value_or: T must by copy constructible"); + static_assert(std::is_convertible::value, + "optional::value_or: U must be convertible to T"); return static_cast(*this) ? **this : static_cast(absl::forward(v)); } template T value_or(U&& v) && { // NOLINT(build/c++11) + static_assert(std::is_move_constructible::value, + "optional::value_or: T must by copy constructible"); + static_assert(std::is_convertible::value, + "optional::value_or: U must be convertible to T"); return static_cast(*this) ? std::move(**this) : static_cast(std::forward(v)); } -- cgit v1.2.3