summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorHendiadyoin1 <leon.a@serenityos.org>2022-09-11 12:44:30 +0200
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-09-15 23:04:46 +0000
commit6b6510b5771a6535b6b05e1453d9bab3a05c540a (patch)
tree7eb72c220ed7c95088cc1c95a92f58a7da226e27 /Tests
parent7bb8d26b0c47ad45d5c6ca47eeecf06fe30f5496 (diff)
downloadserenity-6b6510b5771a6535b6b05e1453d9bab3a05c540a.zip
AK+Tests: Don't double-destroy NoAllocationGuard in TestFixedArray
This caused the m_allocation_enabled_previously member to be technically uninitialized when the compiler emits the implicit destructor call for stack allocated classes. This was pointed out by gcc on lagom builds, no clue how this was flying under the radar for so long and is not triggering CI.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/AK/TestFixedArray.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/Tests/AK/TestFixedArray.cpp b/Tests/AK/TestFixedArray.cpp
index fe34a56338..85e878791d 100644
--- a/Tests/AK/TestFixedArray.cpp
+++ b/Tests/AK/TestFixedArray.cpp
@@ -63,10 +63,15 @@ TEST_CASE(no_allocation)
EXPECT_NO_CRASH("Move", [&] {
FixedArray<int> moved_from_array = FixedArray<int>::must_create_but_fixme_should_propagate_errors(6);
- NoAllocationGuard guard;
- FixedArray<int> moved_to_array(move(moved_from_array));
- // We need to ensure that this destructor runs before the FixedArray destructor.
- guard.~NoAllocationGuard();
+ // We need an Optional here to ensure that the NoAllocationGuard is
+ // destroyed before the moved_to_array, because that would call free
+ Optional<FixedArray<int>> moved_to_array;
+
+ {
+ NoAllocationGuard guard;
+ moved_to_array.emplace(move(moved_from_array));
+ }
+
return Test::Crash::Failure::DidNotCrash;
});