Merge "Delete dangerous comparison operators from base::expected"

This commit is contained in:
Bernie Innocenti 2020-02-05 05:51:45 +00:00 committed by Gerrit Code Review
commit ab65ef22a5
3 changed files with 2 additions and 48 deletions

View file

@ -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) {

View file

@ -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) {

View file

@ -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 {};
}