Add an _LIBCPP_NORETURN inline function named __throw_XXX for each exception type we define. They either construct and throw the exception, or abort() (if exceptions are disabled). Use these functions everywhere instead of assert()ing when exceptions are disabled. WARNING: This is a behavior change - but only with exceptions disabled. Reviewed as: https://reviews.llvm.org/D23855.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@279744 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2016-08-25 15:09:01 +00:00
parent fdb4f1713e
commit 14c09a2413
30 changed files with 272 additions and 288 deletions

View File

@@ -513,15 +513,21 @@ public:
_LIBCPP_INLINE_VISIBILITY
constexpr explicit operator bool() const noexcept {return this->__engaged_;}
_LIBCPP_NORETURN _LIBCPP_INLINE_VISIBILITY
constexpr void __throw_bad_optional_access() const
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_optional_access();
#else
_VSTD::abort();
#endif
}
_LIBCPP_INLINE_VISIBILITY
constexpr value_type const& value() const
{
if (!this->__engaged_)
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_optional_access();
#else
assert(!"bad optional access");
#endif
__throw_bad_optional_access();
return this->__val_;
}
@@ -529,11 +535,7 @@ public:
value_type& value()
{
if (!this->__engaged_)
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_optional_access();
#else
assert(!"bad optional access");
#endif
__throw_bad_optional_access();
return this->__val_;
}