Skip to content

Commit 43cd83b

Browse files
committed
test: move uint256_tests/operator_with_self to arith_uint256_tests
move/formatting-only change. These tests do not cover uint256, so move them to the appropriate test suite. Additionally, apply clang-format suggestions.
1 parent c6c994c commit 43cd83b

File tree

2 files changed

+30
-33
lines changed

2 files changed

+30
-33
lines changed

src/test/arith_uint256_tests.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,4 +578,34 @@ BOOST_AUTO_TEST_CASE(conversion)
578578
}
579579
}
580580

581+
BOOST_AUTO_TEST_CASE(operator_with_self)
582+
{
583+
/* Clang 16 and earlier detects v -= v and v /= v as self-assignments
584+
to 0 and 1 respectively.
585+
See: https://github.com/llvm/llvm-project/issues/42469
586+
and the fix in commit c5302325b2a62d77cf13dd16cd5c19141862fed0 .
587+
588+
This makes some sense for arithmetic classes, but could be considered a bug
589+
elsewhere. Disable the warning here so that the code can be tested, but the
590+
warning should remain on as there will likely always be a better way to
591+
express this.
592+
*/
593+
#if defined(__clang__)
594+
#pragma clang diagnostic push
595+
#pragma clang diagnostic ignored "-Wself-assign-overloaded"
596+
#endif
597+
arith_uint256 v{2};
598+
v *= v;
599+
BOOST_CHECK_EQUAL(v, arith_uint256{4});
600+
v /= v;
601+
BOOST_CHECK_EQUAL(v, arith_uint256{1});
602+
v += v;
603+
BOOST_CHECK_EQUAL(v, arith_uint256{2});
604+
v -= v;
605+
BOOST_CHECK_EQUAL(v, arith_uint256{0});
606+
#if defined(__clang__)
607+
#pragma clang diagnostic pop
608+
#endif
609+
}
610+
581611
BOOST_AUTO_TEST_SUITE_END()

src/test/uint256_tests.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <arith_uint256.h>
65
#include <streams.h>
76
#include <test/util/setup_common.h>
87
#include <uint256.h>
@@ -245,38 +244,6 @@ BOOST_AUTO_TEST_CASE(methods) // GetHex SetHexDeprecated FromHex begin() end() s
245244
ss.clear();
246245
}
247246

248-
BOOST_AUTO_TEST_CASE( operator_with_self )
249-
{
250-
251-
/* Clang 16 and earlier detects v -= v and v /= v as self-assignments
252-
to 0 and 1 respectively.
253-
See: https://github.com/llvm/llvm-project/issues/42469
254-
and the fix in commit c5302325b2a62d77cf13dd16cd5c19141862fed0 .
255-
256-
This makes some sense for arithmetic classes, but could be considered a bug
257-
elsewhere. Disable the warning here so that the code can be tested, but the
258-
warning should remain on as there will likely always be a better way to
259-
express this.
260-
*/
261-
262-
#if defined(__clang__)
263-
# pragma clang diagnostic push
264-
# pragma clang diagnostic ignored "-Wself-assign-overloaded"
265-
#endif
266-
arith_uint256 v{2};
267-
v *= v;
268-
BOOST_CHECK_EQUAL(v, arith_uint256{4});
269-
v /= v;
270-
BOOST_CHECK_EQUAL(v, arith_uint256{1});
271-
v += v;
272-
BOOST_CHECK_EQUAL(v, arith_uint256{2});
273-
v -= v;
274-
BOOST_CHECK_EQUAL(v, arith_uint256{0});
275-
#if defined(__clang__)
276-
# pragma clang diagnostic pop
277-
#endif
278-
}
279-
280247
/**
281248
* Implemented as a templated function so it can be reused by other classes that have a FromHex()
282249
* method that wraps base_blob::FromHex(), such as transaction_identifier::FromHex().

0 commit comments

Comments
 (0)