From 4288671869d1f1867e9f3641dd26e5769dabb2b9 Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Thu, 29 Dec 2022 16:11:38 +0800 Subject: [PATCH 01/12] clang: Suppress `-Winconsistent-missing-override` in winrt::implements --- strings/base_implements.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/strings/base_implements.h b/strings/base_implements.h index a81df5f8e..7d5e1b9a2 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -1462,6 +1462,10 @@ WINRT_EXPORT namespace winrt return result; } +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Winconsistent-missing-override" +#endif impl::hresult_type __stdcall QueryInterface(impl::guid_type const& id, void** object) noexcept { return root_implements_type::QueryInterface(reinterpret_cast(id), object); @@ -1493,6 +1497,9 @@ WINRT_EXPORT namespace winrt { return root_implements_type::abi_GetTrustLevel(reinterpret_cast(value)); } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif void* find_interface(guid const& id) const noexcept override { From 1e9fec6ecb5479d5af7802707039691af40779a3 Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Thu, 29 Dec 2022 17:16:17 +0800 Subject: [PATCH 02/12] Guard MSVC-specific `#pragma` with _MSC_VER --- strings/base_activation.h | 4 ++++ strings/base_events.h | 2 ++ strings/base_identity.h | 4 ++++ strings/base_implements.h | 2 ++ strings/base_macros.h | 6 ++++++ strings/base_string_input.h | 4 ++++ strings/base_version.h | 2 +- 7 files changed, 23 insertions(+), 1 deletion(-) diff --git a/strings/base_activation.h b/strings/base_activation.h index d77b8f5d8..5c6f938d9 100644 --- a/strings/base_activation.h +++ b/strings/base_activation.h @@ -196,8 +196,10 @@ namespace winrt::impl #ifdef _WIN64 inline constexpr uint32_t memory_allocation_alignment{ 16 }; +#ifdef _MSC_VER #pragma warning(push) #pragma warning(disable:4324) // structure was padded due to alignment specifier +#endif struct alignas(16) slist_entry { slist_entry* next; @@ -217,7 +219,9 @@ namespace winrt::impl uint64_t reserved4 : 60; } reserved2; }; +#ifdef _MSC_VER #pragma warning(pop) +#endif #else inline constexpr uint32_t memory_allocation_alignment{ 8 }; struct slist_entry diff --git a/strings/base_events.h b/strings/base_events.h index b5783555b..131186864 100644 --- a/strings/base_events.h +++ b/strings/base_events.h @@ -331,7 +331,9 @@ namespace winrt::impl com_ptr> make_event_array(uint32_t const capacity) { void* raw = ::operator new(sizeof(event_array) + (sizeof(T)* capacity)); +#ifdef _MSC_VER #pragma warning(suppress: 6386) +#endif return { new(raw) event_array(capacity), take_ownership_from_abi }; } diff --git a/strings/base_identity.h b/strings/base_identity.h index 52a77dfc4..0f4a163b6 100644 --- a/strings/base_identity.h +++ b/strings/base_identity.h @@ -453,12 +453,16 @@ namespace winrt::impl template struct pinterface_guid { +#ifdef _MSC_VER #pragma warning(suppress: 4307) +#endif static constexpr guid value{ generate_guid(signature::data) }; }; template +#ifdef _MSC_VER #pragma warning(suppress: 4307) +#endif inline constexpr auto name_v { combine diff --git a/strings/base_implements.h b/strings/base_implements.h index 7d5e1b9a2..80a69faa7 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -340,7 +340,9 @@ namespace winrt::impl template struct uncloaked_iids> { +#ifdef _MSC_VER #pragma warning(suppress: 4307) +#endif static constexpr std::array value{ winrt::guid_of() ... }; }; diff --git a/strings/base_macros.h b/strings/base_macros.h index d48db139d..1dd63c111 100644 --- a/strings/base_macros.h +++ b/strings/base_macros.h @@ -15,11 +15,13 @@ #define WINRT_IMPL_SHIM(...) (*(abi_t<__VA_ARGS__>**)&static_cast<__VA_ARGS__ const&>(static_cast(*this))) +#ifdef _MSC_VER // Note: this is a workaround for a false-positive warning produced by the Visual C++ 15.9 compiler. #pragma warning(disable : 5046) // Note: this is a workaround for a false-positive warning produced by the Visual C++ 16.3 compiler. #pragma warning(disable : 4268) +#endif #if defined(__cpp_lib_coroutine) || defined(__cpp_coroutines) || defined(_RESUMABLE_FUNCTIONS_SUPPORTED) #define WINRT_IMPL_COROUTINES @@ -87,7 +89,9 @@ typedef struct _GUID GUID; #define WINRT_IMPL_SOURCE_LOCATION_FORWARD , sourceInformation #define WINRT_IMPL_SOURCE_LOCATION_FORWARD_SINGLE_PARAM sourceInformation +#ifdef _MSC_VER #pragma detect_mismatch("WINRT_SOURCE_LOCATION", "true") +#endif #else #define WINRT_IMPL_SOURCE_LOCATION_ARGS_NO_DEFAULT #define WINRT_IMPL_SOURCE_LOCATION_ARGS @@ -96,5 +100,7 @@ typedef struct _GUID GUID; #define WINRT_IMPL_SOURCE_LOCATION_FORWARD #define WINRT_IMPL_SOURCE_LOCATION_FORWARD_SINGLE_PARAM +#ifdef _MSC_VER #pragma detect_mismatch("WINRT_SOURCE_LOCATION", "false") #endif +#endif diff --git a/strings/base_string_input.h b/strings/base_string_input.h index 786b31519..8cfea212b 100644 --- a/strings/base_string_input.h +++ b/strings/base_string_input.h @@ -3,13 +3,17 @@ WINRT_EXPORT namespace winrt::param { struct hstring { +#ifdef _MSC_VER #pragma warning(suppress: 26495) +#endif hstring() noexcept : m_handle(nullptr) {} hstring(hstring const& values) = delete; hstring& operator=(hstring const& values) = delete; hstring(std::nullptr_t) = delete; +#ifdef _MSC_VER #pragma warning(suppress: 26495) +#endif hstring(winrt::hstring const& value) noexcept : m_handle(get_abi(value)) { } diff --git a/strings/base_version.h b/strings/base_version.h index 227f10402..adb3608da 100644 --- a/strings/base_version.h +++ b/strings/base_version.h @@ -4,13 +4,13 @@ extern "C" __declspec(selectany) char const * const WINRT_version = "C++/WinRT version:" CPPWINRT_VERSION; +#if defined(_MSC_VER) #ifdef _M_IX86 #pragma comment(linker, "/include:_WINRT_version") #else #pragma comment(linker, "/include:WINRT_version") #endif -#if defined(_MSC_VER) #pragma detect_mismatch("C++/WinRT version", CPPWINRT_VERSION) #endif From dabb76c31162f749da247d9f56f872844ab3d8fd Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Thu, 29 Dec 2022 17:22:03 +0800 Subject: [PATCH 03/12] tests: Guard MSVC-specific `#pragma` with _MSC_VER --- test/old_tests/Component/pch.h | 2 ++ test/old_tests/Composable/precomp.hpp | 2 ++ test/old_tests/UnitTests/Errors.cpp | 2 ++ test/old_tests/UnitTests/IReference.cpp | 4 +++- test/old_tests/UnitTests/constexpr.cpp | 2 ++ test/old_tests/UnitTests/enum_flags.cpp | 2 ++ test/old_tests/UnitTests/hresult_error.cpp | 2 ++ test/old_tests/UnitTests/meta.cpp | 2 ++ 8 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/old_tests/Component/pch.h b/test/old_tests/Component/pch.h index 7d1624884..5d84eecb6 100644 --- a/test/old_tests/Component/pch.h +++ b/test/old_tests/Component/pch.h @@ -1,6 +1,8 @@ #pragma once +#ifdef _MSC_VER #pragma warning(disable:4100) +#endif #include "winrt/Windows.Foundation.Collections.h" #include "winrt/Composable.h" diff --git a/test/old_tests/Composable/precomp.hpp b/test/old_tests/Composable/precomp.hpp index aa5d110c2..29f44db46 100644 --- a/test/old_tests/Composable/precomp.hpp +++ b/test/old_tests/Composable/precomp.hpp @@ -1,6 +1,8 @@ #pragma once +#ifdef _MSC_VER #pragma warning(disable:4100) +#endif #include "winrt/Windows.Foundation.h" #include "winrt/Composable.h" diff --git a/test/old_tests/UnitTests/Errors.cpp b/test/old_tests/UnitTests/Errors.cpp index 33e9b422f..472d633f1 100644 --- a/test/old_tests/UnitTests/Errors.cpp +++ b/test/old_tests/UnitTests/Errors.cpp @@ -66,7 +66,9 @@ void test_exception(HRESULT const code, std::wstring_view message) } } +#ifdef _MSC_VER #pragma warning(disable: 4702) // unreachable code +#endif TEST_CASE("Errors") { // These won't throw. diff --git a/test/old_tests/UnitTests/IReference.cpp b/test/old_tests/UnitTests/IReference.cpp index 50a349f89..cc03c5b9b 100644 --- a/test/old_tests/UnitTests/IReference.cpp +++ b/test/old_tests/UnitTests/IReference.cpp @@ -1,7 +1,9 @@ #include "pch.h" #include "catch.hpp" +#ifdef _MSC_VER #pragma warning(disable:4471) // a forward declaration of an unscoped enumeration must have an underlying type +#endif #include using namespace winrt; @@ -55,4 +57,4 @@ TEST_CASE("IReference, set WinRT runtime class property") { HttpContentDispositionHeaderValue value(L"inline"); value.Size(200); -} \ No newline at end of file +} diff --git a/test/old_tests/UnitTests/constexpr.cpp b/test/old_tests/UnitTests/constexpr.cpp index a881a2659..686d6ede9 100644 --- a/test/old_tests/UnitTests/constexpr.cpp +++ b/test/old_tests/UnitTests/constexpr.cpp @@ -2,7 +2,9 @@ #include "catch.hpp" #include "string_view_compare.h" +#ifdef _MSC_VER #pragma warning(disable:4471) // a forward declaration of an unscoped enumeration must have an underlying type +#endif #include using namespace std::string_view_literals; diff --git a/test/old_tests/UnitTests/enum_flags.cpp b/test/old_tests/UnitTests/enum_flags.cpp index 3b8274f7e..670199c88 100644 --- a/test/old_tests/UnitTests/enum_flags.cpp +++ b/test/old_tests/UnitTests/enum_flags.cpp @@ -1,7 +1,9 @@ #include "pch.h" #include "catch.hpp" +#ifdef _MSC_VER #pragma warning(disable:4471) // a forward declaration of an unscoped enumeration must have an underlying type +#endif #include #include "winrt/Windows.ApplicationModel.Appointments.h" diff --git a/test/old_tests/UnitTests/hresult_error.cpp b/test/old_tests/UnitTests/hresult_error.cpp index 23ad209af..cdeb6141c 100644 --- a/test/old_tests/UnitTests/hresult_error.cpp +++ b/test/old_tests/UnitTests/hresult_error.cpp @@ -482,7 +482,9 @@ TEST_CASE("hresult, exception") } } +#ifdef _MSC_VER #pragma warning(disable: 4702) // unreachable code +#endif TEST_CASE("hresult, throw_last_error") { SetLastError(ERROR_CANCELLED); diff --git a/test/old_tests/UnitTests/meta.cpp b/test/old_tests/UnitTests/meta.cpp index e19a7202a..e8e61dda6 100644 --- a/test/old_tests/UnitTests/meta.cpp +++ b/test/old_tests/UnitTests/meta.cpp @@ -1,7 +1,9 @@ #include "pch.h" #include "catch.hpp" +#ifdef _MSC_VER #pragma warning(disable: 4505) +#endif using namespace winrt; using namespace Windows::Foundation; From bc7b7751ad30b9de8825e8b16cd049b27e9666e6 Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Thu, 29 Dec 2022 17:25:31 +0800 Subject: [PATCH 04/12] clang: Fix `-Wstring-plus-int` warning --- test/test/guid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test/guid.cpp b/test/test/guid.cpp index 48d277e64..dc91c7d3c 100644 --- a/test/test/guid.cpp +++ b/test/test/guid.cpp @@ -20,7 +20,7 @@ TEST_CASE("guid") STATIC_REQUIRE_GUID_EQUAL(winrt::guid("00112233-4455-6677-8899-aabbccddeeff"), expected); REQUIRE(winrt::guid("00112233-4455-6677-8899-aabbccddeeff") == expected); - REQUIRE(winrt::guid({ "{00112233-4455-6677-8899-aabbccddeeff}" + 1, 36 }) == expected); + REQUIRE(winrt::guid({ &"{00112233-4455-6677-8899-aabbccddeeff}"[1], 36 }) == expected); REQUIRE(winrt::guid("{00112233-4455-6677-8899-aabbccddeeff}") == expected); REQUIRE(winrt::guid("(00112233-4455-6677-8899-aabbccddeeff)") == expected); @@ -34,4 +34,4 @@ TEST_CASE("guid") // Verify that you can constexpr-construct a guid from a GUID. constexpr winrt::guid from_abi_guid = GUID{ 0x00112233, 0x4455, 0x6677, { 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff } }; STATIC_REQUIRE_GUID_EQUAL(from_abi_guid, expected); -} \ No newline at end of file +} From dc096032c5747a3a93c45646207792d16a2ee5bf Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Thu, 29 Dec 2022 17:46:32 +0800 Subject: [PATCH 05/12] gcc: Fix `-Wsign-compare` warning --- test/old_tests/UnitTests/hresult_error.cpp | 2 +- test/test/custom_error.cpp | 2 +- test/test_cpp20/custom_error.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/old_tests/UnitTests/hresult_error.cpp b/test/old_tests/UnitTests/hresult_error.cpp index cdeb6141c..fa15c2a1d 100644 --- a/test/old_tests/UnitTests/hresult_error.cpp +++ b/test/old_tests/UnitTests/hresult_error.cpp @@ -3,7 +3,7 @@ // Missing in mingw-w64 #ifndef E_BOUNDS -#define E_BOUNDS (0x8000000B) +#define E_BOUNDS ((HRESULT)0x8000000B) #endif extern "C" BOOL __stdcall RoOriginateLanguageException(HRESULT error, void* message, void* languageException); diff --git a/test/test/custom_error.cpp b/test/test/custom_error.cpp index 8e1855e31..dbdf31ab9 100644 --- a/test/test/custom_error.cpp +++ b/test/test/custom_error.cpp @@ -114,7 +114,7 @@ TEST_CASE("custom_error_logger") #endif REQUIRE(s_loggerArgs.returnAddress); - REQUIRE(s_loggerArgs.result == 0x80000018); // E_ILLEGAL_DELEGATE_ASSIGNMENT) + REQUIRE(s_loggerArgs.result == static_cast(0x80000018)); // E_ILLEGAL_DELEGATE_ASSIGNMENT) // Remove global handler winrt_throw_hresult_handler = nullptr; diff --git a/test/test_cpp20/custom_error.cpp b/test/test_cpp20/custom_error.cpp index 707088cd9..e7e4b83aa 100644 --- a/test/test_cpp20/custom_error.cpp +++ b/test/test_cpp20/custom_error.cpp @@ -66,7 +66,7 @@ TEST_CASE("custom_error_logger") #endif REQUIRE(s_loggerArgs.returnAddress); - REQUIRE(s_loggerArgs.result == 0x80000018); // E_ILLEGAL_DELEGATE_ASSIGNMENT) + REQUIRE(s_loggerArgs.result == static_cast(0x80000018)); // E_ILLEGAL_DELEGATE_ASSIGNMENT) // Remove global handler winrt_throw_hresult_handler = nullptr; From ea1a53aa89f410483688fb08bba40571aad00dbf Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Thu, 29 Dec 2022 17:50:39 +0800 Subject: [PATCH 06/12] gcc: Fix value/function unused warnings --- test/old_tests/UnitTests/Main.cpp | 4 ++-- test/old_tests/UnitTests/apartment_context.cpp | 3 +++ test/test/await_completed.cpp | 3 ++- test/test/disconnected.cpp | 3 +++ test/test/event_clear.cpp | 2 ++ test/test/main.cpp | 4 ++-- test/test_cpp20/main.cpp | 4 ++-- test/test_fast/main.cpp | 4 ++-- test/test_fast_fwd/main.cpp | 4 ++-- test/test_module_lock_custom/main.cpp | 4 ++-- test/test_module_lock_none/main.cpp | 4 ++-- test/test_slow/main.cpp | 4 ++-- test/test_win7/main.cpp | 4 ++-- 13 files changed, 28 insertions(+), 19 deletions(-) diff --git a/test/old_tests/UnitTests/Main.cpp b/test/old_tests/UnitTests/Main.cpp index 3e5ecf03e..1f3818bda 100644 --- a/test/old_tests/UnitTests/Main.cpp +++ b/test/old_tests/UnitTests/Main.cpp @@ -15,9 +15,9 @@ int main(int argc, char * argv[]) init_apartment(); std::set_terminate([]{ reportFatal("Abnormal termination"); ExitProcess(1); }); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); int const result = Catch::Session().run(argc, argv); diff --git a/test/old_tests/UnitTests/apartment_context.cpp b/test/old_tests/UnitTests/apartment_context.cpp index 8500a3100..e42c71160 100644 --- a/test/old_tests/UnitTests/apartment_context.cpp +++ b/test/old_tests/UnitTests/apartment_context.cpp @@ -76,6 +76,8 @@ namespace #endif +// Exclude on mingw-w64 to suppress `-Wunused-function` +#if !defined(__MINGW32__) bool is_nta_on_mta() { APTTYPE type; @@ -83,6 +85,7 @@ namespace check_hresult(CoGetApartmentType(&type, &qualifier)); return (type == APTTYPE_NA) && (qualifier == APTTYPEQUALIFIER_NA_ON_MTA || qualifier == APTTYPEQUALIFIER_NA_ON_IMPLICIT_MTA); } +#endif bool is_mta() { diff --git a/test/test/await_completed.cpp b/test/test/await_completed.cpp index 8ee3a0cce..be33e818f 100644 --- a/test/test/await_completed.cpp +++ b/test/test/await_completed.cpp @@ -62,6 +62,7 @@ namespace // is the ABI breaking change with MSVC standard-conforming coroutines.) REQUIRE(consumed <= sync_usage); #else + (void)sync_usage; // MSVC standard-conforming coroutines (as well as gcc and clang coroutines) // support "bool await_suspend" just fine. REQUIRE(consumed == 0); @@ -71,4 +72,4 @@ namespace TEST_CASE("await_completed_await") { SyncCompletion().get(); -} \ No newline at end of file +} diff --git a/test/test/disconnected.cpp b/test/test/disconnected.cpp index 8c7e30e49..53dfbd142 100644 --- a/test/test/disconnected.cpp +++ b/test/test/disconnected.cpp @@ -35,6 +35,8 @@ namespace co_return 123; } +// Exclude on mingw-w64 to suppress `-Wunused-function` +#if !defined(__MINGW32__) bool is_mta() { APTTYPE type; @@ -42,6 +44,7 @@ namespace check_hresult(CoGetApartmentType(&type, &qualifier)); return type == APTTYPE_MTA; } +#endif } TEST_CASE("disconnected,handler,1") diff --git a/test/test/event_clear.cpp b/test/test/event_clear.cpp index 54db2cef7..54f3d62b7 100644 --- a/test/test/event_clear.cpp +++ b/test/test/event_clear.cpp @@ -16,11 +16,13 @@ TEST_CASE("event_clear") { counter += 1; }); + (void)a; auto b = event.add([&](auto && ...) { counter += 10; }); + (void)b; REQUIRE(counter == 0); event(0, 0); diff --git a/test/test/main.cpp b/test/test/main.cpp index 47d65e667..1481be4dd 100644 --- a/test/test/main.cpp +++ b/test/test/main.cpp @@ -14,9 +14,9 @@ int main(int const argc, char** argv) init_apartment(); std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); }); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); return Catch::Session().run(argc, argv); } diff --git a/test/test_cpp20/main.cpp b/test/test_cpp20/main.cpp index 10150c369..30687e00c 100644 --- a/test/test_cpp20/main.cpp +++ b/test/test_cpp20/main.cpp @@ -14,9 +14,9 @@ int main(int const argc, char** argv) init_apartment(); std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); }); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); return Catch::Session().run(argc, argv); } diff --git a/test/test_fast/main.cpp b/test/test_fast/main.cpp index cb2203171..7590df7e1 100644 --- a/test/test_fast/main.cpp +++ b/test/test_fast/main.cpp @@ -10,9 +10,9 @@ int main(int const argc, char** argv) init_apartment(); std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); }); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); return Catch::Session().run(argc, argv); } diff --git a/test/test_fast_fwd/main.cpp b/test/test_fast_fwd/main.cpp index 88d30fba3..c5b6040f7 100644 --- a/test/test_fast_fwd/main.cpp +++ b/test/test_fast_fwd/main.cpp @@ -13,9 +13,9 @@ int main(int const argc, char** argv) init_apartment(); std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); }); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); return Catch::Session().run(argc, argv); } diff --git a/test/test_module_lock_custom/main.cpp b/test/test_module_lock_custom/main.cpp index 6680fdb51..862df57df 100644 --- a/test/test_module_lock_custom/main.cpp +++ b/test/test_module_lock_custom/main.cpp @@ -63,8 +63,8 @@ int main(int const argc, char** argv) { std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); }); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); return Catch::Session().run(argc, argv); } diff --git a/test/test_module_lock_none/main.cpp b/test/test_module_lock_none/main.cpp index ad6d83ace..57e40a542 100644 --- a/test/test_module_lock_none/main.cpp +++ b/test/test_module_lock_none/main.cpp @@ -68,8 +68,8 @@ int main(int const argc, char** argv) { std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); }); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); return Catch::Session().run(argc, argv); } diff --git a/test/test_slow/main.cpp b/test/test_slow/main.cpp index cb2203171..7590df7e1 100644 --- a/test/test_slow/main.cpp +++ b/test/test_slow/main.cpp @@ -10,9 +10,9 @@ int main(int const argc, char** argv) init_apartment(); std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); }); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); return Catch::Session().run(argc, argv); } diff --git a/test/test_win7/main.cpp b/test/test_win7/main.cpp index 10150c369..30687e00c 100644 --- a/test/test_win7/main.cpp +++ b/test/test_win7/main.cpp @@ -14,9 +14,9 @@ int main(int const argc, char** argv) init_apartment(); std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); }); _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); - _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); return Catch::Session().run(argc, argv); } From 9fe0157fcde04d586d489acb81fa44a9940c071f Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Thu, 29 Dec 2022 18:08:13 +0800 Subject: [PATCH 07/12] tests: gcc: Fix `-Wreorder` (ctor initialization) --- test/test/multi_threaded_common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test/multi_threaded_common.h b/test/test/multi_threaded_common.h index 971e56c6b..2170233fd 100644 --- a/test/test/multi_threaded_common.h +++ b/test/test/multi_threaded_common.h @@ -149,7 +149,7 @@ namespace concurrent_collections container const* owner; concurrency_checked_random_access_iterator() : owner(nullptr) {} - concurrency_checked_random_access_iterator(container const* c, iterator it) : owner(c), iterator(it) {} + concurrency_checked_random_access_iterator(container const* c, iterator it) : iterator(it), owner(c) {} // Implicit conversion from non-const iterator to const iterator. concurrency_checked_random_access_iterator(concurrency_checked_random_access_iterator other) : owner(other.owner), iterator(other.inner()) { } @@ -256,7 +256,7 @@ namespace concurrent_collections concurrency_guard() = default; concurrency_guard(concurrency_guard const& other) noexcept - : m_lock(0), hook(other.hook) + : hook(other.hook), m_lock(0) { auto guard = other.lock_nonconst(); } From 03226e301c10f3f2a99b24906928d28c8956dfe1 Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Thu, 29 Dec 2022 19:15:09 +0800 Subject: [PATCH 08/12] gcc: Fix `-Wclass-memaccess` warning `detach_abi(com_array&)` uses two `memset` calls to zero two objects, one is an `std::pair` (from [#1165]), the other is a `winrt::com_array` (to clear its data pointer to prevent its destructor from freeing the array). GCC rightfully warns about this because these types are not trivially copyable, so calling memset on it is UB. This change fixes the UB and the GCC warning by reverting the first `memset` back to using the `std::pair` constructor as before [#1165], and changing the second `memset` to setting the member fields directly. Since this requires access to protected members, the function body is moved into a private member function, then the `winrt::detach_abi` free function is made `friend` of `com_array` to allow it to call the member function. This fix is not applied when `_MSC_VER` is defined in order to preserve the current behaviour on MSVC, in case [#1165] is still relevant. [#1165]: https://github.com/microsoft/cppwinrt/pull/1165 --- strings/base_array.h | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/strings/base_array.h b/strings/base_array.h index 5d1bee3c5..9f20cf34e 100644 --- a/strings/base_array.h +++ b/strings/base_array.h @@ -345,6 +345,26 @@ WINRT_EXPORT namespace winrt this->m_size = size; } } + + std::pair> detach_abi() noexcept + { +#ifdef _MSC_VER + // https://github.com/microsoft/cppwinrt/pull/1165 + std::pair> result; + memset(&result, 0, sizeof(result)); + result.first = this->size(); + result.second = *reinterpret_cast*>(this); + memset(this, 0, sizeof(com_array)); +#else + std::pair> result(this->size(), *reinterpret_cast*>(this)); + this->m_data = nullptr; + this->m_size = 0; +#endif + return result; + } + + template + friend std::pair> detach_abi(com_array& object) noexcept; }; template com_array(uint32_t, C const&) -> com_array>; @@ -418,14 +438,9 @@ WINRT_EXPORT namespace winrt } template - auto detach_abi(com_array& object) noexcept + std::pair> detach_abi(com_array& object) noexcept { - std::pair> result; - memset(&result, 0, sizeof(result)); - result.first = object.size(); - result.second = *reinterpret_cast*>(&object); - memset(&object, 0, sizeof(com_array)); - return result; + return object.detach_abi(); } template From 42b2e6387998b297645867c7b3a1bde22a5324a7 Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Fri, 30 Dec 2022 21:01:35 +0800 Subject: [PATCH 09/12] tests: Suppress self-assign/self-move warnings --- test/old_tests/UnitTests/apartment_context.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/old_tests/UnitTests/apartment_context.cpp b/test/old_tests/UnitTests/apartment_context.cpp index e42c71160..1bdab7c8b 100644 --- a/test/old_tests/UnitTests/apartment_context.cpp +++ b/test/old_tests/UnitTests/apartment_context.cpp @@ -35,6 +35,11 @@ namespace context2 = nullptr; REQUIRE(!context2); +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wself-assign-overloaded" +#pragma clang diagnostic ignored "-Wself-move" +#endif // Self-copy-assignment context = context; REQUIRE(context); @@ -42,6 +47,9 @@ namespace // Self-move-assignment context = std::move(context); REQUIRE(context); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif co_await context; } From 738996112353d9e25668f4c02c8002997a12b8b3 Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Fri, 30 Dec 2022 21:03:43 +0800 Subject: [PATCH 10/12] tests: Suppress more unused function warnings --- test/old_tests/UnitTests/com_ref.cpp | 7 +++++++ test/test/inspectable_interop.cpp | 7 +++++++ test/test_win7/inspectable_interop.cpp | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/test/old_tests/UnitTests/com_ref.cpp b/test/old_tests/UnitTests/com_ref.cpp index 73c30e331..0d3e69120 100644 --- a/test/old_tests/UnitTests/com_ref.cpp +++ b/test/old_tests/UnitTests/com_ref.cpp @@ -13,7 +13,14 @@ namespace } #ifdef __CRT_UUID_DECL +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-function" +#endif __CRT_UUID_DECL(IClassic, 0x52bb7805, 0xe46e, 0x46f9, 0x85, 0x08, 0x86, 0x60, 0x6d, 0x2f, 0x6b, 0xc1); +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif #endif TEST_CASE("com_ref agile_ref") diff --git a/test/test/inspectable_interop.cpp b/test/test/inspectable_interop.cpp index bfe46d041..6772a7069 100644 --- a/test/test/inspectable_interop.cpp +++ b/test/test/inspectable_interop.cpp @@ -14,7 +14,14 @@ namespace } #ifdef __CRT_UUID_DECL +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-function" +#endif __CRT_UUID_DECL(IBadInterop, 0xed0dd761, 0xc31e, 0x4803, 0x8c, 0xf9, 0x22, 0xa2, 0xcb, 0x20, 0xec, 0x47) +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif #endif namespace diff --git a/test/test_win7/inspectable_interop.cpp b/test/test_win7/inspectable_interop.cpp index 95ee35522..5b0e957a5 100644 --- a/test/test_win7/inspectable_interop.cpp +++ b/test/test_win7/inspectable_interop.cpp @@ -13,7 +13,14 @@ namespace } #ifdef __CRT_UUID_DECL +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-function" +#endif __CRT_UUID_DECL(IBadInterop, 0xed0dd761, 0xc31e, 0x4803, 0x8c, 0xf9, 0x22, 0xa2, 0xcb, 0x20, 0xec, 0x47) +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif #endif namespace From 39c332cfdf25a1d86c4e2dbccf82b76c0ea760b4 Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Fri, 30 Dec 2022 21:04:42 +0800 Subject: [PATCH 11/12] tests: Fix `-Wreorder` (ctor initialization) --- test/test/multi_threaded_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test/multi_threaded_common.h b/test/test/multi_threaded_common.h index 2170233fd..026cb3264 100644 --- a/test/test/multi_threaded_common.h +++ b/test/test/multi_threaded_common.h @@ -152,7 +152,7 @@ namespace concurrent_collections concurrency_checked_random_access_iterator(container const* c, iterator it) : iterator(it), owner(c) {} // Implicit conversion from non-const iterator to const iterator. - concurrency_checked_random_access_iterator(concurrency_checked_random_access_iterator other) : owner(other.owner), iterator(other.inner()) { } + concurrency_checked_random_access_iterator(concurrency_checked_random_access_iterator other) : iterator(other.inner()), owner(other.owner) { } concurrency_checked_random_access_iterator(concurrency_checked_random_access_iterator const&) = default; concurrency_checked_random_access_iterator& operator=(concurrency_checked_random_access_iterator const&) = default; From f9bf404b632c407ad9056bd24f6b028eef44c60c Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Fri, 30 Dec 2022 21:05:36 +0800 Subject: [PATCH 12/12] tests: Suppress `-Woverloaded-virtual` --- test/test/inspectable_interop.cpp | 11 +++++++++-- test/test/tearoff.cpp | 2 +- test/test_win7/inspectable_interop.cpp | 11 +++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/test/test/inspectable_interop.cpp b/test/test/inspectable_interop.cpp index 6772a7069..e9094ca77 100644 --- a/test/test/inspectable_interop.cpp +++ b/test/test/inspectable_interop.cpp @@ -33,15 +33,22 @@ namespace throw hresult_not_implemented(); } - hstring GetRuntimeClassName() + hstring GetRuntimeClassName() const { return L"Sample"; } - Windows::Foundation::TrustLevel GetTrustLevel() +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Woverloaded-virtual" +#endif + Windows::Foundation::TrustLevel GetTrustLevel() const noexcept { return Windows::Foundation::TrustLevel::PartialTrust; } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif int32_t __stdcall JustSayNo() noexcept final { diff --git a/test/test/tearoff.cpp b/test/test/tearoff.cpp index 9ed622870..ac43140dd 100644 --- a/test/test/tearoff.cpp +++ b/test/test/tearoff.cpp @@ -181,7 +181,7 @@ namespace Closed = true; } - winrt::hstring GetRuntimeClassName() + winrt::hstring GetRuntimeClassName() const { return L"RuntimeClassName"; } diff --git a/test/test_win7/inspectable_interop.cpp b/test/test_win7/inspectable_interop.cpp index 5b0e957a5..0be7a9157 100644 --- a/test/test_win7/inspectable_interop.cpp +++ b/test/test_win7/inspectable_interop.cpp @@ -32,15 +32,22 @@ namespace throw hresult_not_implemented(); } - hstring GetRuntimeClassName() + hstring GetRuntimeClassName() const { return L"Sample"; } - Windows::Foundation::TrustLevel GetTrustLevel() +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Woverloaded-virtual" +#endif + Windows::Foundation::TrustLevel GetTrustLevel() const noexcept { return Windows::Foundation::TrustLevel::PartialTrust; } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif int32_t __stdcall JustSayNo() noexcept final {