From 117c211cf7ca94914eef75aa1c1912cd5d6de2ec Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 06:05:58 +0200 Subject: Fix bug in flag_set '==' operator --- src/flag_set.hpp | 9 ++++++++- tests/flag_set.cc | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/flag_set.hpp b/src/flag_set.hpp index 490f0daf..737513d5 100644 --- a/src/flag_set.hpp +++ b/src/flag_set.hpp @@ -99,7 +99,14 @@ public: constexpr bool operator == (flag_set const &other) const { - return m_data == other.m_data; + for (std::size_t i = 0; i < tiers; i++) + { + if (m_data[i] != other.m_data[i]) + { + return false; + } + } + return true; } constexpr bool operator != (flag_set const &other) const diff --git a/tests/flag_set.cc b/tests/flag_set.cc index 3abd505d..05418a05 100644 --- a/tests/flag_set.cc +++ b/tests/flag_set.cc @@ -59,6 +59,16 @@ go_bandit([]() { AssertThat(result, Equals(true)); }); + it("== operator should compare equals as equals", [&] { + // Setup + fs_t fs1 = fs_t::make(1, 3); + fs_t fs2 = fs_t::make(1, 3); + // Exercise + auto result = (fs1 == fs2); + // Verify + AssertThat(result, Equals(true)); + }); + it("| operator should respect the tier and index", [&] { // Setup fs_t fs1 = fs_t::make(0, 31); -- cgit v1.2.3