diff --git a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems index 68bf9f142..3e8d55d2e 100644 --- a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems +++ b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems @@ -205,4 +205,4 @@ - + \ No newline at end of file diff --git a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters index e86490294..ce87fc1a7 100644 --- a/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters +++ b/Solutions/Clienttelemetry/Clienttelemetry.vcxitems.filters @@ -1,196 +1,196 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/api/LogManagerImpl.cpp b/lib/api/LogManagerImpl.cpp index 6a98e6406..3bbcb7cf9 100644 --- a/lib/api/LogManagerImpl.cpp +++ b/lib/api/LogManagerImpl.cpp @@ -2,10 +2,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // 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" diff --git a/lib/http/HttpClient_WinInet.cpp b/lib/http/HttpClient_WinInet.cpp index 0589f9796..e36b14b21 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" @@ -563,6 +561,5 @@ bool HttpClient_WinInet::IsMsRootCheckRequired() } } MAT_NS_END -#pragma warning(pop) #endif // HAVE_MAT_DEFAULT_HTTP_CLIENT // clang-format on diff --git a/lib/include/mat/CompilerWarnings.hpp b/lib/include/mat/CompilerWarnings.hpp new file mode 100644 index 000000000..3323f28e5 --- /dev/null +++ b/lib/include/mat/CompilerWarnings.hpp @@ -0,0 +1,63 @@ +// +// Copyright (c) 2015-2020 Microsoft Corporation and Contributors. +// SPDX-License-Identifier: Apache-2.0 +// +#ifndef MAT_COMPILERWARNINGS_HPP +#define MAT_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(__GNUC__) + +#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 + +#error Unsupported compiler toolchain. + +#endif + +/* + +Define specific Disable warning macros here. Keep macros ordered alphabetically. + +*/ + +#if defined(_MSC_VER) + +#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) +#define MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE MAT_DISABLE_WARNING(4296) +#define MAT_DISABLE_WARNING_INCONSISTENT_MISSING_OVERRIDE + +#elif defined(__clang__) || defined(__GNUC__) + +#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) +#define MAT_DISABLE_WARNING_INCONSISTENT_MISSING_OVERRIDE MAT_DISABLE_WARNING(-Winconsistent-missing-override) + +#else + +#error Unsupported compiler toolchain. + +#endif + +#endif // MAT_COMPILERWARNINGS_HPP \ No newline at end of file diff --git a/lib/offline/OfflineStorage_SQLite.cpp b/lib/offline/OfflineStorage_SQLite.cpp index 781a5dc2e..5ebffabd0 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 @@ -765,16 +766,8 @@ namespace MAT_NS_BEGIN { if (!stmt.select() || !stmt.getRow(m_pageSize)) { return false; } } -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4296) // expression always false. -#elif defined( __clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wtype-limits" // error: comparison of unsigned expression < 0 is always false [-Werror=type-limits] -#elif defined(__GNUC__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wtype-limits" // error: comparison of unsigned expression < 0 is always false [-Werror=type-limits] -#endif +MAT_PUSH_WARNINGS +MAT_DISABLE_WARNING_EXPRESSION_IS_ALWAYS_FALSE // error: comparison of unsigned expression < 0 is always false [-Werror=type-limits] #define PREPARE_SQL(var_, stmt_) \ if ((var_ = m_db->prepare(stmt_)) < 0) { return false; } @@ -863,13 +856,7 @@ namespace MAT_NS_BEGIN { #undef PREPARE_SQL -#if defined(_MSC_VER) -#pragma warning(pop) -#elif defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#pragma GCC diagnostic pop -#endif +MAT_POP_WARNINGS ResizeDb(); return true; diff --git a/lib/pal/PAL.cpp b/lib/pal/PAL.cpp index 641656842..8726e608e 100644 --- a/lib/pal/PAL.cpp +++ b/lib/pal/PAL.cpp @@ -170,10 +170,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) @@ -287,9 +283,6 @@ namespace PAL_NS_BEGIN { (void)(fmt); #endif /* of #ifdef HAVE_MAT_LOGGING */ } -#ifdef _MSC_VER -#pragma warning(pop) -#endif } // namespace detail @@ -304,17 +297,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); #elif defined(__APPLE__) auto uuid {CFUUIDCreate(kCFAllocatorDefault)}; @@ -367,9 +354,6 @@ namespace PAL_NS_BEGIN { return buf; #endif } -#ifdef _MSC_VER -#pragma warning(pop) -#endif int64_t PlatformAbstractionLayer::getUtcSystemTimeMs() const { diff --git a/lib/pal/desktop/NetworkDetector.cpp b/lib/pal/desktop/NetworkDetector.cpp index 90c3e5724..d9d66232d 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 diff --git a/lib/pal/desktop/WindowsDesktopSystemInformationImpl.cpp b/lib/pal/desktop/WindowsDesktopSystemInformationImpl.cpp index d910f99e7..0c61438e8 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") diff --git a/lib/tracing/api/DebugLogger.hpp b/lib/tracing/api/DebugLogger.hpp index a07d2929b..6c914064f 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. /// @@ -602,8 +603,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 @@ -611,7 +612,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 << "|"; } diff --git a/tests/common/MockIEcsClient.hpp b/tests/common/MockIEcsClient.hpp index 706a79dbe..7ce8b2474 100644 --- a/tests/common/MockIEcsClient.hpp +++ b/tests/common/MockIEcsClient.hpp @@ -2,23 +2,15 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // 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_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)); @@ -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 aace4c659..194d1bf05 100644 --- a/tests/common/MockITenantDataSerializer.hpp +++ b/tests/common/MockITenantDataSerializer.hpp @@ -2,37 +2,30 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // 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/APITest.cpp b/tests/functests/APITest.cpp index 510d09477..c14b31728 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" diff --git a/tests/functests/BondDecoderTests.cpp b/tests/functests/BondDecoderTests.cpp index e60f10092..658e7300b 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 bab8476a9..398671218 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 0addaf5d7..af55741df 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 303174749..00111aa6b 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