diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-06-28 12:59:34 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:49:34 +0100 |
commit | 894f558c6e3d4c54de1bef6aa369aa16c72fe687 (patch) | |
tree | acc2525681aa736cfee325170088701b78cb55d6 /gcc | |
parent | c3d5d8bee12e5e18d89db6126fbdd0edde110bf7 (diff) | |
download | gcc-894f558c6e3d4c54de1bef6aa369aa16c72fe687.zip gcc-894f558c6e3d4c54de1bef6aa369aa16c72fe687.tar.gz gcc-894f558c6e3d4c54de1bef6aa369aa16c72fe687.tar.bz2 |
gccrs: optional: Adapt class to GCC's standards.
This commit removes the poisoned includes as well as the exception throwing
mechanism of the original class.
gcc/rust/ChangeLog:
* util/optional.h: Adapt for GCC.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/util/optional.h | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/gcc/rust/util/optional.h b/gcc/rust/util/optional.h index 2b48c45d..4518b42 100644 --- a/gcc/rust/util/optional.h +++ b/gcc/rust/util/optional.h @@ -1,3 +1,4 @@ +// clang-format off /// // optional - An implementation of std::optional with extensions @@ -21,11 +22,7 @@ #define TL_OPTIONAL_VERSION_MINOR 1 #define TL_OPTIONAL_VERSION_PATCH 0 -#include <exception> -#include <functional> -#include <new> -#include <type_traits> -#include <utility> +#include "rust-system.h" #if (defined(_MSC_VER) && _MSC_VER == 1900) #define TL_OPTIONAL_MSVC2015 @@ -664,12 +661,6 @@ struct nullopt_t { static constexpr nullopt_t nullopt{nullopt_t::do_not_use{}, nullopt_t::do_not_use{}}; -class bad_optional_access : public std::exception { -public: - bad_optional_access() = default; - const char *what() const noexcept { return "Optional has no value"; } -}; - /// An optional object is an object that contains the storage for another /// object and manages the lifetime of this contained object, if any. The /// contained object may be initialized after the optional object has been @@ -1289,24 +1280,28 @@ public: TL_OPTIONAL_11_CONSTEXPR T &value() & { if (has_value()) return this->m_value; - throw bad_optional_access(); + + gcc_unreachable(); } TL_OPTIONAL_11_CONSTEXPR const T &value() const & { if (has_value()) return this->m_value; - throw bad_optional_access(); + + gcc_unreachable(); } TL_OPTIONAL_11_CONSTEXPR T &&value() && { if (has_value()) return std::move(this->m_value); - throw bad_optional_access(); + + gcc_unreachable(); } #ifndef TL_OPTIONAL_NO_CONSTRR TL_OPTIONAL_11_CONSTEXPR const T &&value() const && { if (has_value()) return std::move(this->m_value); - throw bad_optional_access(); + + gcc_unreachable(); } #endif @@ -2012,12 +2007,14 @@ public: TL_OPTIONAL_11_CONSTEXPR T &value() { if (has_value()) return *m_value; - throw bad_optional_access(); + + gcc_unreachable(); } TL_OPTIONAL_11_CONSTEXPR const T &value() const { if (has_value()) return *m_value; - throw bad_optional_access(); + + gcc_unreachable(); } /// Returns the stored value if there is one, otherwise returns `u` |