Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): prevent clang from optimizing new away #1017

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/logging_unittest.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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() {
Expand Down