[Analyzers][CPP] Turn on warning 4458 (#22265)

* Turn on warning 4458

Fix the errors by changing variable names and
supressing the warning on winRT GDI headers

* explaining the warning disables
This commit is contained in:
sosssego 2022-11-29 14:10:48 +00:00 committed by GitHub
parent 21a9c82df4
commit 6a6c45189e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 75 additions and 52 deletions

View File

@ -42,7 +42,7 @@
<ClCompile> <ClCompile>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<DisableSpecificWarnings>26800;28251;6387;4458;4505;4702;6031;6248;26451;28182;%(DisableSpecificWarnings)</DisableSpecificWarnings> <DisableSpecificWarnings>26800;28251;6387;4505;4702;6031;6248;26451;28182;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<DisableAnalyzeExternal >true</DisableAnalyzeExternal> <DisableAnalyzeExternal >true</DisableAnalyzeExternal>
<ExternalWarningLevel>TurnOffAllWarnings</ExternalWarningLevel> <ExternalWarningLevel>TurnOffAllWarnings</ExternalWarningLevel>
<ConformanceMode>false</ConformanceMode> <ConformanceMode>false</ConformanceMode>

View File

@ -98,11 +98,11 @@ void Logger::init(std::string loggerName, std::wstring logFilePath, std::wstring
void Logger::init(std::vector<spdlog::sink_ptr> sinks) void Logger::init(std::vector<spdlog::sink_ptr> sinks)
{ {
auto logger = std::make_shared<spdlog::logger>("", begin(sinks), end(sinks)); auto init_logger = std::make_shared<spdlog::logger>("", begin(sinks), end(sinks));
if (!logger) if (!init_logger)
{ {
return; return;
} }
Logger::logger = logger; Logger::logger = init_logger;
} }

View File

@ -8,16 +8,16 @@ void Animation::reset()
{ {
start = std::chrono::high_resolution_clock::now(); start = std::chrono::high_resolution_clock::now();
} }
void Animation::reset(double duration) void Animation::reset(double animation_duration)
{ {
this->duration = duration; duration = animation_duration;
reset(); reset();
} }
void Animation::reset(double duration, double start, double stop) void Animation::reset(double animation_duration, double animation_start, double animation_stop)
{ {
start_value = start; start_value = animation_start;
end_value = stop; end_value = animation_stop;
reset(duration); reset(animation_duration);
} }
static double ease_out_expo(double t) static double ease_out_expo(double t)

View File

@ -22,8 +22,8 @@ public:
Animation(double duration = 1, double start = 0, double stop = 1); Animation(double duration = 1, double start = 0, double stop = 1);
void reset(); void reset();
void reset(double duration); void reset(double animation_duration);
void reset(double duration, double start, double stop); void reset(double animation_duration, double animation_start, double animation_stop);
double value(AnimFunctions apply_function) const; double value(AnimFunctions apply_function) const;
bool done() const; bool done() const;

View File

@ -297,13 +297,13 @@ D2DOverlayWindow::D2DOverlayWindow() :
}); });
} }
void D2DOverlayWindow::show(HWND active_window, bool snappable) void D2DOverlayWindow::show(HWND window, bool snappable)
{ {
std::unique_lock lock(mutex); std::unique_lock lock(mutex);
hidden = false; hidden = false;
tasklist_buttons.clear(); tasklist_buttons.clear();
this->active_window = active_window; active_window = window;
this->active_window_snappable = snappable; active_window_snappable = snappable;
auto old_bck = colors.start_color_menu; auto old_bck = colors.start_color_menu;
auto colors_updated = colors.update(); auto colors_updated = colors.update();
auto new_light_mode = (theme_setting == Light) || (theme_setting == System && colors.light_mode); auto new_light_mode = (theme_setting == Light) || (theme_setting == System && colors.light_mode);
@ -355,10 +355,10 @@ void D2DOverlayWindow::show(HWND active_window, bool snappable)
total_screen.rect.top += monitor_dy; total_screen.rect.top += monitor_dy;
total_screen.rect.bottom += monitor_dy; total_screen.rect.bottom += monitor_dy;
tasklist.update(); tasklist.update();
if (active_window) if (window)
{ {
// Ignore errors, if this fails we will just not show the thumbnail // Ignore errors, if this fails we will just not show the thumbnail
DwmRegisterThumbnail(hwnd, active_window, &thumbnail); DwmRegisterThumbnail(hwnd, window, &thumbnail);
} }
background_animation.reset(); background_animation.reset();
@ -644,7 +644,7 @@ void D2DOverlayWindow::hide_thumbnail()
DwmUpdateThumbnailProperties(thumbnail, &thumb_properties); DwmUpdateThumbnailProperties(thumbnail, &thumb_properties);
} }
void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_dc) void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_device_context)
{ {
if (!hidden && !overlay_window_instance->overlay_visible()) if (!hidden && !overlay_window_instance->overlay_visible())
{ {
@ -652,7 +652,7 @@ void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_dc)
return; return;
} }
d2d_dc->Clear(); d2d_device_context->Clear();
int taskbar_icon_shortcuts_x_offset = 0, taskbar_icon_shortcuts_y_offset = 0; int taskbar_icon_shortcuts_x_offset = 0, taskbar_icon_shortcuts_y_offset = 0;
float current_background_anim_value = (float)background_animation.value(Animation::AnimFunctions::LINEAR); float current_background_anim_value = (float)background_animation.value(Animation::AnimFunctions::LINEAR);
@ -665,12 +665,12 @@ void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_dc)
winrt::com_ptr<ID2D1SolidColorBrush> brush; winrt::com_ptr<ID2D1SolidColorBrush> brush;
float brush_opacity = get_overlay_opacity(); float brush_opacity = get_overlay_opacity();
D2D1_COLOR_F brushColor = light_mode ? D2D1::ColorF(1.0f, 1.0f, 1.0f, brush_opacity) : D2D1::ColorF(0, 0, 0, brush_opacity); D2D1_COLOR_F brushColor = light_mode ? D2D1::ColorF(1.0f, 1.0f, 1.0f, brush_opacity) : D2D1::ColorF(0, 0, 0, brush_opacity);
winrt::check_hresult(d2d_dc->CreateSolidColorBrush(brushColor, brush.put())); winrt::check_hresult(d2d_device_context->CreateSolidColorBrush(brushColor, brush.put()));
D2D1_RECT_F background_rect = {}; D2D1_RECT_F background_rect = {};
background_rect.bottom = (float)window_height; background_rect.bottom = (float)window_height;
background_rect.right = (float)window_width; background_rect.right = (float)window_width;
d2d_dc->SetTransform(D2D1::Matrix3x2F::Identity()); d2d_device_context->SetTransform(D2D1::Matrix3x2F::Identity());
d2d_dc->FillRectangle(background_rect, brush.get()); d2d_device_context->FillRectangle(background_rect, brush.get());
// Draw the taskbar shortcuts (the arrows with numbers) // Draw the taskbar shortcuts (the arrows with numbers)
if (taskbar_icon_shortcuts_shown) if (taskbar_icon_shortcuts_shown)
@ -703,7 +703,7 @@ void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_dc)
{ {
continue; continue;
} }
render_arrow(arrows[(size_t)(button.keynum) - 1], button, window_rect, use_overlay->get_scale(), d2d_dc, taskbar_icon_shortcuts_x_offset, taskbar_icon_shortcuts_y_offset); render_arrow(arrows[(size_t)(button.keynum) - 1], button, window_rect, use_overlay->get_scale(), d2d_device_context, taskbar_icon_shortcuts_x_offset, taskbar_icon_shortcuts_y_offset);
} }
} }
} }
@ -793,7 +793,7 @@ void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_dc)
{ {
brushColor = D2D1::ColorF(colors.start_color_menu, miniature_shown ? current_global_windows_shortcuts_anim_value * 0.9f : current_global_windows_shortcuts_anim_value * 0.3f); brushColor = D2D1::ColorF(colors.start_color_menu, miniature_shown ? current_global_windows_shortcuts_anim_value * 0.9f : current_global_windows_shortcuts_anim_value * 0.3f);
brush = nullptr; brush = nullptr;
winrt::check_hresult(d2d_dc->CreateSolidColorBrush(brushColor, brush.put())); winrt::check_hresult(d2d_device_context->CreateSolidColorBrush(brushColor, brush.put()));
for (auto& monitor : monitors) for (auto& monitor : monitors)
{ {
D2D1_RECT_F monitor_rect; D2D1_RECT_F monitor_rect;
@ -802,22 +802,22 @@ void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_dc)
monitor_rect.top = (float)((monitor_size.top() + monitor_dy) * rect_and_scale.scale + rect_and_scale.rect.top); monitor_rect.top = (float)((monitor_size.top() + monitor_dy) * rect_and_scale.scale + rect_and_scale.rect.top);
monitor_rect.right = (float)((monitor_size.right() + monitor_dx) * rect_and_scale.scale + rect_and_scale.rect.left); monitor_rect.right = (float)((monitor_size.right() + monitor_dx) * rect_and_scale.scale + rect_and_scale.rect.left);
monitor_rect.bottom = (float)((monitor_size.bottom() + monitor_dy) * rect_and_scale.scale + rect_and_scale.rect.top); monitor_rect.bottom = (float)((monitor_size.bottom() + monitor_dy) * rect_and_scale.scale + rect_and_scale.rect.top);
d2d_dc->SetTransform(D2D1::Matrix3x2F::Identity()); d2d_device_context->SetTransform(D2D1::Matrix3x2F::Identity());
d2d_dc->FillRectangle(monitor_rect, brush.get()); d2d_device_context->FillRectangle(monitor_rect, brush.get());
} }
} }
// Finalize the overlay - dimm the buttons if no thumbnail is present and show "No active window" // Finalize the overlay - dimm the buttons if no thumbnail is present and show "No active window"
use_overlay->toggle_window_group(miniature_shown || window_state == MINIMIZED); use_overlay->toggle_window_group(miniature_shown || window_state == MINIMIZED);
if (!miniature_shown && window_state != MINIMIZED) if (!miniature_shown && window_state != MINIMIZED)
{ {
no_active.render(d2d_dc); no_active.render(d2d_device_context);
window_state = UNKNOWN; window_state = UNKNOWN;
} }
// Set the animation - move the draw window according to animation step // Set the animation - move the draw window according to animation step
int global_windows_shortcuts_y_offset = (int)(pos_global_windows_shortcuts_anim_value * use_overlay->height() * use_overlay->get_scale()); int global_windows_shortcuts_y_offset = (int)(pos_global_windows_shortcuts_anim_value * use_overlay->height() * use_overlay->get_scale());
auto popIn = D2D1::Matrix3x2F::Translation(0, (float)global_windows_shortcuts_y_offset); auto popIn = D2D1::Matrix3x2F::Translation(0, (float)global_windows_shortcuts_y_offset);
d2d_dc->SetTransform(popIn); d2d_device_context->SetTransform(popIn);
// Animate keys // Animate keys
for (unsigned id = 0; id < key_animations.size();) for (unsigned id = 0; id < key_animations.size();)
@ -846,7 +846,7 @@ void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_dc)
++id; ++id;
} }
// Finally: render the overlay... // Finally: render the overlay...
use_overlay->render(d2d_dc); use_overlay->render(d2d_device_context);
// ... window arrows texts ... // ... window arrows texts ...
std::wstring left, right, up, down; std::wstring left, right, up, down;
bool left_disabled = false; bool left_disabled = false;
@ -925,13 +925,13 @@ void D2DOverlayWindow::render(ID2D1DeviceContext5* d2d_dc)
} }
auto text_color = D2D1::ColorF(light_mode ? 0x222222 : 0xDDDDDD, active_window_snappable && (miniature_shown || window_state == MINIMIZED) ? 1.0f : 0.3f); auto text_color = D2D1::ColorF(light_mode ? 0x222222 : 0xDDDDDD, active_window_snappable && (miniature_shown || window_state == MINIMIZED) ? 1.0f : 0.3f);
use_overlay->find_element(L"KeyUpGroup")->SetAttributeValue(L"fill-opacity", up_disabled ? 0.3f : 1.0f); use_overlay->find_element(L"KeyUpGroup")->SetAttributeValue(L"fill-opacity", up_disabled ? 0.3f : 1.0f);
text.set_alignment_center().write(d2d_dc, text_color, use_overlay->get_maximize_label(), up); text.set_alignment_center().write(d2d_device_context, text_color, use_overlay->get_maximize_label(), up);
use_overlay->find_element(L"KeyDownGroup")->SetAttributeValue(L"fill-opacity", down_disabled ? 0.3f : 1.0f); use_overlay->find_element(L"KeyDownGroup")->SetAttributeValue(L"fill-opacity", down_disabled ? 0.3f : 1.0f);
text.write(d2d_dc, text_color, use_overlay->get_minimize_label(), down); text.write(d2d_device_context, text_color, use_overlay->get_minimize_label(), down);
use_overlay->find_element(L"KeyLeftGroup")->SetAttributeValue(L"fill-opacity", left_disabled ? 0.3f : 1.0f); use_overlay->find_element(L"KeyLeftGroup")->SetAttributeValue(L"fill-opacity", left_disabled ? 0.3f : 1.0f);
text.set_alignment_right().write(d2d_dc, text_color, use_overlay->get_snap_left(), left); text.set_alignment_right().write(d2d_device_context, text_color, use_overlay->get_snap_left(), left);
use_overlay->find_element(L"KeyRightGroup")->SetAttributeValue(L"fill-opacity", right_disabled ? 0.3f : 1.0f); use_overlay->find_element(L"KeyRightGroup")->SetAttributeValue(L"fill-opacity", right_disabled ? 0.3f : 1.0f);
text.set_alignment_left().write(d2d_dc, text_color, use_overlay->get_snap_right(), right); text.set_alignment_left().write(d2d_device_context, text_color, use_overlay->get_snap_right(), right);
} }
else else
{ {

View File

@ -48,7 +48,7 @@ class D2DOverlayWindow : public D2DWindow
{ {
public: public:
D2DOverlayWindow(); D2DOverlayWindow();
void show(HWND active_window, bool snappable); void show(HWND window, bool snappable);
~D2DOverlayWindow(); ~D2DOverlayWindow();
void apply_overlay_opacity(float opacity); void apply_overlay_opacity(float opacity);
void apply_press_time_for_global_windows_shortcuts(int press_time); void apply_press_time_for_global_windows_shortcuts(int press_time);
@ -57,9 +57,9 @@ public:
void quick_hide(); void quick_hide();
HWND get_window_handle(); HWND get_window_handle();
void SetWindowCloseType(std::wstring windowCloseType) void SetWindowCloseType(std::wstring wCloseType)
{ {
this->windowCloseType = windowCloseType; windowCloseType = wCloseType;
} }
private: private:
@ -68,7 +68,7 @@ private:
void hide_thumbnail(); void hide_thumbnail();
virtual void init() override; virtual void init() override;
virtual void resize() override; virtual void resize() override;
virtual void render(ID2D1DeviceContext5* d2d_dc) override; virtual void render(ID2D1DeviceContext5* d2dd2d_device_context_dc) override;
virtual void on_show() override; virtual void on_show() override;
virtual void on_hide() override; virtual void on_hide() override;
float get_overlay_opacity(); float get_overlay_opacity();

View File

@ -56,14 +56,14 @@ namespace NonLocalizable
struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZonesCallback>, public SettingsObserver struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZonesCallback>, public SettingsObserver
{ {
public: public:
FancyZones(HINSTANCE hinstance, std::function<void()> disableModuleCallback) noexcept : FancyZones(HINSTANCE hinstance, std::function<void()> disableModuleCallbackFunction) noexcept :
SettingsObserver({ SettingId::EditorHotkey, SettingId::PrevTabHotkey, SettingId::NextTabHotkey, SettingId::SpanZonesAcrossMonitors }), SettingsObserver({ SettingId::EditorHotkey, SettingId::PrevTabHotkey, SettingId::NextTabHotkey, SettingId::SpanZonesAcrossMonitors }),
m_hinstance(hinstance), m_hinstance(hinstance),
m_windowMoveHandler([this]() { m_windowMoveHandler([this]() {
PostMessageW(m_window, WM_PRIV_LOCATIONCHANGE, NULL, NULL); PostMessageW(m_window, WM_PRIV_LOCATIONCHANGE, NULL, NULL);
}) })
{ {
this->disableModuleCallback = std::move(disableModuleCallback); this->disableModuleCallback = std::move(disableModuleCallbackFunction);
FancyZonesSettings::instance().LoadSettings(); FancyZonesSettings::instance().LoadSettings();

View File

@ -1,6 +1,12 @@
#pragma once #pragma once
// disabling warning 4458 - declaration of 'identifier' hides class member
// to avoid warnings from GDI files - can't add winRT directory to external code
// in the Cpp.Build.props
#pragma warning(push)
#pragma warning(disable : 4458)
#include "gdiplus.h" #include "gdiplus.h"
#pragma warning(pop)
namespace std namespace std
{ {

View File

@ -2,7 +2,13 @@
#include <Windows.h> #include <Windows.h>
// disabling warning 4458 - declaration of 'identifier' hides class member
// to avoid warnings from GDI files - can't add winRT directory to external code
// in the Cpp.Build.props
#pragma warning(push)
#pragma warning(disable : 4458)
#include "gdiplus.h" #include "gdiplus.h"
#pragma warning(pop)
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -21,7 +21,13 @@
#include <mutex> #include <mutex>
#include <fileapi.h> #include <fileapi.h>
// disabling warning 4458 - declaration of 'identifier' hides class member
// to avoid warnings from GDI files - can't add winRT directory to external code
// in the Cpp.Build.props
#pragma warning(push)
#pragma warning(disable : 4458)
#include <gdiplus.h> #include <gdiplus.h>
#pragma warning(pop)
// Non-Localizable strings // Non-Localizable strings
namespace NonLocalizable namespace NonLocalizable
@ -58,7 +64,6 @@ namespace
} }
public: public:
HWND NewZonesOverlayWindow(Rect position, HINSTANCE hinstance, WorkArea* owner) HWND NewZonesOverlayWindow(Rect position, HINSTANCE hinstance, WorkArea* owner)
{ {
HWND windowFromPool = ExtractWindow(); HWND windowFromPool = ExtractWindow();
@ -666,4 +671,3 @@ LRESULT CALLBACK WorkArea::s_WndProc(HWND window, UINT message, WPARAM wparam, L
return (thisRef != nullptr) ? thisRef->WndProc(message, wparam, lparam) : return (thisRef != nullptr) ? thisRef->WndProc(message, wparam, lparam) :
DefWindowProc(window, message, wparam, lparam); DefWindowProc(window, message, wparam, lparam);
} }

View File

@ -239,8 +239,8 @@ namespace FancyZonesUnitTests
TEST_METHOD (FromJsonInvalidTypes) TEST_METHOD (FromJsonInvalidTypes)
{ {
json::JsonObject m_json = json::JsonObject::Parse(L"{\"ref-width\": true, \"ref-height\": \"string\", \"zones\": [{\"X\": \"11\", \"Y\": \"22\", \"width\": \".\", \"height\": \"*\"}, {\"X\": null, \"Y\": {}, \"width\": [], \"height\": \"абвгд\"}]}"); json::JsonObject local_json = json::JsonObject::Parse(L"{\"ref-width\": true, \"ref-height\": \"string\", \"zones\": [{\"X\": \"11\", \"Y\": \"22\", \"width\": \".\", \"height\": \"*\"}, {\"X\": null, \"Y\": {}, \"width\": [], \"height\": \"абвгд\"}]}");
Assert::IsFalse(CanvasLayoutInfoJSON::FromJson(m_json).has_value()); Assert::IsFalse(CanvasLayoutInfoJSON::FromJson(local_json).has_value());
} }
}; };

View File

@ -46,7 +46,14 @@
#include <common/utils/window.h> #include <common/utils/window.h>
#include <common/version/version.h> #include <common/version/version.h>
#include <common/utils/string_utils.h> #include <common/utils/string_utils.h>
// disabling warning 4458 - declaration of 'identifier' hides class member
// to avoid warnings from GDI files - can't add winRT directory to external code
// in the Cpp.Build.props
#pragma warning(push)
#pragma warning(disable : 4458)
#include <gdiplus.h> #include <gdiplus.h>
#pragma warning(pop)
namespace namespace
{ {

View File

@ -95,7 +95,7 @@ namespace
} }
// Enumerate all the events in the result set. // Enumerate all the events in the result set.
void PrintResults(EVT_HANDLE hResults) void PrintResults(EVT_HANDLE results)
{ {
DWORD status = ERROR_SUCCESS; DWORD status = ERROR_SUCCESS;
EVT_HANDLE hEvents[BATCH_SIZE]; EVT_HANDLE hEvents[BATCH_SIZE];
@ -104,7 +104,7 @@ namespace
while (true) while (true)
{ {
// Get a block of events from the result set. // Get a block of events from the result set.
if (!EvtNext(hResults, BATCH_SIZE, hEvents, INFINITE, 0, &dwReturned)) if (!EvtNext(results, BATCH_SIZE, hEvents, INFINITE, 0, &dwReturned))
{ {
if (ERROR_NO_MORE_ITEMS != (status = GetLastError())) if (ERROR_NO_MORE_ITEMS != (status = GetLastError()))
{ {

View File

@ -162,8 +162,8 @@ private:
{ {
auto path = tmpDir; auto path = tmpDir;
path += "installationFolderStructure.txt"; path += "installationFolderStructure.txt";
std::wofstream os = std::wofstream(path); std::wofstream out_s = std::wofstream(path);
return os; return out_s;
} }
public: public:
Reporter(const path& tmpDir) Reporter(const path& tmpDir)