mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 01:08:18 +08:00
[Analyzers][CPP] Turn on rule 26497 (#23119)
* Turn on warning 26497 This function function-name could be marked constexpr if compile-time evaluation is desired. * C++20 has constexpr swap * as constexpr is not only for compile time, make all functions that can be constexpr constexpr * constexpr functions are implicity inline
This commit is contained in:
parent
53f0b00328
commit
956eb98125
@ -84,7 +84,7 @@
|
||||
<Rule Id="C26494" Action="Hidden" />
|
||||
<Rule Id="C26495" Action="Error" />
|
||||
<Rule Id="C26496" Action="Hidden" />
|
||||
<Rule Id="C26497" Action="Hidden" />
|
||||
<Rule Id="C26497" Action="Error" />
|
||||
<Rule Id="C26498" Action="Error" />
|
||||
<Rule Id="C26800" Action="Hidden" />
|
||||
<Rule Id="C26810" Action="Error" />
|
||||
|
@ -206,7 +206,7 @@ void notifications::show_toast(std::wstring message, std::wstring title, toast_p
|
||||
show_toast_with_activations(std::move(message), std::move(title), {}, {}, std::move(params));
|
||||
}
|
||||
|
||||
inline void xml_escape(std::wstring data)
|
||||
constexpr inline void xml_escape(std::wstring data)
|
||||
{
|
||||
std::wstring buffer;
|
||||
buffer.reserve(data.size());
|
||||
|
@ -4,8 +4,9 @@
|
||||
#include <Windows.h>
|
||||
|
||||
// disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast
|
||||
// Disable 26497 for winrt - This function function-name could be marked constexpr if compile-time evaluation is desired.
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 26471)
|
||||
#pragma warning(disable : 26471 26497)
|
||||
#include <wil/resource.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
|
@ -115,12 +115,12 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isWin(int key)
|
||||
constexpr bool isWin(int key)
|
||||
{
|
||||
return key == VK_LWIN || key == VK_RWIN;
|
||||
}
|
||||
|
||||
bool isKeyDown(LowlevelKeyboardEvent event)
|
||||
constexpr bool isKeyDown(LowlevelKeyboardEvent event)
|
||||
{
|
||||
return event.wParam == WM_KEYDOWN || event.wParam == WM_SYSKEYDOWN;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ namespace MonitorUtils
|
||||
return { .id = str.substr(0, dividerPos), .instanceId = str.substr(dividerPos + 1) };
|
||||
}
|
||||
|
||||
inline bool not_digit(wchar_t ch)
|
||||
constexpr inline bool not_digit(wchar_t ch)
|
||||
{
|
||||
return '0' <= ch && ch <= '9';
|
||||
}
|
||||
|
@ -248,32 +248,6 @@ namespace FancyZonesUtils
|
||||
return closestIdx;
|
||||
}
|
||||
|
||||
RECT PrepareRectForCycling(RECT windowRect, RECT workAreaRect, DWORD vkCode) noexcept
|
||||
{
|
||||
LONG deltaX = 0, deltaY = 0;
|
||||
switch (vkCode)
|
||||
{
|
||||
case VK_UP:
|
||||
deltaY = workAreaRect.bottom - workAreaRect.top;
|
||||
break;
|
||||
case VK_DOWN:
|
||||
deltaY = workAreaRect.top - workAreaRect.bottom;
|
||||
break;
|
||||
case VK_LEFT:
|
||||
deltaX = workAreaRect.right - workAreaRect.left;
|
||||
break;
|
||||
case VK_RIGHT:
|
||||
deltaX = workAreaRect.left - workAreaRect.right;
|
||||
}
|
||||
|
||||
windowRect.left += deltaX;
|
||||
windowRect.right += deltaX;
|
||||
windowRect.top += deltaY;
|
||||
windowRect.bottom += deltaY;
|
||||
|
||||
return windowRect;
|
||||
}
|
||||
|
||||
void SwallowKey(const WORD key) noexcept
|
||||
{
|
||||
INPUT inputKey[1] = {};
|
||||
|
@ -93,7 +93,7 @@ namespace FancyZonesUtils
|
||||
}
|
||||
}
|
||||
|
||||
inline BYTE OpacitySettingToAlpha(int opacity)
|
||||
constexpr inline BYTE OpacitySettingToAlpha(int opacity)
|
||||
{
|
||||
return static_cast<BYTE>(opacity * 2.55);
|
||||
}
|
||||
@ -168,6 +168,32 @@ namespace FancyZonesUtils
|
||||
return result;
|
||||
}
|
||||
|
||||
constexpr RECT PrepareRectForCycling(RECT windowRect, RECT workAreaRect, DWORD vkCode) noexcept
|
||||
{
|
||||
LONG deltaX = 0, deltaY = 0;
|
||||
switch (vkCode)
|
||||
{
|
||||
case VK_UP:
|
||||
deltaY = workAreaRect.bottom - workAreaRect.top;
|
||||
break;
|
||||
case VK_DOWN:
|
||||
deltaY = workAreaRect.top - workAreaRect.bottom;
|
||||
break;
|
||||
case VK_LEFT:
|
||||
deltaX = workAreaRect.right - workAreaRect.left;
|
||||
break;
|
||||
case VK_RIGHT:
|
||||
deltaX = workAreaRect.left - workAreaRect.right;
|
||||
}
|
||||
|
||||
windowRect.left += deltaX;
|
||||
windowRect.right += deltaX;
|
||||
windowRect.top += deltaY;
|
||||
windowRect.bottom += deltaY;
|
||||
|
||||
return windowRect;
|
||||
}
|
||||
|
||||
UINT GetDpiForMonitor(HMONITOR monitor) noexcept;
|
||||
void OrderMonitors(std::vector<std::pair<HMONITOR, RECT>>& monitorInfo);
|
||||
|
||||
@ -175,7 +201,6 @@ namespace FancyZonesUtils
|
||||
std::optional<GUID> GuidFromString(const std::wstring& str) noexcept;
|
||||
std::optional<std::wstring> GuidToString(const GUID& guid) noexcept;
|
||||
|
||||
RECT PrepareRectForCycling(RECT windowRect, RECT workAreaRect, DWORD vkCode) noexcept;
|
||||
size_t ChooseNextZoneByPosition(DWORD vkCode, RECT windowRect, const std::vector<RECT>& zoneRects) noexcept;
|
||||
|
||||
void SwallowKey(const WORD key) noexcept;
|
||||
|
@ -421,8 +421,12 @@ void KeyDropDownControl::AddShortcutToControl(Shortcut shortcut, StackPanel tabl
|
||||
}
|
||||
}
|
||||
|
||||
// Disable 26497 this function should be evaluated at compile time
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 26497)
|
||||
// Get number of selected keys. Do not count -1 and 0 values as they stand for Not selected and None
|
||||
int KeyDropDownControl::GetNumberOfSelectedKeys(std::vector<int32_t> keyCodes)
|
||||
{
|
||||
return (int)std::count_if(keyCodes.begin(), keyCodes.end(), [](int32_t a) { return a != -1 && a != 0; });
|
||||
}
|
||||
}
|
||||
#pragma warning(pop)
|
@ -165,7 +165,7 @@ int XamlBridge::MessageLoop()
|
||||
|
||||
static const WPARAM invalidKey = (WPARAM)-1;
|
||||
|
||||
WPARAM GetKeyFromReason(winrt::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason reason)
|
||||
constexpr WPARAM GetKeyFromReason(winrt::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason reason)
|
||||
{
|
||||
auto key = invalidKey;
|
||||
if (reason == winrt::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::Last || reason == winrt::Windows::UI::Xaml::Hosting::XamlSourceFocusNavigationReason::First)
|
||||
|
@ -592,13 +592,13 @@ bool Shortcut::CheckModifiersKeyboardState(KeyboardManagerInput::InputInterface&
|
||||
}
|
||||
|
||||
// Helper method for checking if a key is in a range for cleaner code
|
||||
bool in_range(DWORD key, DWORD a, DWORD b)
|
||||
constexpr bool in_range(DWORD key, DWORD a, DWORD b)
|
||||
{
|
||||
return (key >= a && key <= b);
|
||||
}
|
||||
|
||||
// Helper method for checking if a key is equal to a value for cleaner code
|
||||
bool equals(DWORD key, DWORD a)
|
||||
constexpr bool equals(DWORD key, DWORD a)
|
||||
{
|
||||
return (key == a);
|
||||
}
|
||||
|
@ -41,12 +41,12 @@ std::string toMediaTypeString(GUID subtype);
|
||||
#define LOG(str) LogToFile(str, false);
|
||||
#endif
|
||||
|
||||
inline bool failed(HRESULT hr)
|
||||
constexpr inline bool failed(HRESULT hr)
|
||||
{
|
||||
return hr != S_OK;
|
||||
}
|
||||
|
||||
inline bool failed(bool val)
|
||||
constexpr inline bool failed(bool val)
|
||||
{
|
||||
return val == false;
|
||||
}
|
||||
|
@ -6,8 +6,9 @@
|
||||
#include <dshow.h>
|
||||
|
||||
// disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast
|
||||
// Disable 26497 for winrt - This function function-name could be marked constexpr if compile-time evaluation is desired.
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 26471)
|
||||
#pragma warning(disable : 26471 26497)
|
||||
#include <wil/com.h>
|
||||
#pragma warning(push)
|
||||
|
||||
|
@ -6,8 +6,9 @@
|
||||
#include <cguid.h>
|
||||
|
||||
// disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast
|
||||
// Disable 26497 for winrt - This function function-name could be marked constexpr if compile-time evaluation is desired.
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 26471)
|
||||
#pragma warning(disable : 26471 26497)
|
||||
#include <wil/com.h>
|
||||
#pragma warning(push)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user