From 944ac56baa7739a79295e5157afd99cb93a3a809 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 3 Dec 2025 16:10:25 +0100 Subject: [PATCH] Fix behavior of prefix increment/decrement --- include/boost/int128/detail/int128_imp.hpp | 26 ++++++++------------- include/boost/int128/detail/uint128_imp.hpp | 16 ++++++++----- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/include/boost/int128/detail/int128_imp.hpp b/include/boost/int128/detail/int128_imp.hpp index ec5eb8f1..4e5fbc0f 100644 --- a/include/boost/int128/detail/int128_imp.hpp +++ b/include/boost/int128/detail/int128_imp.hpp @@ -188,11 +188,11 @@ int128_t // Prefix and postfix increment constexpr int128_t& operator++() noexcept; - constexpr int128_t& operator++(int) noexcept; + constexpr int128_t operator++(int) noexcept; // Prefix and postfix decrment constexpr int128_t& operator--() noexcept; - constexpr int128_t& operator--(int) noexcept; + constexpr int128_t operator--(int) noexcept; // Compound Addition template @@ -2005,14 +2005,11 @@ constexpr int128_t& int128_t::operator++() noexcept return *this; } -constexpr int128_t& int128_t::operator++(int) noexcept +constexpr int128_t int128_t::operator++(int) noexcept { - if (++low == UINT64_C(0)) - { - ++high; - } - - return *this; + const auto temp {*this}; + ++(*this); + return temp; } //===================================== @@ -2029,14 +2026,11 @@ constexpr int128_t& int128_t::operator--() noexcept return *this; } -constexpr int128_t& int128_t::operator--(int) noexcept +constexpr int128_t int128_t::operator--(int) noexcept { - if (low-- == UINT64_C(0)) - { - --high; - } - - return *this; + const auto temp {*this}; + --(*this); + return temp; } //===================================== diff --git a/include/boost/int128/detail/uint128_imp.hpp b/include/boost/int128/detail/uint128_imp.hpp index ab44f4d7..09b97611 100644 --- a/include/boost/int128/detail/uint128_imp.hpp +++ b/include/boost/int128/detail/uint128_imp.hpp @@ -198,9 +198,9 @@ uint128_t #endif // BOOST_INT128_HAS_MSVC_INT128 constexpr uint128_t& operator++() noexcept; - constexpr uint128_t& operator++(int) noexcept; + constexpr uint128_t operator++(int) noexcept; constexpr uint128_t& operator--() noexcept; - constexpr uint128_t& operator--(int) noexcept; + constexpr uint128_t operator--(int) noexcept; // Compound Addition template @@ -2035,9 +2035,11 @@ constexpr uint128_t& uint128_t::operator++() noexcept return *this; } -constexpr uint128_t& uint128_t::operator++(int) noexcept +constexpr uint128_t uint128_t::operator++(int) noexcept { - return ++(*this); + const auto temp {*this}; + ++(*this); + return temp; } //===================================== @@ -2054,9 +2056,11 @@ constexpr uint128_t& uint128_t::operator--() noexcept return *this; } -constexpr uint128_t& uint128_t::operator--(int) noexcept +constexpr uint128_t uint128_t::operator--(int) noexcept { - return --(*this); + const auto temp {*this}; + --(*this); + return temp; } //=====================================