From cba7a26a3ff80dd159845d3fc33793cffc3e301f Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 17 Aug 2021 18:48:32 -0700 Subject: [PATCH] Fix _Convert_size noexcept bug, use `if constexpr`. --- stl/inc/xmemory | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/stl/inc/xmemory b/stl/inc/xmemory index 29f2c2afb3..81e476ab1f 100644 --- a/stl/inc/xmemory +++ b/stl/inc/xmemory @@ -949,21 +949,17 @@ _CONSTEXPR20 void _Destroy_range(_NoThrowFwdIt _First, const _NoThrowSentinel _L } template -_NODISCARD constexpr _Size_type _Convert_size(const size_t _Len) noexcept { +_NODISCARD constexpr _Size_type _Convert_size(const size_t _Len) noexcept(is_same_v<_Size_type, size_t>) { // convert size_t to _Size_type, avoiding truncation - if (_Len > (numeric_limits<_Size_type>::max) ()) { - _Xlength_error("size_t too long for _Size_type"); + if constexpr (!is_same_v<_Size_type, size_t>) { + if (_Len > (numeric_limits<_Size_type>::max) ()) { + _Xlength_error("size_t too long for _Size_type"); + } } return static_cast<_Size_type>(_Len); } -template <> -_NODISCARD constexpr size_t _Convert_size(const size_t _Len) noexcept { - // convert size_t to size_t, unchanged - return _Len; -} - template _CONSTEXPR20 void _Deallocate_plain(_Alloc& _Al, typename _Alloc::value_type* const _Ptr) noexcept { // deallocate a plain pointer using an allocator