mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 13:11:46 +03: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
Notes:
sideshowbarker
2024-07-19 12:51:56 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9553ecfe016
@ -104,6 +104,7 @@ public:
|
|||||||
ASSERT(m_has_value);
|
ASSERT(m_has_value);
|
||||||
T released_value = move(value());
|
T released_value = move(value());
|
||||||
value().~T();
|
value().~T();
|
||||||
|
m_has_value = false;
|
||||||
return released_value;
|
return released_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,9 @@ TestNonnullRefPtr: TestNonnullRefPtr.o $(SHARED_TEST_OBJS)
|
|||||||
TestRefPtr: TestRefPtr.o $(SHARED_TEST_OBJS)
|
TestRefPtr: TestRefPtr.o $(SHARED_TEST_OBJS)
|
||||||
$(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ TestRefPtr.o $(SHARED_TEST_OBJS)
|
$(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ TestRefPtr.o $(SHARED_TEST_OBJS)
|
||||||
|
|
||||||
|
TestOptional: TestOptional.o $(SHARED_TEST_OBJS)
|
||||||
|
$(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ TestOptional.o $(SHARED_TEST_OBJS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(SHARED_TEST_OBJS)
|
rm -f $(SHARED_TEST_OBJS)
|
||||||
rm -f $(PROGRAMS)
|
rm -f $(PROGRAMS)
|
||||||
|
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…
Reference in New Issue
Block a user