From 12920619dd09c2db4adf3b075329b97ad90a54a0 Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Tue, 2 Jan 2024 02:18:33 +0100 Subject: [PATCH] fix(tests): prevent clang from optimizing new away --- src/logging_unittest.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/logging_unittest.cc b/src/logging_unittest.cc index cb1c657e7..40da9a44d 100644 --- a/src/logging_unittest.cc +++ b/src/logging_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2023, Google Inc. +// Copyright (c) 2024, Google Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without @@ -355,10 +355,19 @@ struct NewHook { ~NewHook() { g_new_hook = nullptr; } }; +namespace { +int* allocInt() { return new int; } +} // namespace + TEST(DeathNoAllocNewHook, logging) { // tests that NewHook used below works NewHook new_hook; - ASSERT_DEATH({ new int; }, "unexpected new"); + // Avoid unused warnings under MinGW + // + // NOTE MSVC produces warning C4551 here if we do not take the address of the + // function explicitly. + (void)&allocInt; + ASSERT_DEATH({ allocInt(); }, "unexpected new"); } void TestRawLogging() {