Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1cc76dfe authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

Delete dangerous comparison operators from base::expected

These operators were included because they're present in the draft
standard proposal of std::expected, but they were deemed to lead to
bugs, particularly when T is implicitly convertible to bool.

Change-Id: Ib149decf1f230198f358dc1ae0eaed71961363f6
Test: m
parent 955601be
Loading
Loading
Loading
Loading
+1 −19
Original line number Diff line number Diff line
@@ -499,24 +499,6 @@ TEST(Expected, testDifferentErrors) {
  EXPECT_TRUE(e4 != e3);
}

TEST(Expected, testCompareWithSameValue) {
  exp_int e = 10;
  int value = 10;
  EXPECT_TRUE(e == value);
  EXPECT_TRUE(value == e);
  EXPECT_FALSE(e != value);
  EXPECT_FALSE(value != e);
}

TEST(Expected, testCompareWithDifferentValue) {
  exp_int e = 10;
  int value = 20;
  EXPECT_FALSE(e == value);
  EXPECT_FALSE(value == e);
  EXPECT_TRUE(e != value);
  EXPECT_TRUE(value != e);
}

TEST(Expected, testCompareWithSameError) {
  exp_int e = unexpected(10);
  exp_int::unexpected_type error = 10;
@@ -594,7 +576,7 @@ TEST(Expected, testDivideExample) {
  EXPECT_EQ(-1, divide(10, 0).error().cause);

  EXPECT_TRUE(divide(10, 3));
  EXPECT_EQ(QR(3, 1), divide(10, 3));
  EXPECT_EQ(QR(3, 1), *divide(10, 3));
}

TEST(Expected, testPair) {
+0 −28
Original line number Diff line number Diff line
@@ -366,16 +366,6 @@ class _NODISCARD_ expected {
  template<class T1, class E1, class T2, class E2>
  friend constexpr bool operator!=(const expected<T1, E1>& x, const expected<T2, E2>& y);

  // comparison with T
  template<class T1, class E1, class T2>
  friend constexpr bool operator==(const expected<T1, E1>&, const T2&);
  template<class T1, class E1, class T2>
  friend constexpr bool operator==(const T2&, const expected<T1, E1>&);
  template<class T1, class E1, class T2>
  friend constexpr bool operator!=(const expected<T1, E1>&, const T2&);
  template<class T1, class E1, class T2>
  friend constexpr bool operator!=(const T2&, const expected<T1, E1>&);

  // Comparison with unexpected<E>
  template<class T1, class E1, class E2>
  friend constexpr bool operator==(const expected<T1, E1>&, const unexpected<E2>&);
@@ -410,24 +400,6 @@ constexpr bool operator!=(const expected<T1, E1>& x, const expected<T2, E2>& y)
  return !(x == y);
}

// comparison with T
template<class T1, class E1, class T2>
constexpr bool operator==(const expected<T1, E1>& x, const T2& y) {
  return x.has_value() && (*x == y);
}
template<class T1, class E1, class T2>
constexpr bool operator==(const T2& x, const expected<T1, E1>& y) {
  return y.has_value() && (x == *y);
}
template<class T1, class E1, class T2>
constexpr bool operator!=(const expected<T1, E1>& x, const T2& y) {
  return !x.has_value() || (*x != y);
}
template<class T1, class E1, class T2>
constexpr bool operator!=(const T2& x, const expected<T1, E1>& y) {
  return !y.has_value() || (x != *y);
}

// Comparison with unexpected<E>
template<class T1, class E1, class E2>
constexpr bool operator==(const expected<T1, E1>& x, const unexpected<E2>& y) {
+1 −1
Original line number Diff line number Diff line
@@ -208,7 +208,7 @@ Result<void> ServiceParser::ParseKeycodes(std::vector<std::string>&& args) {

        // If the property is not set, it defaults to none, in which case there are no keycodes
        // for this service.
        if (expanded == "none") {
        if (*expanded == "none") {
            return {};
        }