From 5a3a324459558f793da77bc4c56eaeadedf9dca7 Mon Sep 17 00:00:00 2001 From: Aliaksey Kandratsenka Date: Thu, 13 Jul 2023 18:15:25 -0400 Subject: [PATCH] try to avoid certain warnings in tests Our tests do explicitly trigger certain "bad" cases. And compilers are getting increasingly smarter, so they start giving us warnings. People dislike warnings, so lets try to disable them specifically for unit tests. Refers to issue #1401 --- src/config_for_unittests.h | 22 ++++++++++++++++++++++ src/tests/debugallocation_test.cc | 2 ++ src/tests/profile-handler_unittest.cc | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/config_for_unittests.h b/src/config_for_unittests.h index 12bf614..bb6f224 100644 --- a/src/config_for_unittests.h +++ b/src/config_for_unittests.h @@ -63,3 +63,25 @@ #else # define PERFTOOLS_DLL_DECL // if DLL_DECL_FOR_UNITTESTS isn't defined, use "" #endif + +#if defined(__clang__) +#if __has_warning("-Wuse-after-free") +#pragma clang diagnostic ignored "-Wuse-after-free" +#endif +#if __has_warning("-Wunused-result") +#pragma clang diagnostic ignored "-Wunused-result" +#endif +#if __has_warning("-Wunused-private-field") +#pragma clang diagnostic ignored "-Wunused-private-field" +#endif +#if __has_warning("-Wimplicit-exception-spec-mismatch") +#pragma clang diagnostic ignored "-Wimplicit-exception-spec-mismatch" +#endif +#if __has_warning("-Wmissing-exception-spec") +#pragma clang diagnostic ignored "-Wmissing-exception-spec" +#endif +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind +#pragma GCC diagnostic ignored "-Wuse-after-free" +#pragma GCC diagnostic ignored "-Wunused-result" +#endif diff --git a/src/tests/debugallocation_test.cc b/src/tests/debugallocation_test.cc index af50d55..020c983 100644 --- a/src/tests/debugallocation_test.cc +++ b/src/tests/debugallocation_test.cc @@ -31,6 +31,8 @@ // --- // Author: Fred Akalin +#include "config_for_unittests.h" + #include #include #include // for memcmp diff --git a/src/tests/profile-handler_unittest.cc b/src/tests/profile-handler_unittest.cc index d7678ba..3531bef 100644 --- a/src/tests/profile-handler_unittest.cc +++ b/src/tests/profile-handler_unittest.cc @@ -9,7 +9,8 @@ // // This file contains the unit tests for profile-handler.h interface. -#include "config.h" +#include "config_for_unittests.h" + #include "profile-handler.h" #include