Skip to content

Commit 59dad2c

Browse files
committed
test: ignore self-move warning in buffer unit test
The new warning forbids to move an objects to itself - in our case, it's the purpose of the case, so let's ignore the warning there. The problem failed build on `ubuntu-24.04` GitHub Actions runner.
1 parent a63dae3 commit 59dad2c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

test/BufferUnitTest.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,27 @@ auto itr_at(BUF &buf, size_t pos)
613613
return itr;
614614
}
615615

616+
/** A helper to move buffer to itself - disables warning on GCC compiler. */
617+
template<class Buffer>
618+
static inline void
619+
buffer_move_to_self(Buffer &buf)
620+
{
621+
#ifdef __GNUC__
622+
#pragma GCC diagnostic push
623+
/*
624+
* Warning -Wself-move is brand-new and older compilers don't know
625+
* about it, so let's simply ignore all warnings for a self move.
626+
*/
627+
#pragma GCC diagnostic ignored "-Wall"
628+
#endif
629+
630+
buf = std::move(buf);
631+
632+
#ifdef __GNUC__
633+
#pragma GCC diagnostic pop
634+
#endif
635+
}
636+
616637
/**
617638
* Test move constructor and assignment.
618639
*/
@@ -626,7 +647,7 @@ buffer_move()
626647
tnt::Buffer<N> buf1;
627648
fillBuffer(buf1, S);
628649
/* It is ok to move to itself. */
629-
buf1 = std::move(buf1);
650+
buffer_move_to_self(buf1);
630651

631652
/* Create three iterators pointing to different parts. */
632653
auto itr0 = buf1.begin();
@@ -655,7 +676,7 @@ buffer_move()
655676
fail_unless(!buf1.has(buf1.begin(), S + ins_cnt + 1));
656677

657678
/* It is ok to move to itself. */
658-
buf1 = std::move(buf1);
679+
buffer_move_to_self(buf1);
659680
fail_unless(itr0 == buf1.begin());
660681
fail_unless(itr1 == itr_at(buf1, 1 + ins_cnt));
661682
fail_unless(itr2 == itr_at(buf1, S / 2 + ins_cnt));

0 commit comments

Comments
 (0)