Skip to content

Commit 46fd3ed

Browse files
authored
All cppwinrt vcxproj should build with /W4 and /WX (warnings turned up, treated as error). Fix existing violations. (#1487)
Why is this change being made? The most recent PR introduced a warning for non-Clang consumers. Many projects build with warnings-as-errors so this is a build break for those projects. Because cppwinrt is widely used by many such projects it should itself build with warnings as errors enabled so that this doesn't happen again in the future. Plus it is general goodness to build with warnings cranked up and blocking. Briefly summarize what changed I added /WX to every single vcxproj in this repo (which required a whole lot of redundant edits). Many of them didn't have /W4 so I added it wherever it was missing. The project files definitely need some refactoring to reduce duplication. But for this change I decided to modify them as-is without also including a refactoring. I also fixed the newly-blocking warnings. MSVC only had the one new warning to fix. Clang had a whole bunch of previously-unknown warnings that needed to be fixed or suppressed to get the build passing again. I also removed a typo'd (warning is singular, not plural) that was trying to disable warnings in one specific project. It has no warnings so we might as well baseline them as blocking. I also added a new clang-only test file to try and exercise the LTO public visibility annotation. How was this change tested? It builds locally (x64 Debug+Release, MSVC + Clang).
1 parent 723f64b commit 46fd3ed

File tree

73 files changed

+458
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+458
-33
lines changed

Directory.Build.Props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<ItemDefinitionGroup>
5050
<ClCompile>
5151
<WarningLevel>Level4</WarningLevel>
52+
<TreatWarningAsError>true</TreatWarningAsError>
5253
<SDLCheck>true</SDLCheck>
5354
<ConformanceMode>true</ConformanceMode>
5455
<LanguageStandard Condition="'$(CppWinRTLanguageStandard)'==''">stdcpp17</LanguageStandard>

cppwinrt/component_writers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ catch (...) { return winrt::to_hresult(); }
754754
using implements_type = typename %_base::implements_type;
755755
using implements_type::implements_type;
756756
%%
757-
hstring GetRuntimeClassName() const
757+
hstring GetRuntimeClassName() const override
758758
{
759759
return L"%.%";
760760
}

cppwinrt/cppwinrt.vcxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@
176176
<Optimization>Disabled</Optimization>
177177
<AdditionalIncludeDirectories>..\inc;$(OutputPath);$(WinMDPackageDir);</AdditionalIncludeDirectories>
178178
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
179+
<WarningLevel>Level4</WarningLevel>
180+
<TreatWarningAsError>true</TreatWarningAsError>
179181
</ClCompile>
180182
<Link>
181183
<SubSystem>Console</SubSystem>
@@ -193,6 +195,8 @@
193195
<Optimization>Disabled</Optimization>
194196
<AdditionalIncludeDirectories>..\inc;$(OutputPath);$(WinMDPackageDir);</AdditionalIncludeDirectories>
195197
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
198+
<WarningLevel>Level4</WarningLevel>
199+
<TreatWarningAsError>true</TreatWarningAsError>
196200
</ClCompile>
197201
<Link>
198202
<SubSystem>Console</SubSystem>
@@ -210,6 +214,8 @@
210214
<Optimization>Disabled</Optimization>
211215
<AdditionalIncludeDirectories>..\inc;$(OutputPath);$(WinMDPackageDir);</AdditionalIncludeDirectories>
212216
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
217+
<WarningLevel>Level4</WarningLevel>
218+
<TreatWarningAsError>true</TreatWarningAsError>
213219
</ClCompile>
214220
<Link>
215221
<SubSystem>Console</SubSystem>
@@ -230,6 +236,8 @@
230236
<AdditionalIncludeDirectories>..\inc;$(OutputPath);$(WinMDPackageDir);</AdditionalIncludeDirectories>
231237
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
232238
<ControlFlowGuard>Guard</ControlFlowGuard>
239+
<WarningLevel>Level4</WarningLevel>
240+
<TreatWarningAsError>true</TreatWarningAsError>
233241
</ClCompile>
234242
<Link>
235243
<SubSystem>Console</SubSystem>
@@ -253,6 +261,8 @@
253261
<AdditionalIncludeDirectories>..\inc;$(OutputPath);$(WinMDPackageDir);</AdditionalIncludeDirectories>
254262
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
255263
<ControlFlowGuard>Guard</ControlFlowGuard>
264+
<WarningLevel>Level4</WarningLevel>
265+
<TreatWarningAsError>true</TreatWarningAsError>
256266
</ClCompile>
257267
<Link>
258268
<SubSystem>Console</SubSystem>
@@ -276,6 +286,8 @@
276286
<AdditionalIncludeDirectories>..\inc;$(OutputPath);$(WinMDPackageDir);</AdditionalIncludeDirectories>
277287
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
278288
<ControlFlowGuard>Guard</ControlFlowGuard>
289+
<WarningLevel>Level4</WarningLevel>
290+
<TreatWarningAsError>true</TreatWarningAsError>
279291
</ClCompile>
280292
<Link>
281293
<SubSystem>Console</SubSystem>

natvis/cppwinrtvisualizer.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<ClCompile>
104104
<PrecompiledHeader>Use</PrecompiledHeader>
105105
<WarningLevel>Level4</WarningLevel>
106+
<TreatWarningAsError>true</TreatWarningAsError>
106107
<Optimization>Disabled</Optimization>
107108
<PreprocessorDefinitions>VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;WIN32;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108109
<AdditionalIncludeDirectories>$(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -127,6 +128,7 @@
127128
<ClCompile>
128129
<PrecompiledHeader>Use</PrecompiledHeader>
129130
<WarningLevel>Level4</WarningLevel>
131+
<TreatWarningAsError>true</TreatWarningAsError>
130132
<Optimization>Disabled</Optimization>
131133
<PreprocessorDefinitions>VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
132134
<AdditionalIncludeDirectories>$(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -150,6 +152,7 @@
150152
<ClCompile>
151153
<PrecompiledHeader>Use</PrecompiledHeader>
152154
<WarningLevel>Level4</WarningLevel>
155+
<TreatWarningAsError>true</TreatWarningAsError>
153156
<Optimization>Disabled</Optimization>
154157
<PreprocessorDefinitions>VSDEBUGENG_USE_CPP11_SCOPED_ENUMS;_DEBUG;VISUALIZER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
155158
<AdditionalIncludeDirectories>$(IntDir);..\cppwinrt;..\strings;$(DIASDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -173,6 +176,7 @@
173176
<ClCompile>
174177
<PrecompiledHeader>Use</PrecompiledHeader>
175178
<WarningLevel>Level4</WarningLevel>
179+
<TreatWarningAsError>true</TreatWarningAsError>
176180
<Optimization>MaxSpeed</Optimization>
177181
<FunctionLevelLinking>true</FunctionLevelLinking>
178182
<IntrinsicFunctions>true</IntrinsicFunctions>
@@ -202,6 +206,7 @@
202206
<ClCompile>
203207
<PrecompiledHeader>Use</PrecompiledHeader>
204208
<WarningLevel>Level4</WarningLevel>
209+
<TreatWarningAsError>true</TreatWarningAsError>
205210
<Optimization>MaxSpeed</Optimization>
206211
<FunctionLevelLinking>true</FunctionLevelLinking>
207212
<IntrinsicFunctions>true</IntrinsicFunctions>
@@ -231,6 +236,7 @@
231236
<ClCompile>
232237
<PrecompiledHeader>Use</PrecompiledHeader>
233238
<WarningLevel>Level4</WarningLevel>
239+
<TreatWarningAsError>true</TreatWarningAsError>
234240
<Optimization>MaxSpeed</Optimization>
235241
<FunctionLevelLinking>true</FunctionLevelLinking>
236242
<IntrinsicFunctions>true</IntrinsicFunctions>

prebuild/prebuild.vcxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
<Optimization>Disabled</Optimization>
8989
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
9090
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
91+
<WarningLevel>Level4</WarningLevel>
92+
<TreatWarningAsError>true</TreatWarningAsError>
9193
</ClCompile>
9294
<Link>
9395
<SubSystem>Console</SubSystem>
@@ -98,6 +100,8 @@
98100
<Optimization>Disabled</Optimization>
99101
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
100102
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
103+
<WarningLevel>Level4</WarningLevel>
104+
<TreatWarningAsError>true</TreatWarningAsError>
101105
</ClCompile>
102106
<Link>
103107
<SubSystem>Console</SubSystem>
@@ -108,6 +112,8 @@
108112
<Optimization>Disabled</Optimization>
109113
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
110114
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
115+
<WarningLevel>Level4</WarningLevel>
116+
<TreatWarningAsError>true</TreatWarningAsError>
111117
</ClCompile>
112118
<Link>
113119
<SubSystem>Console</SubSystem>
@@ -121,6 +127,8 @@
121127
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
122128
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
123129
<ControlFlowGuard>Guard</ControlFlowGuard>
130+
<WarningLevel>Level4</WarningLevel>
131+
<TreatWarningAsError>true</TreatWarningAsError>
124132
</ClCompile>
125133
<Link>
126134
<SubSystem>Console</SubSystem>
@@ -136,6 +144,8 @@
136144
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
137145
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
138146
<ControlFlowGuard>Guard</ControlFlowGuard>
147+
<WarningLevel>Level4</WarningLevel>
148+
<TreatWarningAsError>true</TreatWarningAsError>
139149
</ClCompile>
140150
<Link>
141151
<SubSystem>Console</SubSystem>
@@ -151,6 +161,8 @@
151161
<AdditionalIncludeDirectories>..\cppwinrt</AdditionalIncludeDirectories>
152162
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
153163
<ControlFlowGuard>Guard</ControlFlowGuard>
164+
<WarningLevel>Level4</WarningLevel>
165+
<TreatWarningAsError>true</TreatWarningAsError>
154166
</ClCompile>
155167
<Link>
156168
<SubSystem>Console</SubSystem>

scratch/scratch.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
<ItemDefinitionGroup>
5454
<ClCompile>
5555
<AdditionalIncludeDirectories>$(OutputPath);Generated Files;</AdditionalIncludeDirectories>
56+
<WarningLevel>Level4</WarningLevel>
57+
<TreatWarningAsError>true</TreatWarningAsError>
5658
</ClCompile>
5759
<Link>
5860
<SubSystem>Console</SubSystem>

strings/base_activation.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ namespace winrt::impl
257257
}
258258

259259
private:
260-
261-
size_t& m_count;
260+
[[maybe_unused]] size_t& m_count; // Field is unused when WINRT_NO_MODULE_LOCK is defined.
262261
};
263262

264263
struct factory_cache_entry_base

strings/base_fast_forward.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
#define WINRT_IMPL_FF_NOVTABLE
1111
#endif
1212

13-
#if defined(__clang__) && __has_attribute(__lto_visibility_public__)
13+
#if defined(__clang__) && defined(__has_attribute)
14+
#if __has_attribute(__lto_visibility_public__)
1415
#define WINRT_IMPL_FF_PUBLIC __attribute__((lto_visibility_public))
1516
#else
1617
#define WINRT_IMPL_FF_PUBLIC
18+
#endif // __has_attribute(__lto_visibility_public__)
19+
#else
20+
#define WINRT_IMPL_FF_PUBLIC
1721
#endif
1822

1923
#if !defined(WINRT_FAST_ABI_SIZE)
@@ -59,7 +63,7 @@ namespace winrt::impl
5963
std::atomic<uint32_t> m_references{ 1 };
6064

6165
fast_abi_forwarder(void* owner, guid const& iid, std::size_t offset) noexcept :
62-
m_vfptr(s_vtable), m_owner(static_cast<inspectable*>(owner)), m_iid(iid), m_offset(offset)
66+
m_vfptr(s_vtable), m_owner(static_cast<inspectable*>(owner)), m_offset(offset), m_iid(iid)
6367
{
6468
m_owner->AddRef();
6569
}
@@ -112,6 +116,11 @@ namespace winrt::impl
112116
return self->m_owner->GetTrustLevel(level);
113117
}
114118

119+
120+
#ifdef __clang__
121+
#pragma clang diagnostic push
122+
#pragma clang diagnostic ignored "-Wmicrosoft-cast"
123+
#endif
115124
static inline void* const s_vtable[] =
116125
{
117126
QueryInterface,
@@ -121,6 +130,9 @@ namespace winrt::impl
121130
GetRuntimeClassName,
122131
GetTrustLevel,
123132
% };
133+
#ifdef __clang__
134+
#pragma clang diagnostic pop
135+
#endif
124136
};
125137

126138
// Enforce assumptions made by thunk asm code

strings/base_macros.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@
6161
#define WINRT_IMPL_NOVTABLE
6262
#endif
6363

64-
#if defined(__clang__) && __has_attribute(__lto_visibility_public__)
64+
#if defined(__clang__) && defined(__has_attribute)
65+
#if __has_attribute(__lto_visibility_public__)
6566
#define WINRT_IMPL_PUBLIC __attribute__((lto_visibility_public))
6667
#else
6768
#define WINRT_IMPL_PUBLIC
69+
#endif // __has_attribute(__lto_visibility_public__)
70+
#else
71+
#define WINRT_IMPL_PUBLIC
6872
#endif
6973

7074
#define WINRT_IMPL_ABI_DECL WINRT_IMPL_NOVTABLE WINRT_IMPL_PUBLIC

strings/base_string.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ namespace winrt::impl
574574
// when non-const (e.g. ranges::filter_view) so taking a const reference
575575
// as parameter wouldn't work for all scenarios.
576576
auto const size = std::formatted_size(args...);
577-
WINRT_ASSERT(size < UINT_MAX);
578-
auto const size32 = static_cast<uint32_t>(size);
577+
WINRT_ASSERT(size < INT_MAX);
578+
auto const size32 = static_cast<int32_t>(size);
579579

580580
hstring_builder builder(size32);
581581
WINRT_VERIFY_(size32, std::format_to_n(builder.data(), size32, args...).size);

0 commit comments

Comments
 (0)