Skip to content

Commit 53372f2

Browse files
committed
refactor: disable self-assign warning for tests
clang-16 and earlier detect "foo -= foo" and "foo /= foo" as self-assignments.
1 parent 1040a1f commit 53372f2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/test/fuzz/muhash.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ FUZZ_TARGET(muhash)
4343
},
4444
[&] {
4545
// Test that dividing a MuHash by itself brings it back to it's initial state
46+
47+
// See note about clang + self-assignment in test/uint256_tests.cpp
48+
#if defined(__clang__)
49+
# pragma clang diagnostic push
50+
# pragma clang diagnostic ignored "-Wself-assign-overloaded"
51+
#endif
52+
4653
muhash /= muhash;
54+
55+
#if defined(__clang__)
56+
# pragma clang diagnostic pop
57+
#endif
58+
4759
muhash.Finalize(out);
4860
out2 = uint256S(initial_state_hash);
4961
},

src/test/uint256_tests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ BOOST_AUTO_TEST_CASE( conversion )
267267

268268
BOOST_AUTO_TEST_CASE( operator_with_self )
269269
{
270+
271+
/* Clang 16 and earlier detects v -= v and v /= v as self-assignments
272+
to 0 and 1 respectively.
273+
See: https://github.com/llvm/llvm-project/issues/42469
274+
and the fix in commit c5302325b2a62d77cf13dd16cd5c19141862fed0 .
275+
276+
This makes some sense for arithmetic classes, but could be considered a bug
277+
elsewhere. Disable the warning here so that the code can be tested, but the
278+
warning should remain on as there will likely always be a better way to
279+
express this.
280+
*/
281+
282+
#if defined(__clang__)
283+
# pragma clang diagnostic push
284+
# pragma clang diagnostic ignored "-Wself-assign-overloaded"
285+
#endif
270286
arith_uint256 v = UintToArith256(uint256S("02"));
271287
v *= v;
272288
BOOST_CHECK(v == UintToArith256(uint256S("04")));
@@ -276,6 +292,9 @@ BOOST_AUTO_TEST_CASE( operator_with_self )
276292
BOOST_CHECK(v == UintToArith256(uint256S("02")));
277293
v -= v;
278294
BOOST_CHECK(v == UintToArith256(uint256S("0")));
295+
#if defined(__clang__)
296+
# pragma clang diagnostic pop
297+
#endif
279298
}
280299

281300
BOOST_AUTO_TEST_CASE(parse)

0 commit comments

Comments
 (0)