Skip to content

Commit 081a0f4

Browse files
qiutongMSQiutong Shen
andauthored
fix: resolve C4100 unreferenced parameter warnings across samples (#513)
* fix: resolve C4100 unreferenced parameter warnings across samples * set C4100 treateAsError * move 8305 suppress to global * extra C4100 process * add extra test * ext --------- Co-authored-by: Qiutong Shen <[email protected]>
1 parent 7682638 commit 081a0f4

File tree

21 files changed

+94
-87
lines changed

21 files changed

+94
-87
lines changed

Samples/AppLifecycle/RestartRegistration/cpp-winui-packaged/S2_CrashRecovery.xaml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace winrt::cpp_winui_packaged::implementation
8383
*((int*)nullptr) = 0;
8484
}
8585

86-
void S2_CrashRecovery::OnNavigatedFrom(winrt::Microsoft::UI::Xaml::Navigation::NavigationEventArgs e)
86+
void S2_CrashRecovery::OnNavigatedFrom(winrt::Microsoft::UI::Xaml::Navigation::NavigationEventArgs /*e*/)
8787
{
8888
_timer.Stop();
8989
}

Samples/AppLifecycle/StateNotifications/cpp/cpp-winui-packaged/CppWinUiDesktopState/CppWinUiDesktopState/MainWindow.xaml.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@ void winrt::CppWinUiDesktopState::implementation::MainWindow::OutputFormattedMes
6161
void winrt::CppWinUiDesktopState::implementation::MainWindow::RegisterPowerManagerCallbacks()
6262
{
6363
batteryToken = PowerManager::BatteryStatusChanged([&](
64-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnBatteryStatusChanged(); });
64+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnBatteryStatusChanged(); });
6565
powerToken = PowerManager::PowerSupplyStatusChanged([&](
66-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnPowerSupplyStatusChanged(); });
66+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnPowerSupplyStatusChanged(); });
6767
powerSourceToken = PowerManager::PowerSourceKindChanged([&](
68-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnPowerSourceKindChanged(); });
68+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnPowerSourceKindChanged(); });
6969
chargeToken = PowerManager::RemainingChargePercentChanged([&](
70-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnRemainingChargePercentChanged(); });
70+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnRemainingChargePercentChanged(); });
7171
dischargeToken = PowerManager::RemainingDischargeTimeChanged([&](
72-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnRemainingDischargeTimeChanged(); });
72+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnRemainingDischargeTimeChanged(); });
7373
displayToken = PowerManager::DisplayStatusChanged([&](
74-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnDisplayStatusChanged(); });
74+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnDisplayStatusChanged(); });
7575
energyToken = PowerManager::EnergySaverStatusChanged([&](
76-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnEnergySaverStatusChanged(); });
76+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnEnergySaverStatusChanged(); });
7777
powerModeToken = PowerManager::EffectivePowerModeChanged([&](
78-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnPowerModeChanged(); });
78+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnPowerModeChanged(); });
7979
userPresenceToken = PowerManager::UserPresenceStatusChanged([&](
80-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnUserPresenceStatusChanged(); });
80+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnUserPresenceStatusChanged(); });
8181
systemSuspendToken = PowerManager::SystemSuspendStatusChanged([&](
82-
const auto&, winrt::Windows::Foundation::IInspectable obj) { OnSystemSuspendStatusChanged(); });
82+
const auto&, winrt::Windows::Foundation::IInspectable /*obj*/) { OnSystemSuspendStatusChanged(); });
8383

8484
if (batteryToken && powerToken && powerSourceToken && chargeToken && dischargeToken)
8585
{

Samples/Directory.Build.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<!-- Suppress CS8305: Feature is for evaluation purposes only and is subject to change or removal in future updates. -->
5+
<NoWarn>$(NoWarn);8305</NoWarn>
6+
</PropertyGroup>
37
<ItemDefinitionGroup>
48
<ClCompile>
59
<AdditionalOptions>%(AdditionalOptions) /Qspectre</AdditionalOptions>
@@ -8,6 +12,8 @@
812
<!-- Setting this to be compatible with CFG -->
913
<DebugInformationFormat>OldStyle</DebugInformationFormat>
1014
<SDLCheck>true</SDLCheck>
15+
<!-- Treat C4100 (unreferenced parameter) as error -->
16+
<TreatSpecificWarningsAsErrors>4100;%(TreatSpecificWarningsAsErrors)</TreatSpecificWarningsAsErrors>
1117
</ClCompile>
1218
<Link>
1319
<!-- dynamicbase is required for enabling CFG -->

Samples/Notifications/Push/cpp-console-packaged/cpp-console.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ winrt::Windows::Foundation::IAsyncOperation<PushNotificationChannel> RequestChan
2525

2626
// Setup the in-progress event handler
2727
channelOperation.Progress(
28-
[](auto&& sender, auto&& args)
28+
[](auto&& /*sender*/, auto&& args)
2929
{
3030
if (args.status == PushNotificationChannelStatus::InProgress)
3131
{

Samples/Notifications/Push/cpp-console-unpackaged/cpp-console-unpackaged.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ winrt::Windows::Foundation::IAsyncOperation<PushNotificationChannel> RequestChan
2525

2626
// Setup the in-progress event handler
2727
channelOperation.Progress(
28-
[](auto&& sender, auto&& args)
28+
[](auto&& /*sender*/, auto&& args)
2929
{
3030
if (args.status == PushNotificationChannelStatus::InProgress)
3131
{

Samples/PhotoEditor/cpp-winui/PhotoEditor/MainPage.xaml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ namespace winrt::PhotoEditor::implementation
214214
}
215215

216216
// Photo clicked event handler for navigation to DetailPage view.
217-
void MainPage::ImageGridView_ItemClick(IInspectable const sender, ItemClickEventArgs const e)
217+
void MainPage::ImageGridView_ItemClick(IInspectable const /*sender*/, ItemClickEventArgs const e)
218218
{
219219
// Prepare the connected animation for navigation to the detail page.
220220
m_persistedItem = e.ClickedItem().as<PhotoEditor::Photo>();

Samples/TextRendering/cpp-win32/DWriteCoreGallery/ChildWindow.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ void ChildWindow::Move(int pixelLeft, int pixelTop, int pixelWidth, int pixelHei
6969
SetWindowPos(m_hwnd, nullptr, pixelLeft, pixelTop, pixelWidth, pixelHeight, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOACTIVATE);
7070
}
7171

72-
LRESULT ChildWindow::Handle_Create(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
72+
LRESULT ChildWindow::Handle_Create(HWND hwnd, UINT /*message*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
7373
{
7474
m_hwnd = hwnd;
7575
return 0;
7676
}
7777

78-
LRESULT ChildWindow::Handle_Paint(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
78+
LRESULT ChildWindow::Handle_Paint(HWND hwnd, UINT /*message*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
7979
{
8080
PAINTSTRUCT ps;
8181
auto hdc = wil::BeginPaint(hwnd, &ps);
@@ -95,7 +95,7 @@ LRESULT ChildWindow::Handle_KeyDown(HWND hwnd, UINT message, WPARAM wParam, LPAR
9595
}
9696
}
9797

98-
LRESULT ChildWindow::Handle_LButtonDown(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
98+
LRESULT ChildWindow::Handle_LButtonDown(HWND /*hwnd*/, UINT message, WPARAM wParam, LPARAM lParam)
9999
{
100100
// Send the message to the parent window if it's not handled by the current window.
101101
if (OnLeftButtonDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)))
@@ -108,32 +108,32 @@ LRESULT ChildWindow::Handle_LButtonDown(HWND hwnd, UINT message, WPARAM wParam,
108108
}
109109
}
110110

111-
LRESULT ChildWindow::Handle_LButtonUp(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
111+
LRESULT ChildWindow::Handle_LButtonUp(HWND /*hwnd*/, UINT /*message*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
112112
{
113113
OnLeftButtonUp();
114114
return 0;
115115
}
116116

117-
LRESULT ChildWindow::Handle_MouseMove(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
117+
LRESULT ChildWindow::Handle_MouseMove(HWND /*hwnd*/, UINT /*message*/, WPARAM /*wParam*/, LPARAM lParam)
118118
{
119119
OnMouseMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
120120
return 0;
121121
}
122122

123123

124-
LRESULT ChildWindow::Handle_VScroll(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
124+
LRESULT ChildWindow::Handle_VScroll(HWND /*hwnd*/, UINT /*message*/, WPARAM wParam, LPARAM /*lParam*/)
125125
{
126126
OnVSCroll(LOWORD(wParam));
127127
return 0;
128128
}
129129

130-
LRESULT ChildWindow::Handle_MouseWheel(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
130+
LRESULT ChildWindow::Handle_MouseWheel(HWND /*hwnd*/, UINT /*message*/, WPARAM wParam, LPARAM /*lParam*/)
131131
{
132132
OnMouseWheel(static_cast<int16_t>(HIWORD(wParam)));
133133
return 0;
134134
}
135135

136-
LRESULT ChildWindow::Handle_Size(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
136+
LRESULT ChildWindow::Handle_Size(HWND hwnd, UINT /*message*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
137137
{
138138
RECT clientRect;
139139
GetClientRect(hwnd, &clientRect);
@@ -144,7 +144,7 @@ LRESULT ChildWindow::Handle_Size(HWND hwnd, UINT message, WPARAM wParam, LPARAM
144144
return 0;
145145
}
146146

147-
LRESULT ChildWindow::Handle_Command(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
147+
LRESULT ChildWindow::Handle_Command(HWND /*hwnd*/, UINT /*message*/, WPARAM wParam, LPARAM lParam)
148148
{
149149
if (lParam != 0)
150150
{
@@ -157,13 +157,13 @@ LRESULT ChildWindow::Handle_Command(HWND hwnd, UINT message, WPARAM wParam, LPAR
157157
}
158158
}
159159

160-
LRESULT ChildWindow::Handle_SetFocus(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
160+
LRESULT ChildWindow::Handle_SetFocus(HWND /*hwnd*/, UINT /*message*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
161161
{
162162
OnFocus(true);
163163
return 0;
164164
}
165165

166-
LRESULT ChildWindow::Handle_KillFocus(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
166+
LRESULT ChildWindow::Handle_KillFocus(HWND /*hwnd*/, UINT /*message*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
167167
{
168168
OnFocus(false);
169169
return 0;

Samples/TextRendering/cpp-win32/DWriteCoreGallery/ChildWindow.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ class ChildWindow
3636
protected:
3737

3838
// Window message handlers.
39-
virtual void OnPaint(HDC hdc, RECT invalidRect) {}
40-
virtual bool OnKeyDown(uint32_t keyCode) { return false; }
41-
virtual bool OnLeftButtonDown(int x, int y) { return false; }
39+
// Remove parameter names to avoid C4100 (unreferenced formal parameter) warnings in base implementations.
40+
virtual void OnPaint(HDC /*hdc*/, RECT /*invalidRect*/) {}
41+
virtual bool OnKeyDown(uint32_t /*keyCode*/) { return false; }
42+
virtual bool OnLeftButtonDown(int /*x*/, int /*y*/) { return false; }
4243
virtual void OnLeftButtonUp() {}
43-
virtual void OnMouseMove(int x, int y) {}
44-
virtual void OnVSCroll(uint32_t requestId) {}
45-
virtual void OnMouseWheel(int distance) {}
44+
virtual void OnMouseMove(int /*x*/, int /*y*/) {}
45+
virtual void OnVSCroll(uint32_t /*requestId*/) {}
46+
virtual void OnMouseWheel(int /*distance*/) {}
4647
virtual void OnSize() {}
47-
virtual void OnFocus(bool haveFocus) {}
48-
virtual void OnMenuCommand(uint32_t id) {}
49-
virtual LRESULT OnControlCommand(HWND controlWindow, uint32_t controlId, uint32_t notificationCode) { return 0; }
48+
virtual void OnFocus(bool /*haveFocus*/) {}
49+
virtual void OnMenuCommand(uint32_t /*id*/) {}
50+
virtual LRESULT OnControlCommand(HWND /*controlWindow*/, uint32_t /*controlId*/, uint32_t /*notificationCode*/) { return 0; }
5051

5152
private:
5253
LRESULT Handle_Create(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

Samples/TextRendering/cpp-win32/DWriteCoreGallery/FontCollectionWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ FontFaceListWindow& FontCollectionWindow::GetFaceList()
3030
return static_cast<FontFaceListWindow&>(*GetRightPane());
3131
}
3232

33-
LRESULT FontCollectionWindow::OnControlCommand(HWND controlWindow, uint32_t controlId, uint32_t notificationCode)
33+
LRESULT FontCollectionWindow::OnControlCommand(HWND /*controlWindow*/, uint32_t /*controlId*/, uint32_t notificationCode)
3434
{
3535
switch (notificationCode)
3636
{

Samples/TextRendering/cpp-win32/DWriteCoreGallery/FontFaceListWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void FontFaceListWindow::SetFontFamily(
178178
ListWindow::SetItemCount(fontCount);
179179
}
180180

181-
void FontFaceListWindow::DrawItem(TextRenderer* textRenderer, int itemIndex, bool isSelected)
181+
void FontFaceListWindow::DrawItem(TextRenderer* textRenderer, int itemIndex, bool /*isSelected*/)
182182
{
183183
auto& item = m_fontItems[itemIndex];
184184

0 commit comments

Comments
 (0)