mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:27:34 +00:00
AK: Optional::operator=(Optional&&) should clear movee's has_value bit
We were forgetting to clear m_has_value in the Optional being moved from when using operator=(Optional&&).
This commit is contained in:
parent
cd08c8e1bf
commit
9553ecfe01
3 changed files with 34 additions and 0 deletions
30
AK/Tests/TestOptional.cpp
Normal file
30
AK/Tests/TestOptional.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <AK/TestSuite.h>
|
||||
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/Optional.h>
|
||||
|
||||
TEST_CASE(basic_optional)
|
||||
{
|
||||
Optional<int> x;
|
||||
EXPECT_EQ(x.has_value(), false);
|
||||
x = 3;
|
||||
EXPECT_EQ(x.has_value(), true);
|
||||
EXPECT_EQ(x.value(), 3);
|
||||
}
|
||||
|
||||
TEST_CASE(move_optional)
|
||||
{
|
||||
Optional<int> x;
|
||||
EXPECT_EQ(x.has_value(), false);
|
||||
x = 3;
|
||||
EXPECT_EQ(x.has_value(), true);
|
||||
EXPECT_EQ(x.value(), 3);
|
||||
|
||||
Optional<int> y;
|
||||
y = move(x);
|
||||
EXPECT_EQ(y.has_value(), true);
|
||||
EXPECT_EQ(y.value(), 3);
|
||||
EXPECT_EQ(x.has_value(), false);
|
||||
}
|
||||
|
||||
TEST_MAIN(Optional)
|
Loading…
Add table
Add a link
Reference in a new issue