Skip to content

Fix various build warnings #1473

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

Merged
merged 6 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions cppwinrt/component_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ void* __stdcall %_get_activation_factory([[maybe_unused]] std::wstring_view cons
int32_t __stdcall WINRT_CanUnloadNow() noexcept
{
#ifdef _WRL_MODULE_H_
#ifdef _MSC_VER
#pragma warning(disable: 4324) // structure was padded due to alignment specifier
#endif
if (!::Microsoft::WRL::Module<::Microsoft::WRL::InProc>::GetModule().Terminate())
{
return 1;
Expand Down
6 changes: 6 additions & 0 deletions prebuild/prebuild.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -98,6 +99,7 @@
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -108,6 +110,7 @@
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -120,6 +123,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -134,6 +138,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -148,6 +153,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ControlFlowGuard>Guard</ControlFlowGuard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
7 changes: 7 additions & 0 deletions strings/base_composable.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ namespace winrt::impl
template <typename D>
struct composable_factory
{
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4702) // Compiler bug causing spurious "unreachable code" warnings
#endif
template <typename I, typename... Args>
static I CreateInstance(const Windows::Foundation::IInspectable& outer, Windows::Foundation::IInspectable& inner, Args&&... args)
{
static_assert(std::is_base_of_v<Windows::Foundation::IInspectable, I>, "Requested interface must derive from winrt::Windows::Foundation::IInspectable");
inner = CreateInstanceImpl(outer, std::forward<Args>(args)...);
return inner.as<I>();
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif

private:
template <typename... Args>
Expand Down
7 changes: 7 additions & 0 deletions strings/base_implements.h
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,10 @@ namespace winrt::impl

WINRT_EXPORT namespace winrt
{
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4702) // Compiler bug causing spurious "unreachable code" warnings
#endif
template <typename D, typename... Args>
auto make(Args&&... args)
{
Expand Down Expand Up @@ -1443,6 +1447,9 @@ WINRT_EXPORT namespace winrt
return { impl::create_and_initialize<D>(std::forward<Args>(args)...), take_ownership_from_abi };
}
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif

template <typename... FactoryClasses>
inline void clear_factory_static_lifetime()
Expand Down
4 changes: 4 additions & 0 deletions test/old_tests/Component/Component.idl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ namespace Component
HRESULT Create([in] Windows.Foundation.Collections.IVectorView<HSTRING>* _in, [out, retval] FastInputVector** _out);
};

midl_pragma warning(disable: 4066) // A member name has been qualified with an interface name because name collisions occurred across interface members on a runtime class.

[version(1.0), activatable(IFastInputVectorFactory, 1.0)]
runtimeclass FastInputVector
{
Expand Down Expand Up @@ -271,6 +273,8 @@ namespace Component
interface Windows.Foundation.Collections.IMapView<HSTRING, HSTRING>;
};

midl_pragma warning(default: 4066)

//
// Boxing support for enums and their underlying types.
//
Expand Down
2 changes: 1 addition & 1 deletion test/test/fast_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TEST_CASE("fast_iterator")
REQUIRE(2 - (vbegin + 4) > vbegin);
REQUIRE(vbegin < vbegin + 2);
REQUIRE(vbegin + 2 - 2 == vbegin);
REQUIRE(end(v) - begin(v) == v.Size());
REQUIRE(static_cast<uint32_t>(end(v) - begin(v)) == v.Size());
REQUIRE((begin(v) + 3)[-1] == 4);
}
{
Expand Down
6 changes: 3 additions & 3 deletions test/test_component/OverloadClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace winrt::test_component::implementation
{
throw hresult_not_implemented();
}
void OverloadClass::Overload(int a)
void OverloadClass::Overload(int /*a*/)
{
throw hresult_not_implemented();
}
void OverloadClass::Overload(int a, int b)
void OverloadClass::Overload(int /*a*/, int /*b*/)
{
throw hresult_not_implemented();
}
void OverloadClass::Overload(int a, int b, int c)
void OverloadClass::Overload(int /*a*/, int /*b*/, int /*c*/)
{
throw hresult_not_implemented();
}
Expand Down
2 changes: 2 additions & 0 deletions test/test_component_base/HierarchyB.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "pch.h"
#include "HierarchyB.h"

#pragma warning(disable: 4702)

namespace winrt::test_component_base::implementation
{
HierarchyB::HierarchyB(hstring const& name)
Expand Down
Loading