Cast this to (void*) in zero-clearing memset calls to fix -Wnontrivial-memcall (#9247, #8295, #8129, #8135)

Clang 20+ warns on memset(this, ...) for non-trivially copyable types via -Wnontrivial-memcall.
Should separately investigate -Wnonontrivial-memaccess vs -Wnonontrivial-memcall.
This commit is contained in:
Laurenz Altenmüller
2026-02-16 14:36:36 +01:00
committed by ocornut
parent eaa32bb787
commit fbe973a8d0
6 changed files with 55 additions and 55 deletions

View File

@@ -1568,7 +1568,7 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
ImGuiIO::ImGuiIO()
{
// Most fields are initialized with zero
memset(this, 0, sizeof(*this));
memset((void*)this, 0, sizeof(*this));
IM_STATIC_ASSERT(IM_COUNTOF(ImGuiIO::MouseDown) == ImGuiMouseButton_COUNT && IM_COUNTOF(ImGuiIO::MouseClicked) == ImGuiMouseButton_COUNT);
// Settings
@@ -1974,7 +1974,7 @@ void ImGuiIO::AddFocusEvent(bool focused)
ImGuiPlatformIO::ImGuiPlatformIO()
{
// Most fields are initialized with zero
memset(this, 0, sizeof(*this));
memset((void*)this, 0, sizeof(*this));
Platform_LocaleDecimalPoint = '.';
}
@@ -3231,7 +3231,7 @@ static void ImGuiListClipper_SeekCursorAndSetupPrevLine(ImGuiListClipper* clippe
ImGuiListClipper::ImGuiListClipper()
{
memset(this, 0, sizeof(*this));
memset((void*)this, 0, sizeof(*this));
}
ImGuiListClipper::~ImGuiListClipper()
@@ -4525,7 +4525,7 @@ void ImGui::CallContextHooks(ImGuiContext* ctx, ImGuiContextHookType hook_type)
// ImGuiWindow is mostly a dumb struct. It merely has a constructor and a few helper methods
ImGuiWindow::ImGuiWindow(ImGuiContext* ctx, const char* name) : DrawListInst(NULL)
{
memset(this, 0, sizeof(*this));
memset((void*)this, 0, sizeof(*this));
Ctx = ctx;
Name = ImStrdup(name);
NameBufLen = (int)ImStrlen(name) + 1;