Skip to content

Commit 719c2e2

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 719c2e2

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

test/BufferUnitTest.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,28 @@ 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 self-move is brand-new, so ignore unknown pragmas for
625+
* successful build with older compilers.
626+
*/
627+
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
628+
#pragma GCC diagnostic ignored "-Wself-move"
629+
#endif
630+
631+
buf = std::move(buf);
632+
633+
#ifdef __GNUC__
634+
#pragma GCC diagnostic pop
635+
#endif
636+
}
637+
616638
/**
617639
* Test move constructor and assignment.
618640
*/
@@ -626,7 +648,7 @@ buffer_move()
626648
tnt::Buffer<N> buf1;
627649
fillBuffer(buf1, S);
628650
/* It is ok to move to itself. */
629-
buf1 = std::move(buf1);
651+
buffer_move_to_self(buf1);
630652

631653
/* Create three iterators pointing to different parts. */
632654
auto itr0 = buf1.begin();
@@ -655,7 +677,7 @@ buffer_move()
655677
fail_unless(!buf1.has(buf1.begin(), S + ins_cnt + 1));
656678

657679
/* It is ok to move to itself. */
658-
buf1 = std::move(buf1);
680+
buffer_move_to_self(buf1);
659681
fail_unless(itr0 == buf1.begin());
660682
fail_unless(itr1 == itr_at(buf1, 1 + ins_cnt));
661683
fail_unless(itr2 == itr_at(buf1, S / 2 + ins_cnt));

0 commit comments

Comments
 (0)