From e1b8a2e517aaddf0239a754574652dae45072e17 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 12 May 2021 05:51:59 -0600 Subject: [PATCH] Tests: Mark use-after-scope NeverDestroyed test NO_SANITIZE_ADDRESS The should_not_destroy test case intentionally performs an invalid stack access on a NeverDestroyed to confirm that the destructor for the held type was not called. --- Tests/AK/TestNeverDestroyed.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/AK/TestNeverDestroyed.cpp b/Tests/AK/TestNeverDestroyed.cpp index 7b72d6bae3..329eaa8ebd 100644 --- a/Tests/AK/TestNeverDestroyed.cpp +++ b/Tests/AK/TestNeverDestroyed.cpp @@ -44,16 +44,22 @@ TEST_CASE(should_construct_by_move) EXPECT_EQ(1, n->num_moves); } -TEST_CASE(should_not_destroy) +NO_SANITIZE_ADDRESS static void should_not_destroy() { Counter* c = nullptr; { AK::NeverDestroyed n {}; + // note: explicit stack-use-after-scope c = &n.get(); } EXPECT_EQ(0, c->num_destroys); } +TEST_CASE(should_not_destroy) +{ + should_not_destroy(); +} + TEST_CASE(should_provide_dereference_operator) { AK::NeverDestroyed n {};