mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Remove operators && and || from DistinctNumeric
These don't do short-circuit evaluation, and so I ran into some some very subtle side-effects when converting code to DistinctNumeric. In code like this: MyDistinctNumeric n; if (n && check_thing(n)) return; There would be no short-circuit evaluation if the return type of check_thing() was implicitly convertible to MyDistinctNumeric. Ran into this while making Ext2FS::GroupIndex a DistinctNumeric.
This commit is contained in:
parent
e00f519cdd
commit
acf341862a
Notes:
sideshowbarker
2024-07-18 22:24:30 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/acf341862aa
2 changed files with 0 additions and 19 deletions
|
@ -150,16 +150,6 @@ public:
|
||||||
static_assert(Bool, "'!a' is only available for DistinctNumeric types with 'Bool'.");
|
static_assert(Bool, "'!a' is only available for DistinctNumeric types with 'Bool'.");
|
||||||
return !this->m_value;
|
return !this->m_value;
|
||||||
}
|
}
|
||||||
bool operator&&(const Self& other) const
|
|
||||||
{
|
|
||||||
static_assert(Bool, "'a&&b' is only available for DistinctNumeric types with 'Bool'.");
|
|
||||||
return this->m_value && other.m_value;
|
|
||||||
}
|
|
||||||
bool operator||(const Self& other) const
|
|
||||||
{
|
|
||||||
static_assert(Bool, "'a||b' is only available for DistinctNumeric types with 'Bool'.");
|
|
||||||
return this->m_value || other.m_value;
|
|
||||||
}
|
|
||||||
// Intentionally don't define `operator bool() const` here. C++ is a bit
|
// Intentionally don't define `operator bool() const` here. C++ is a bit
|
||||||
// overzealos, and whenever there would be a type error, C++ instead tries
|
// overzealos, and whenever there would be a type error, C++ instead tries
|
||||||
// to convert to a common int-ish type first. `bool` is int-ish, so
|
// to convert to a common int-ish type first. `bool` is int-ish, so
|
||||||
|
|
|
@ -123,13 +123,6 @@ TEST_CASE(operator_bool)
|
||||||
EXPECT_EQ(!a, true);
|
EXPECT_EQ(!a, true);
|
||||||
EXPECT_EQ(!b, false);
|
EXPECT_EQ(!b, false);
|
||||||
EXPECT_EQ(!c, false);
|
EXPECT_EQ(!c, false);
|
||||||
EXPECT_EQ(a && b, false);
|
|
||||||
EXPECT_EQ(a && c, false);
|
|
||||||
EXPECT_EQ(b && c, true);
|
|
||||||
EXPECT_EQ(a || a, false);
|
|
||||||
EXPECT_EQ(a || b, true);
|
|
||||||
EXPECT_EQ(a || c, true);
|
|
||||||
EXPECT_EQ(b || c, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE(operator_flags)
|
TEST_CASE(operator_flags)
|
||||||
|
@ -233,8 +226,6 @@ TEST_CASE(composability)
|
||||||
EXPECT_EQ(a >= b, false);
|
EXPECT_EQ(a >= b, false);
|
||||||
// Bool
|
// Bool
|
||||||
EXPECT_EQ(!a, true);
|
EXPECT_EQ(!a, true);
|
||||||
EXPECT_EQ(a && b, false);
|
|
||||||
EXPECT_EQ(a || b, true);
|
|
||||||
// Flags
|
// Flags
|
||||||
EXPECT_EQ(a & b, GeneralNumeric(0));
|
EXPECT_EQ(a & b, GeneralNumeric(0));
|
||||||
EXPECT_EQ(a | b, GeneralNumeric(1));
|
EXPECT_EQ(a | b, GeneralNumeric(1));
|
||||||
|
|
Loading…
Reference in a new issue