Skip to content

Commit 7565738

Browse files
_Convert_size() should be conditionally noexcept (#2139)
1 parent dd20f56 commit 7565738

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

stl/inc/xmemory

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -949,21 +949,17 @@ _CONSTEXPR20 void _Destroy_range(_NoThrowFwdIt _First, const _NoThrowSentinel _L
949949
}
950950

951951
template <class _Size_type>
952-
_NODISCARD constexpr _Size_type _Convert_size(const size_t _Len) noexcept {
952+
_NODISCARD constexpr _Size_type _Convert_size(const size_t _Len) noexcept(is_same_v<_Size_type, size_t>) {
953953
// convert size_t to _Size_type, avoiding truncation
954-
if (_Len > (numeric_limits<_Size_type>::max) ()) {
955-
_Xlength_error("size_t too long for _Size_type");
954+
if constexpr (!is_same_v<_Size_type, size_t>) {
955+
if (_Len > (numeric_limits<_Size_type>::max) ()) {
956+
_Xlength_error("size_t too long for _Size_type");
957+
}
956958
}
957959

958960
return static_cast<_Size_type>(_Len);
959961
}
960962

961-
template <>
962-
_NODISCARD constexpr size_t _Convert_size<size_t>(const size_t _Len) noexcept {
963-
// convert size_t to size_t, unchanged
964-
return _Len;
965-
}
966-
967963
template <class _Alloc>
968964
_CONSTEXPR20 void _Deallocate_plain(_Alloc& _Al, typename _Alloc::value_type* const _Ptr) noexcept {
969965
// deallocate a plain pointer using an allocator

0 commit comments

Comments
 (0)