Skip to content

Commit

Permalink
replace _Throw_bad_variant_access
Browse files Browse the repository at this point in the history
  • Loading branch information
achabense committed Aug 30, 2023
1 parent ee2508f commit a9190c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
21 changes: 0 additions & 21 deletions stl/inc/exception
Original file line number Diff line number Diff line change
Expand Up @@ -389,27 +389,6 @@ _EXPORT_STD template <class _Ty>
void rethrow_if_nested(const _Ty&) = delete; // requires /GR option
#endif // ^^^ !defined(_CPPRTTI) ^^^

_EXPORT_STD class bad_variant_access
: public exception { // exception for visit of a valueless variant or get<I> on a variant with index() != I
public:
bad_variant_access() noexcept = default;

_NODISCARD const char* __CLR_OR_THIS_CALL what() const noexcept override {
return "bad variant access";
}

#if !_HAS_EXCEPTIONS
protected:
void _Doraise() const override { // perform class-specific exception handling
_RAISE(*this);
}
#endif // ^^^ !_HAS_EXCEPTIONS ^^^
};

[[noreturn]] inline void _Throw_bad_variant_access() {
_THROW(bad_variant_access{});
}

_STD_END

#pragma pop_macro("new")
Expand Down
16 changes: 10 additions & 6 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -4246,7 +4246,7 @@ namespace ranges {
} else if (_Inner_it._Contains == _Variantish_state::_Holds_second) {
return _Func(_Inner_it._Get_second());
} else {
_STD _Throw_bad_variant_access();
_Xinvalid_iterator();
}
}

Expand Down Expand Up @@ -4279,6 +4279,10 @@ namespace ranges {
}
}

[[noreturn]] static void _Xinvalid_iterator() {
_Xinvalid_argument("_Inner_it has been invalid due to a failure in _Emplace_first or _Emplace_second");
}

public:
using iterator_concept =
conditional_t<_Deref_is_glvalue && bidirectional_range<_Base> && _Bidi_common_range<_InnerRng<_Const>>
Expand Down Expand Up @@ -4306,7 +4310,7 @@ namespace ranges {
_Inner_it._Emplace_second(_STD move(_It._Inner_it._Get_second()));
break;
case _Variantish_state::_Nothing:
_STD _Throw_bad_variant_access();
_Xinvalid_iterator();
}
}

Expand All @@ -4324,7 +4328,7 @@ namespace ranges {
++_Inner_it._Get_second();
break;
case _Variantish_state::_Nothing:
_STD _Throw_bad_variant_access();
_Xinvalid_iterator();
}
_Satisfy();
return *this;
Expand Down Expand Up @@ -4369,7 +4373,7 @@ namespace ranges {
break;
}
} else {
_STD _Throw_bad_variant_access();
_Xinvalid_iterator();
}
}

Expand All @@ -4381,7 +4385,7 @@ namespace ranges {
--_Inner_it._Get_second();
break;
case _Variantish_state::_Nothing:
_STD _Throw_bad_variant_access();
_Xinvalid_iterator();
}
return *this;
}
Expand Down Expand Up @@ -4452,7 +4456,7 @@ namespace ranges {
break;
}

_STD _Throw_bad_variant_access();
_Xinvalid_iterator();
}
};

Expand Down
21 changes: 21 additions & 0 deletions stl/inc/variant
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,27 @@ private:
}
};

_EXPORT_STD class bad_variant_access
: public exception { // exception for visit of a valueless variant or get<I> on a variant with index() != I
public:
bad_variant_access() noexcept = default;

_NODISCARD const char* __CLR_OR_THIS_CALL what() const noexcept override {
return "bad variant access";
}

#if !_HAS_EXCEPTIONS
protected:
void _Doraise() const override { // perform class-specific exception handling
_RAISE(*this);
}
#endif // ^^^ !_HAS_EXCEPTIONS ^^^
};

[[noreturn]] inline void _Throw_bad_variant_access() {
_THROW(bad_variant_access{});
}

_EXPORT_STD template <class _Ty, class... _Types>
_NODISCARD constexpr bool holds_alternative(const variant<_Types...>& _Var) noexcept {
// true iff _Var holds alternative _Ty
Expand Down

0 comments on commit a9190c7

Please sign in to comment.