From 6234b5a16d63db0691b6a5efe463e7cba6b75f95 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Tue, 9 Mar 2021 14:42:20 -0800 Subject: [PATCH 01/17] Add CompilerWarnings.hpp which provides some helpful macros to make suppressing warnings across supported compilers a bit more clean. Obviously it's better if we don't suppress warnings at all, but for where we do, we can at least make the code around that look less bad. --- .../Clienttelemetry/Clienttelemetry.vcxitems | 415 +++++++++--------- .../Clienttelemetry.vcxitems.filters | 395 +++++++++-------- lib/include/mat/CompilerWarnings.hpp | 50 +++ 3 files changed, 454 insertions(+), 406 deletions(-) create mode 100644 lib/include/mat/CompilerWarnings.hpp diff --git a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems index 4a73fbea7..eb05e1ba7 100644 --- a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems +++ b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems @@ -1,207 +1,208 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - {45d41acc-2c3c-43d2-bc10-02aa73ffc7c7} - ClientTelemetry - - - - %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + {45d41acc-2c3c-43d2-bc10-02aa73ffc7c7} + ClientTelemetry + + + + %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters index 0c37e8876..f259c4cdc 100644 --- a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters +++ b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters @@ -1,199 +1,196 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/include/mat/CompilerWarnings.hpp b/lib/include/mat/CompilerWarnings.hpp new file mode 100644 index 000000000..9e55877bd --- /dev/null +++ b/lib/include/mat/CompilerWarnings.hpp @@ -0,0 +1,50 @@ +#ifndef COMPILERWARNINGS_HPP +#define COMPILERWARNINGS_HPP + +#if defined(_MSC_VER) + +#define MAT_PUSH_WARNINGS __pragma(warning(push)) +#define MAT_POP_WARNINGS __pragma(warning(pop)) +#define MAT_DISABLE_WARNING(warningNumber) __pragma(warning(disable: warningNumber)) + +#elif defined(__clang__) || defined(__GCC__) + +#define MAT_STRINGIFY_PRAGMA(args) _Pragma(#args) + +#ifdef __clang__ +#define MAT_STRINGIFY_PRAGMA_WITH_COMPILER(args) MAT_STRINGIFY_PRAGMA(clang args) +#else +#define MAT_STRINGIFY_PRAGMA_WITH_COMPILER(args) MAT_STRINGIFY_PRAGMA(GCC args) +#endif + +#define MAT_PUSH_WARNINGS MAT_STRINGIFY_PRAGMA_WITH_COMPILER(diagnostic push) +#define MAT_POP_WARNINGS MAT_STRINGIFY_PRAGMA_WITH_COMPILER(diagnostic pop) +#define MAT_DISABLE_WARNING(warningName) MAT_STRINGIFY_PRAGMA_WITH_COMPILER(diagnostic ignored #warningName) + +#else + +#define MAT_PUSH_WARNINGS +#define MAT_POP_WARNINGS +#define MAT_DISABLE_WARNING(warningName) + +#endif + +/* + +Define specific Disable warning macros here. + +Best effort should be made keep both MSVC and GCC/Clang blocks as equivalent as possible. + +*/ + +#if defined(_MSC_VER) + +#define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(4296) + +#elif defined(__clang__) || defined(__GCC__) + +#define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(-Wtype-limits) + +#endif + +#endif // COMPILERWARNINGS_HPP \ No newline at end of file From aac511cf28c24562777ecc46199f6fb537714e97 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Tue, 9 Mar 2021 14:42:52 -0800 Subject: [PATCH 02/17] Add a use case for disabling a compiler warning using the macros. --- lib/offline/OfflineStorage_SQLite.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/offline/OfflineStorage_SQLite.cpp b/lib/offline/OfflineStorage_SQLite.cpp index b5d8d2ff3..af2f09727 100644 --- a/lib/offline/OfflineStorage_SQLite.cpp +++ b/lib/offline/OfflineStorage_SQLite.cpp @@ -9,6 +9,7 @@ #include "ILogManager.hpp" #include "SQLiteWrapper.hpp" #include "utils/StringUtils.hpp" +#include "mat/CompilerWarnings.hpp" #include #include #include @@ -755,8 +756,9 @@ namespace MAT_NS_BEGIN { if (!stmt.select() || !stmt.getRow(m_pageSize)) { return false; } } -#pragma warning(push) -#pragma warning(disable:4296) // expression always false. +MAT_PUSH_WARNINGS +MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE + #define PREPARE_SQL(var_, stmt_) \ if ((var_ = m_db->prepare(stmt_)) < 0) { return false; } @@ -843,7 +845,8 @@ namespace MAT_NS_BEGIN { Execute("DELETE FROM " TABLE_NAME_PACKAGES); #undef PREPARE_SQL -#pragma warning(pop) + +MAT_POP_WARNINGS ResizeDb(); return true; From 47b4447f82f1de93ec97dd57293054b0acaa20c5 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 12:50:49 -0700 Subject: [PATCH 03/17] I missed one last merge, whoops. --- lib/offline/OfflineStorage_SQLite.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/offline/OfflineStorage_SQLite.cpp b/lib/offline/OfflineStorage_SQLite.cpp index e69449edf..07af97137 100644 --- a/lib/offline/OfflineStorage_SQLite.cpp +++ b/lib/offline/OfflineStorage_SQLite.cpp @@ -846,17 +846,7 @@ MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE // error: comparison of unsigned #undef PREPARE_SQL -<<<<<<< HEAD MAT_POP_WARNINGS -======= -#if defined(_MSC_VER) -#pragma warning(pop) -#elif defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#endif ->>>>>>> master ResizeDb(); return true; From cd4584e7a34096fc9d0b470ee0fb94967848e372 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 12:51:24 -0700 Subject: [PATCH 04/17] This warning supression wasn't actually doing anything, so I've removed it. --- lib/api/LogManagerImpl.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/api/LogManagerImpl.cpp b/lib/api/LogManagerImpl.cpp index 7fc32e124..e5a018d6a 100644 --- a/lib/api/LogManagerImpl.cpp +++ b/lib/api/LogManagerImpl.cpp @@ -2,10 +2,6 @@ // Copyright (c) 2015-2020 Microsoft Corporation and Contributors. // SPDX-License-Identifier: Apache-2.0 // -#ifdef _MSC_VER -// evntprov.h(838) : warning C4459 : declaration of 'Version' hides global declaration -#pragma warning(disable : 4459) -#endif #include "LogManagerImpl.hpp" #include "mat/config.h" From 8d7c7086d737489588309d4b020f3d7a454d2c0f Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 13:21:08 -0700 Subject: [PATCH 05/17] Remove unused warning supression. --- lib/http/HttpClient_WinInet.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/http/HttpClient_WinInet.cpp b/lib/http/HttpClient_WinInet.cpp index 69c847a99..90953a94b 100644 --- a/lib/http/HttpClient_WinInet.cpp +++ b/lib/http/HttpClient_WinInet.cpp @@ -6,8 +6,6 @@ #include "mat/config.h" #ifdef HAVE_MAT_DEFAULT_HTTP_CLIENT -#pragma warning(push) -#pragma warning(disable:4189) /* Turn off Level 4: local variable is initialized but not referenced. dwError unused in Release without printing it. */ #include "HttpClient_WinInet.hpp" #include "utils/StringUtils.hpp" @@ -561,7 +559,6 @@ bool HttpClient_WinInet::IsMsRootCheckRequired() } } MAT_NS_END -#pragma warning(pop) #endif // HAVE_MAT_DEFAULT_HTTP_CLIENT // clang-format on From 90f1ff2d8a90f67a3c499f7f2036dd1bf4ba7ee0 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 13:25:16 -0700 Subject: [PATCH 06/17] Remove warning supression, simply cast result of CoCreateGuid to void if we're not gonna use the result. --- lib/pal/PAL.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/pal/PAL.cpp b/lib/pal/PAL.cpp index e461a9c13..a685d3e07 100644 --- a/lib/pal/PAL.cpp +++ b/lib/pal/PAL.cpp @@ -288,17 +288,11 @@ namespace PAL_NS_BEGIN { return m_taskDispatcher; } -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:6031) -#endif std::string PlatformAbstractionLayer::generateUuidString() const { #ifdef _WIN32 GUID uuid = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }; - auto hr = CoCreateGuid(&uuid); - /* CoCreateGuid` will possiblity never fail, so ignoring the result */ - UNREFERENCED_PARAMETER(hr); + (void) CoCreateGuid(&uuid); return MAT::to_string(uuid); #else static std::once_flag flag; @@ -325,9 +319,6 @@ namespace PAL_NS_BEGIN { return buf; #endif } -#ifdef _MSC_VER -#pragma warning(pop) -#endif int64_t PlatformAbstractionLayer::getUtcSystemTimeMs() const { From 4a880beb2dea253eb046f9ebaf176dd233ce9451 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 13:38:45 -0700 Subject: [PATCH 07/17] Remove deprecated method warning supression. --- lib/pal/PAL.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/pal/PAL.cpp b/lib/pal/PAL.cpp index a685d3e07..988d400a2 100644 --- a/lib/pal/PAL.cpp +++ b/lib/pal/PAL.cpp @@ -166,10 +166,6 @@ namespace PAL_NS_BEGIN { #define _CRT_SECURE_NO_WARNINGS #endif -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4996) -#endif void log(LogLevel level, char const* component, char const* fmt, ...) { #if defined(ANDROID) && !defined(ANDROID_SUPPRESS_LOGCAT) @@ -271,9 +267,6 @@ namespace PAL_NS_BEGIN { (void)(fmt); #endif /* of #ifdef HAVE_MAT_LOGGING */ } -#ifdef _MSC_VER -#pragma warning(pop) -#endif } // namespace detail From ed4d50da0234ecc98bcf2baa7e27bbd3760948b9 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 15:15:03 -0700 Subject: [PATCH 08/17] Replace all #pragma warning supressions in NetworkDetector.cpp with the new macros. --- lib/include/mat/CompilerWarnings.hpp | 7 ++++--- lib/pal/desktop/NetworkDetector.cpp | 16 +++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/include/mat/CompilerWarnings.hpp b/lib/include/mat/CompilerWarnings.hpp index 9e55877bd..4b6606636 100644 --- a/lib/include/mat/CompilerWarnings.hpp +++ b/lib/include/mat/CompilerWarnings.hpp @@ -31,18 +31,19 @@ /* -Define specific Disable warning macros here. - -Best effort should be made keep both MSVC and GCC/Clang blocks as equivalent as possible. +Define specific Disable warning macros here. Keep macros ordered alphabetically. */ #if defined(_MSC_VER) +#define MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL MAT_DISABLE_WARNING(4996) +#define MAT_DISABLE_WARNING_EXCEPTION_EXECUTE_HANDLER MAT_DISABLE_WARNING(6320) #define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(4296) #elif defined(__clang__) || defined(__GCC__) +#define MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL MAT_DISABLE_WARNING(-Wdeprecated-declarations) #define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(-Wtype-limits) #endif diff --git a/lib/pal/desktop/NetworkDetector.cpp b/lib/pal/desktop/NetworkDetector.cpp index 60e989396..565245a0f 100644 --- a/lib/pal/desktop/NetworkDetector.cpp +++ b/lib/pal/desktop/NetworkDetector.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 // #include "ctmacros.hpp" +#include "mat/CompilerWarnings.hpp" #include "mat/config.h" #ifdef HAVE_MAT_NETDETECT @@ -81,8 +82,6 @@ namespace MAT_NS_BEGIN /// This function can be called on any Windows release and it provides a SEH handler. /// /// -#pragma warning(push) -#pragma warning(disable: 6320) int NetworkDetector::GetCurrentNetworkCost() { #if 0 @@ -106,11 +105,14 @@ namespace MAT_NS_BEGIN // Exception thrown at XXX (KernelBase.dll) in YYY : The binding handle is invalid. // If there is a handler for this exception, the program may be safely continued. //******************************************************************************************************************************* +MAT_PUSH_WARNINGS +MAT_DISABLE_WARNING_EXCEPTION_EXECUTE_HANDLER __except (EXCEPTION_EXECUTE_HANDLER) { LOG_ERROR("Unable to obtain network state!"); m_currentNetworkCost = NetworkCost_Unknown; } +MAT_POP_WARNINGS // Notify the app about current network cost change DebugEvent evt; @@ -121,7 +123,6 @@ namespace MAT_NS_BEGIN return m_currentNetworkCost; } -#pragma warning(pop) /// /// Get current network connectivity state @@ -438,11 +439,6 @@ namespace MAT_NS_BEGIN /// /// Register for COM events and block-wait in RegisterAndListen /// -#pragma warning( push ) -#pragma warning(disable:28159) -#pragma warning(disable:4996) -#pragma warning(disable:6320) -// We must use GetVersionEx to retain backwards compat with Win 7 SP1 void NetworkDetector::run() { // Check Windows version and if below Windows 8, then avoid running Network cost detection logic @@ -450,7 +446,10 @@ namespace MAT_NS_BEGIN BOOL bIsWindows8orLater; ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); +MAT_PUSH_WARNINGS +MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL // We must use GetVersionEx to retain backwards compat with Win 7 SP1 GetVersionEx(&osvi); +MAT_POP_WARNINGS bIsWindows8orLater = ((osvi.dwMajorVersion >= 6) && (osvi.dwMinorVersion >= 2)) || (osvi.dwMajorVersion > 6); // Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2) if (!bIsWindows8orLater) @@ -504,7 +503,6 @@ namespace MAT_NS_BEGIN } } -#pragma warning( pop ) /// /// Start network monitoring thread From 06b66303cc7966061ca47b7aedbc80611088fa72 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 15:18:46 -0700 Subject: [PATCH 09/17] Remove unnecessary #pragma warning in WindowsDesktopSystemInformationImpl.cpp --- lib/pal/desktop/WindowsDesktopSystemInformationImpl.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/pal/desktop/WindowsDesktopSystemInformationImpl.cpp b/lib/pal/desktop/WindowsDesktopSystemInformationImpl.cpp index 273e8b30b..eff88f875 100644 --- a/lib/pal/desktop/WindowsDesktopSystemInformationImpl.cpp +++ b/lib/pal/desktop/WindowsDesktopSystemInformationImpl.cpp @@ -6,8 +6,6 @@ #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #endif -#pragma warning( disable : 4996 ) - // Windows 7.1 SDK module: #pragma comment (lib, "Version.Lib") From 6f479a90f5692009761ae0596ac5bd79ec066afc Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 15:32:21 -0700 Subject: [PATCH 10/17] Remove unnecessary warning suppression. --- tests/functests/APITest.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/functests/APITest.cpp b/tests/functests/APITest.cpp index 685be0bea..3f2a03ff8 100644 --- a/tests/functests/APITest.cpp +++ b/tests/functests/APITest.cpp @@ -8,11 +8,6 @@ #include "mat/config.h" -#ifdef _MSC_VER -#pragma warning (disable : 4389) -#endif - -//#include "gtest/gtest.h" #include "common/Common.hpp" #include "CsProtocol_types.hpp" From 2ac6f520e9d43364abac8188f3c91f57ba29d023 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 15:33:32 -0700 Subject: [PATCH 11/17] Replace warning pragmas in DebugLogger.hpp with macros from CompilerWarnings.hpp --- lib/tracing/api/DebugLogger.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/tracing/api/DebugLogger.hpp b/lib/tracing/api/DebugLogger.hpp index 6a02b8624..14df7f9a5 100644 --- a/lib/tracing/api/DebugLogger.hpp +++ b/lib/tracing/api/DebugLogger.hpp @@ -4,6 +4,7 @@ // #ifndef DEBUGLOGGER_HPP #define DEBUGLOGGER_HPP +#include "mat/CompilerWarnings.hpp" /// /// C++11 implementation of a cross-platform debug logging facility. /// @@ -608,8 +609,8 @@ class DebugLogger auto now = std::chrono::system_clock::now(); int64_t millis = std::chrono::duration_cast(now.time_since_epoch()).count(); auto in_time_t = std::chrono::system_clock::to_time_t(now); -#pragma warning(push) -#pragma warning(disable: 4996) +MAT_PUSH_WARNINGS +MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL // FIXME: this has been the case for all v1 builds and v2 Linux, but we should improve this because // the static structure returned by localtime function may change its contents if another thread // invokes localtime. Generally that is not an issue, as time won't change that fast, but it may @@ -617,7 +618,7 @@ class DebugLogger // // warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead ss << std::put_time(localtime(&in_time_t), "%Y-%m-%d %X"); -#pragma warning(pop) +MAT_POP_WARNINGS ss << "." << std::setfill('0') << std::setw(3) << (unsigned)(millis % 1000); ss << "|"; } From 503d40f750dd22a9dec8e79f7cbb1e991afd6ce6 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Wed, 14 Apr 2021 15:36:06 -0700 Subject: [PATCH 12/17] Add copyright blob to CompilerWarnings.hpp --- lib/include/mat/CompilerWarnings.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/include/mat/CompilerWarnings.hpp b/lib/include/mat/CompilerWarnings.hpp index 4b6606636..a4704df9f 100644 --- a/lib/include/mat/CompilerWarnings.hpp +++ b/lib/include/mat/CompilerWarnings.hpp @@ -1,3 +1,7 @@ +// +// Copyright (c) 2015-2020 Microsoft Corporation and Contributors. +// SPDX-License-Identifier: Apache-2.0 +// #ifndef COMPILERWARNINGS_HPP #define COMPILERWARNINGS_HPP From 46f64eba8a46eafe9295c73a5ea48d5a6f644154 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Thu, 15 Apr 2021 11:24:26 -0700 Subject: [PATCH 13/17] Move warning suppressions in tests to macros. Remove unnecessary warning supressions while I'm there. --- lib/include/mat/CompilerWarnings.hpp | 16 ++++++--- tests/common/MockIEcsClient.hpp | 33 +++++++------------ tests/common/MockITenantDataSerializer.hpp | 25 +++++--------- tests/functests/BondDecoderTests.cpp | 4 --- tests/functests/Main.cpp | 1 - .../unittests/HttpDeflateCompressionTests.cpp | 11 +++---- tests/unittests/Main.cpp | 1 - 7 files changed, 36 insertions(+), 55 deletions(-) diff --git a/lib/include/mat/CompilerWarnings.hpp b/lib/include/mat/CompilerWarnings.hpp index a4704df9f..d4468eb4f 100644 --- a/lib/include/mat/CompilerWarnings.hpp +++ b/lib/include/mat/CompilerWarnings.hpp @@ -41,14 +41,20 @@ Define specific Disable warning macros here. Keep macros ordered alphabetically. #if defined(_MSC_VER) -#define MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL MAT_DISABLE_WARNING(4996) -#define MAT_DISABLE_WARNING_EXCEPTION_EXECUTE_HANDLER MAT_DISABLE_WARNING(6320) -#define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(4296) +#define MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDEN MAT_DISABLE_WARNING(4373) +#define MAT_DISABLE_WARNING_DECIMAL_TERMINATES_OCTAL_ESCAPE_SEQUCENCE MAT_DISABLE_WARNING(4125) +#define MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL MAT_DISABLE_WARNING(4996) +#define MAT_DISABLE_WARNING_EXCEPTION_EXECUTE_HANDLER MAT_DISABLE_WARNING(6320) +#define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(4296) +#define MAT_DISABLE_WARNING_INCONSISTENT_MISSING_OVERRIDE #elif defined(__clang__) || defined(__GCC__) -#define MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL MAT_DISABLE_WARNING(-Wdeprecated-declarations) -#define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(-Wtype-limits) +#define MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDEN +#define MAT_DISABLE_WARNING_DECIMAL_TERMINATES_OCTAL_ESCAPE_SEQUCENCE +#define MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL MAT_DISABLE_WARNING(-Wdeprecated-declarations) +#define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(-Wtype-limits) +#define MAT_DISABLE_WARNING_INCONSISTENT_MISSING_OVERRIDE MAT_DISABLE_WARNING(-Winconsistent-missing-override) #endif diff --git a/tests/common/MockIEcsClient.hpp b/tests/common/MockIEcsClient.hpp index 86c482903..abdcd16d3 100644 --- a/tests/common/MockIEcsClient.hpp +++ b/tests/common/MockIEcsClient.hpp @@ -2,23 +2,15 @@ // Copyright (c) 2015-2020 Microsoft Corporation and Contributors. // SPDX-License-Identifier: Apache-2.0 // - -#pragma once +#ifndef MOCKIECSCLIENT_HPP +#define MOCKIECSCLIENT_HPP #include +#include "mat/CompilerWarnings.hpp" namespace testing { -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Winconsistent-missing-override" // GMock MOCK_METHOD* macros don't use override. -#endif - -#ifdef _MSC_VER -// Avoid noise caused by ECS using const modifier on value-type arguments like int, bool and double. -// The modifiers are lost inside Google Mock, the resulting signature differs and compiler complains. -#pragma warning(push) -#pragma warning(disable:4373) // C4373: previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers -#endif +MAT_PUSH_WARNINGS +MAT_DISABLE_WARNING_INCONSISTENT_MISSING_OVERRIDE // GMock MOCK_METHOD* macros don't use override. class MockIEcsConfig : public ecsclient::IEcsConfig, public virtual auf::Object @@ -27,6 +19,10 @@ class MockIEcsConfig : public ecsclient::IEcsConfig, MockIEcsConfig(); virtual ~MockIEcsConfig(); +// Avoid noise caused by ECS using const modifier on value-type arguments like int, bool and double. +// The modifiers are lost inside Google Mock, the resulting signature differs and compiler complains. +MAT_PUSH_WARNINGS +MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDEN // C4373: previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers MOCK_CONST_METHOD3(GetSetting, std::string(std::string const & t, std::string const &, std::string const &)); MOCK_CONST_METHOD3(GetSettingAsString, std::string(std::string const &, std::string const &, std::string const &)); MOCK_CONST_METHOD3(GetSettingAsInt, int(std::string const &, std::string const &, int const defaultValue)); @@ -38,13 +34,9 @@ class MockIEcsConfig : public ecsclient::IEcsConfig, MOCK_CONST_METHOD2(GetKeys, std::vector(std::string const &, std::string const &)); MOCK_CONST_METHOD0(GetAgents, std::vector()); MOCK_CONST_METHOD0(GetETag, std::string()); +MAT_POP_WARNINGS }; -#ifdef _MSC_VER -#pragma warning(pop) -#endif - - class MockIEcsClient : public ecsclient::IEcsClient { public: MockIEcsClient(); @@ -67,9 +59,8 @@ class MockIEcsClient : public ecsclient::IEcsClient { MOCK_METHOD0(ResumeSendingRequests, void()); }; -#if defined(__clang__) -#pragma clang diagnostic pop -#endif +MAT_POP_WARNINGS } // namespace testing +#endif // #ifndef MOCKIECSCLIENT_HPP \ No newline at end of file diff --git a/tests/common/MockITenantDataSerializer.hpp b/tests/common/MockITenantDataSerializer.hpp index 0574bce9b..dde087d81 100644 --- a/tests/common/MockITenantDataSerializer.hpp +++ b/tests/common/MockITenantDataSerializer.hpp @@ -2,37 +2,30 @@ // Copyright (c) 2015-2020 Microsoft Corporation and Contributors. // SPDX-License-Identifier: Apache-2.0 // - -#pragma once +#ifndef MOCKITENANTDATASERIALIZER_HPP +#define MOCKITENANTDATASERIALIZER_HPP #include "common/Common.hpp" #include #include "gmock/gmock.h" +#include "mat/CompilerWarnings.hpp" using namespace MAT; using namespace MAT::ControlPlane; namespace testing { -#pragma warning(push) -#pragma warning(disable:4373) - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Winconsistent-missing-override" // GMock MOCK_METHOD* macros don't use the override keyword. -#endif - class MockITenantDataSerializer : public ITenantDataSerializer { public: - ~MockITenantDataSerializer() {} + ~MockITenantDataSerializer() noexcept = default; +MAT_PUSH_WARNINGS +MAT_DISABLE_WARNING_INCONSISTENT_MISSING_OVERRIDE MOCK_CONST_METHOD1(SerializeTenantData, std::string(TenantDataPtr tenantData)); MOCK_CONST_METHOD1(DeserializeTenantData, TenantDataPtr(const std::string& string)); +MAT_POP_WARNINGS }; -#if defined(__clang__) -#pragma clang diagnostic pop -#endif +} // namespace testing -#pragma warning(pop) -} // namespace testing \ No newline at end of file +#endif // #ifndef MOCKITENANTDATASERIALIZER_HPP \ No newline at end of file diff --git a/tests/functests/BondDecoderTests.cpp b/tests/functests/BondDecoderTests.cpp index 619cf5929..2f4b80f5b 100644 --- a/tests/functests/BondDecoderTests.cpp +++ b/tests/functests/BondDecoderTests.cpp @@ -9,10 +9,6 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#ifdef _MSC_VER -#pragma warning (disable : 4389) -#endif - #include "common/Common.hpp" #include "LogManager.hpp" diff --git a/tests/functests/Main.cpp b/tests/functests/Main.cpp index b036d93af..4d6df4d51 100644 --- a/tests/functests/Main.cpp +++ b/tests/functests/Main.cpp @@ -25,7 +25,6 @@ class TestStatusLogger : public testing::EmptyTestEventListener { }; #ifdef _MSC_VER -#pragma warning(suppress:4447) // 'main' signature found without threading model. Consider using 'int main(Platform::Array^ args)'. #define MAIN_CDECL __cdecl #else #define MAIN_CDECL diff --git a/tests/unittests/HttpDeflateCompressionTests.cpp b/tests/unittests/HttpDeflateCompressionTests.cpp index c652b3abb..a08efa517 100644 --- a/tests/unittests/HttpDeflateCompressionTests.cpp +++ b/tests/unittests/HttpDeflateCompressionTests.cpp @@ -6,6 +6,7 @@ #include "common/Common.hpp" #include "compression/HttpDeflateCompression.hpp" #include "config/RuntimeConfig_Default.hpp" +#include "mat/CompilerWarnings.hpp" #include #include "zlib.h" @@ -126,10 +127,8 @@ TEST_F(HttpDeflateCompressionTests, WorksMultipleTimes) TEST_F(HttpDeflateCompressionTests, HasReasonableCompressionRatio) { -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4125) -#endif +MAT_PUSH_WARNINGS +MAT_DISABLE_WARNING_DECIMAL_TERMINATES_OCTAL_ESCAPE_SEQUCENCE static char const bond[] = "+\n\001I\003sct\215\t\t\001\nservice_id\0011\251$772bcee2-8c19-454b-9af7-99b97ae4afde\321" "\006\262\305\361\313\364T\320\a\004\313\b\n\001)$0ac61ae4-ce84-430e-98d3-81adfb88c6a0q" @@ -143,9 +142,7 @@ TEST_F(HttpDeflateCompressionTests, HasReasonableCompressionRatio) "ay\016act_sent_count\0010 act_sent_failure_and_retry_count\0010\016act_session_id$39d9160" "f-396d-4427-ad76-9dedc5dea386\reventpriority\0012\315\036\t\n\001\020VideoPublisherIdP\02" "4i\t123456789\000\000\000\000"; -#ifdef _MSC_VER -#pragma warning(pop) -#endif +MAT_POP_WARNINGS size_t const size = sizeof(bond) - 1; EventsUploadContextPtr event = std::make_shared(); diff --git a/tests/unittests/Main.cpp b/tests/unittests/Main.cpp index 125835efe..8dab828d2 100644 --- a/tests/unittests/Main.cpp +++ b/tests/unittests/Main.cpp @@ -26,7 +26,6 @@ class TestStatusLogger : public testing::EmptyTestEventListener { } }; #ifdef _MSC_VER -#pragma warning(suppress:4447) // 'main' signature found without threading model. Consider using 'int main(Platform::Array^ args)'. #define MAIN_CDECL __cdecl #else #define MAIN_CDECL From 4de6d1d3f5fdc7811248093bcacb22302bd5cff3 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Fri, 16 Apr 2021 11:31:14 -0700 Subject: [PATCH 14/17] Replace #else bodies with #error, to fail quickly on unsupported compilers. --- lib/include/mat/CompilerWarnings.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/include/mat/CompilerWarnings.hpp b/lib/include/mat/CompilerWarnings.hpp index d4468eb4f..4d866e26a 100644 --- a/lib/include/mat/CompilerWarnings.hpp +++ b/lib/include/mat/CompilerWarnings.hpp @@ -2,8 +2,8 @@ // Copyright (c) 2015-2020 Microsoft Corporation and Contributors. // SPDX-License-Identifier: Apache-2.0 // -#ifndef COMPILERWARNINGS_HPP -#define COMPILERWARNINGS_HPP +#ifndef MAT_COMPILERWARNINGS_HPP +#define MAT_COMPILERWARNINGS_HPP #if defined(_MSC_VER) @@ -27,9 +27,7 @@ #else -#define MAT_PUSH_WARNINGS -#define MAT_POP_WARNINGS -#define MAT_DISABLE_WARNING(warningName) +#error "Unsupported compiler toolchain." #endif @@ -56,6 +54,10 @@ Define specific Disable warning macros here. Keep macros ordered alphabetically. #define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(-Wtype-limits) #define MAT_DISABLE_WARNING_INCONSISTENT_MISSING_OVERRIDE MAT_DISABLE_WARNING(-Winconsistent-missing-override) +#else + +#error "Unsupported compiler toolchain." + #endif -#endif // COMPILERWARNINGS_HPP \ No newline at end of file +#endif // MAT_COMPILERWARNINGS_HPP \ No newline at end of file From c17a01d914f369806e09b652af535482beeb6398 Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Fri, 16 Apr 2021 11:37:33 -0700 Subject: [PATCH 15/17] lib/include/mat/CompilerWarnings.hpp:42:48: 'OVERRIDEN' is a misspelling of 'OVERRIDDEN' --- lib/include/mat/CompilerWarnings.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/include/mat/CompilerWarnings.hpp b/lib/include/mat/CompilerWarnings.hpp index 4d866e26a..8a902ee7a 100644 --- a/lib/include/mat/CompilerWarnings.hpp +++ b/lib/include/mat/CompilerWarnings.hpp @@ -27,7 +27,7 @@ #else -#error "Unsupported compiler toolchain." +#error Unsupported compiler toolchain. #endif @@ -39,7 +39,7 @@ Define specific Disable warning macros here. Keep macros ordered alphabetically. #if defined(_MSC_VER) -#define MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDEN MAT_DISABLE_WARNING(4373) +#define MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDDEN MAT_DISABLE_WARNING(4373) #define MAT_DISABLE_WARNING_DECIMAL_TERMINATES_OCTAL_ESCAPE_SEQUCENCE MAT_DISABLE_WARNING(4125) #define MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL MAT_DISABLE_WARNING(4996) #define MAT_DISABLE_WARNING_EXCEPTION_EXECUTE_HANDLER MAT_DISABLE_WARNING(6320) @@ -48,7 +48,7 @@ Define specific Disable warning macros here. Keep macros ordered alphabetically. #elif defined(__clang__) || defined(__GCC__) -#define MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDEN +#define MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDDEN #define MAT_DISABLE_WARNING_DECIMAL_TERMINATES_OCTAL_ESCAPE_SEQUCENCE #define MAT_DISABLE_WARNING_DEPRECATED_METHOD_CALL MAT_DISABLE_WARNING(-Wdeprecated-declarations) #define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(-Wtype-limits) @@ -56,7 +56,7 @@ Define specific Disable warning macros here. Keep macros ordered alphabetically. #else -#error "Unsupported compiler toolchain." +#error Unsupported compiler toolchain. #endif From 4ef02f7cbd26eb37c3e85718a7a713412474505b Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Fri, 16 Apr 2021 13:53:59 -0700 Subject: [PATCH 16/17] Replace __GCC__ with __GNUC__, which is the actual macro that GCC sets. Whoops. --- lib/include/mat/CompilerWarnings.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/include/mat/CompilerWarnings.hpp b/lib/include/mat/CompilerWarnings.hpp index 8a902ee7a..3323f28e5 100644 --- a/lib/include/mat/CompilerWarnings.hpp +++ b/lib/include/mat/CompilerWarnings.hpp @@ -11,7 +11,7 @@ #define MAT_POP_WARNINGS __pragma(warning(pop)) #define MAT_DISABLE_WARNING(warningNumber) __pragma(warning(disable: warningNumber)) -#elif defined(__clang__) || defined(__GCC__) +#elif defined(__clang__) || defined(__GNUC__) #define MAT_STRINGIFY_PRAGMA(args) _Pragma(#args) @@ -46,7 +46,7 @@ Define specific Disable warning macros here. Keep macros ordered alphabetically. #define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(4296) #define MAT_DISABLE_WARNING_INCONSISTENT_MISSING_OVERRIDE -#elif defined(__clang__) || defined(__GCC__) +#elif defined(__clang__) || defined(__GNUC__) #define MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDDEN #define MAT_DISABLE_WARNING_DECIMAL_TERMINATES_OCTAL_ESCAPE_SEQUCENCE From 372672b9316baabd27cfdd5d8cbb2ed681ff662b Mon Sep 17 00:00:00 2001 From: Matt Koscumb Date: Fri, 16 Apr 2021 13:56:41 -0700 Subject: [PATCH 17/17] Replace misspelling with MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDDEN --- tests/common/MockIEcsClient.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/MockIEcsClient.hpp b/tests/common/MockIEcsClient.hpp index abdcd16d3..3f14c61ce 100644 --- a/tests/common/MockIEcsClient.hpp +++ b/tests/common/MockIEcsClient.hpp @@ -22,7 +22,7 @@ class MockIEcsConfig : public ecsclient::IEcsConfig, // Avoid noise caused by ECS using const modifier on value-type arguments like int, bool and double. // The modifiers are lost inside Google Mock, the resulting signature differs and compiler complains. MAT_PUSH_WARNINGS -MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDEN // C4373: previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers +MAT_DISABLE_WARNING_CONST_PARAMETER_NOT_OVERRIDDEN // C4373: previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers MOCK_CONST_METHOD3(GetSetting, std::string(std::string const & t, std::string const &, std::string const &)); MOCK_CONST_METHOD3(GetSettingAsString, std::string(std::string const &, std::string const &, std::string const &)); MOCK_CONST_METHOD3(GetSettingAsInt, int(std::string const &, std::string const &, int const defaultValue));