Skip to content

Commit ddd4043

Browse files
authored
Merge pull request #1263 from cppalliance/inc_dec
Fix return value & type of post-fix increment/decrement
2 parents 5b42457 + 8587443 commit ddd4043

File tree

8 files changed

+48
-24
lines changed

8 files changed

+48
-24
lines changed

include/boost/decimal/decimal128_t.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,9 @@ constexpr auto decimal128_t::operator++() noexcept -> decimal128_t&
20132013

20142014
constexpr auto decimal128_t::operator++(int) noexcept -> decimal128_t
20152015
{
2016-
return ++(*this);
2016+
const auto temp {*this};
2017+
++(*this);
2018+
return temp;
20172019
}
20182020

20192021
constexpr auto decimal128_t::operator--() noexcept -> decimal128_t&
@@ -2025,7 +2027,9 @@ constexpr auto decimal128_t::operator--() noexcept -> decimal128_t&
20252027

20262028
constexpr auto decimal128_t::operator--(int) noexcept -> decimal128_t
20272029
{
2028-
return --(*this);
2030+
const auto temp {*this};
2031+
--(*this);
2032+
return temp;
20292033
}
20302034

20312035
constexpr auto decimal128_t::operator+=(const decimal128_t rhs) noexcept -> decimal128_t&

include/boost/decimal/decimal32_t.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,9 @@ constexpr auto decimal32_t::operator++() noexcept -> decimal32_t&
10991099

11001100
constexpr auto decimal32_t::operator++(int) noexcept -> decimal32_t
11011101
{
1102-
return ++(*this);
1102+
const auto temp {*this};
1103+
++(*this);
1104+
return temp;
11031105
}
11041106

11051107
constexpr auto decimal32_t::operator+=(const decimal32_t rhs) noexcept -> decimal32_t&
@@ -1221,7 +1223,9 @@ constexpr auto decimal32_t::operator--() noexcept -> decimal32_t&
12211223

12221224
constexpr auto decimal32_t::operator--(int) noexcept -> decimal32_t
12231225
{
1224-
return --(*this);
1226+
const auto temp {*this};
1227+
--(*this);
1228+
return temp;
12251229
}
12261230

12271231
constexpr auto decimal32_t::operator-=(const decimal32_t rhs) noexcept -> decimal32_t&

include/boost/decimal/decimal64_t.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,9 @@ constexpr auto decimal64_t::operator++() noexcept -> decimal64_t&
19921992

19931993
constexpr auto decimal64_t::operator++(int) noexcept -> decimal64_t
19941994
{
1995-
return ++(*this);
1995+
const auto temp {*this};
1996+
++(*this);
1997+
return temp;
19961998
}
19971999

19982000
constexpr auto decimal64_t::operator--() noexcept -> decimal64_t&
@@ -2004,7 +2006,9 @@ constexpr auto decimal64_t::operator--() noexcept -> decimal64_t&
20042006

20052007
constexpr auto decimal64_t::operator--(int) noexcept -> decimal64_t
20062008
{
2007-
return --(*this);
2009+
const auto temp {*this};
2010+
--(*this);
2011+
return temp;
20082012
}
20092013

20102014
constexpr auto decimal64_t::operator+=(const decimal64_t rhs) noexcept -> decimal64_t&

include/boost/decimal/decimal_fast128_t.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,9 @@ constexpr auto decimal_fast128_t::operator++() noexcept -> decimal_fast128_t&
14721472

14731473
constexpr auto decimal_fast128_t::operator++(int) noexcept -> decimal_fast128_t
14741474
{
1475-
return ++(*this);
1475+
const auto temp {*this};
1476+
++(*this);
1477+
return temp;
14761478
}
14771479

14781480
constexpr auto decimal_fast128_t::operator--() noexcept -> decimal_fast128_t&
@@ -1484,7 +1486,9 @@ constexpr auto decimal_fast128_t::operator--() noexcept -> decimal_fast128_t&
14841486

14851487
constexpr auto decimal_fast128_t::operator--(int) noexcept -> decimal_fast128_t
14861488
{
1487-
return --(*this);
1489+
const auto temp {*this};
1490+
--(*this);
1491+
return temp;
14881492
}
14891493

14901494
constexpr decimal_fast128_t::operator bool() const noexcept

include/boost/decimal/decimal_fast32_t.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ BOOST_DECIMAL_EXPORT class decimal_fast32_t final
420420

421421
// Increment and decrement
422422
constexpr auto operator++() noexcept -> decimal_fast32_t&;
423-
constexpr auto operator++(int) noexcept -> decimal_fast32_t&;
423+
constexpr auto operator++(int) noexcept -> decimal_fast32_t;
424424
constexpr auto operator--() noexcept -> decimal_fast32_t&;
425-
constexpr auto operator--(int) noexcept -> decimal_fast32_t&;
425+
constexpr auto operator--(int) noexcept -> decimal_fast32_t;
426426

427427
// 3.2.2.4 Conversion to integral type
428428
explicit constexpr operator bool() const noexcept;
@@ -1430,9 +1430,11 @@ constexpr auto decimal_fast32_t::operator++() noexcept -> decimal_fast32_t&
14301430
return *this;
14311431
}
14321432

1433-
constexpr auto decimal_fast32_t::operator++(int) noexcept -> decimal_fast32_t&
1433+
constexpr auto decimal_fast32_t::operator++(int) noexcept -> decimal_fast32_t
14341434
{
1435-
return ++(*this);
1435+
const auto temp {*this};
1436+
++(*this);
1437+
return temp;
14361438
}
14371439

14381440
constexpr auto decimal_fast32_t::operator--() noexcept -> decimal_fast32_t&
@@ -1442,9 +1444,11 @@ constexpr auto decimal_fast32_t::operator--() noexcept -> decimal_fast32_t&
14421444
return *this;
14431445
}
14441446

1445-
constexpr auto decimal_fast32_t::operator--(int) noexcept -> decimal_fast32_t&
1447+
constexpr auto decimal_fast32_t::operator--(int) noexcept -> decimal_fast32_t
14461448
{
1447-
return --(*this);
1449+
const auto temp {*this};
1450+
--(*this);
1451+
return temp;
14481452
}
14491453

14501454
constexpr decimal_fast32_t::operator bool() const noexcept

include/boost/decimal/decimal_fast64_t.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,9 @@ BOOST_DECIMAL_EXPORT class decimal_fast64_t final
482482

483483
// Increment and decrement
484484
constexpr auto operator++() noexcept -> decimal_fast64_t&;
485-
constexpr auto operator++(int) noexcept -> decimal_fast64_t&;
485+
constexpr auto operator++(int) noexcept -> decimal_fast64_t;
486486
constexpr auto operator--() noexcept -> decimal_fast64_t&;
487-
constexpr auto operator--(int) noexcept -> decimal_fast64_t&;
487+
constexpr auto operator--(int) noexcept -> decimal_fast64_t;
488488

489489
// Cmath friend functions
490490
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
@@ -1573,9 +1573,11 @@ constexpr auto decimal_fast64_t::operator++() noexcept -> decimal_fast64_t&
15731573
return *this;
15741574
}
15751575

1576-
constexpr auto decimal_fast64_t::operator++(int) noexcept -> decimal_fast64_t&
1576+
constexpr auto decimal_fast64_t::operator++(int) noexcept -> decimal_fast64_t
15771577
{
1578-
return ++(*this);
1578+
const auto temp {*this};
1579+
++(*this);
1580+
return temp;
15791581
}
15801582

15811583
constexpr auto decimal_fast64_t::operator--() noexcept -> decimal_fast64_t&
@@ -1585,9 +1587,11 @@ constexpr auto decimal_fast64_t::operator--() noexcept -> decimal_fast64_t&
15851587
return *this;
15861588
}
15871589

1588-
constexpr auto decimal_fast64_t::operator--(int) noexcept -> decimal_fast64_t&
1590+
constexpr auto decimal_fast64_t::operator--(int) noexcept -> decimal_fast64_t
15891591
{
1590-
return --(*this);
1592+
const auto temp {*this};
1593+
--(*this);
1594+
return temp;
15911595
}
15921596

15931597
// Effects: if x is finite, returns its quantum exponent.

test/test_decimal32_fast_basis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void test_addition()
212212

213213
// Pre- and post- increment
214214
BOOST_TEST_EQ(mutable_one, one);
215-
BOOST_TEST_EQ(mutable_one++, two);
215+
BOOST_TEST_EQ(mutable_one++, one);
216216
BOOST_TEST_EQ(++mutable_one, three);
217217

218218
// Different orders of magnitude
@@ -262,7 +262,7 @@ void test_subtraction()
262262

263263
// Pre- and post- increment
264264
BOOST_TEST_EQ(mutable_three, three);
265-
BOOST_TEST_EQ(mutable_three--, two);
265+
BOOST_TEST_EQ(mutable_three--, three);
266266
BOOST_TEST_EQ(--mutable_three, one);
267267

268268
// Different orders of magnitude

test/test_decimal64_fast_basis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void test_addition()
192192

193193
// Pre- and post- increment
194194
BOOST_TEST_EQ(mutable_one, one);
195-
BOOST_TEST_EQ(mutable_one++, two);
195+
BOOST_TEST_EQ(mutable_one++, one);
196196
BOOST_TEST_EQ(++mutable_one, three);
197197

198198
// Different orders of magnitude
@@ -236,7 +236,7 @@ void test_subtraction()
236236

237237
// Pre- and post- increment
238238
BOOST_TEST_EQ(mutable_three, three);
239-
BOOST_TEST_EQ(mutable_three--, two);
239+
BOOST_TEST_EQ(mutable_three--, three);
240240
BOOST_TEST_EQ(--mutable_three, one);
241241

242242
// Different orders of magnitude

0 commit comments

Comments
 (0)