Skip to content

Commit

Permalink
Demonstrate that batch_enqueue of move_iterator might still
Browse files Browse the repository at this point in the history
copy the contents when the contents allow copying.
  • Loading branch information
koraa committed Apr 4, 2016
1 parent 2578150 commit 86965b2
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions tests/unittests/unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,13 @@ struct Copyable {

struct Moveable {
Moveable(int id) : moved(false), id(id) { }

This comment has been minimized.

Copy link
@cameron314

cameron314 Apr 4, 2016

copied is never initialized. It should start at false.

Moveable(Moveable&& o) MOODYCAMEL_NOEXCEPT : moved(true), id(o.id) { }
void operator=(Moveable&& o) MOODYCAMEL_NOEXCEPT { moved = true; id = o.id; }
bool moved;
Moveable(Moveable&& o) MOODYCAMEL_NOEXCEPT : moved(true), copied(o.copied), id(o.id) { }
void operator=(Moveable&& o) MOODYCAMEL_NOEXCEPT { moved = true; id = o.id; copied = o.copied; }
bool moved, copied;
int id;

#if defined(_MSC_VER) && _MSC_VER < 1800
Moveable(Moveable const& o) MOODYCAMEL_NOEXCEPT : moved(o.moved), id(o.id) { }
void operator=(Moveable const& o) MOODYCAMEL_NOEXCEPT { moved = o.moved; id = o.id; }
#else
Moveable(Moveable const&) MOODYCAMEL_DELETE_FUNCTION;
void operator=(Moveable const&) MOODYCAMEL_DELETE_FUNCTION;
#endif
Moveable(Moveable const& o) : moved(o.moved), copied(true), id(o.id) {}
void operator=(Moveable const& o) { moved = o.moved; copied = true;id = o.id; }
};

struct ThrowingMovable {
Expand Down Expand Up @@ -3270,6 +3265,7 @@ class ConcurrentQueueTests : public TestClass<ConcurrentQueueTests>
ASSERT_OR_FAIL(q.try_dequeue(item));
ASSERT_OR_FAIL(item.id == 12345);
ASSERT_OR_FAIL(item.moved);
ASSERT_OR_FAIL(!item.copied);
ASSERT_OR_FAIL(!q.try_dequeue(item));
}

Expand Down

0 comments on commit 86965b2

Please sign in to comment.