Outline `Optional::require_value()`
[folly.git] / folly / Optional.h
index 5350b2ee5e44d69c55868c0a96e2e24d286a16fb..6b49f1ab3b3a7507e3b16ad352e95f75b154e729 100644 (file)
 
 namespace folly {
 
-namespace detail { struct NoneHelper {}; }
+namespace detail {
+struct NoneHelper {};
+
+// Allow each translation unit to control its own -fexceptions setting.
+// If exceptions are disabled, std::terminate() will be called instead of
+// throwing OptionalEmptyException when the condition fails.
+[[noreturn]] void throw_optional_empty_exception();
+}
 
 typedef int detail::NoneHelper::*None;
 
@@ -252,7 +259,7 @@ class Optional {
  private:
   void require_value() const {
     if (!storage_.hasValue) {
-      throw OptionalEmptyException();
+      detail::throw_optional_empty_exception();
     }
   }