Hi, i have a compile problem with Clang 20.1 ! Older versions of Clang can compile the…
- User
Hi, i have a compile problem with Clang 20.1 ! Older versions of Clang can compile the file 3rdparty\bgfx\3rdparty\dear-imgui\imgui.h. See here https://raw.githubusercontent.com/mamedev/mame/refs/heads/master/3rdparty/bgfx/3rdparty/dear-imgui/imgui.h
The compile error is this here:
Clang 20.1.0 detected Compiling 3rdparty/bgfx/3rdparty/dear-imgui/imgui.cpp... In file included from ../../../../../3rdparty/bgfx/3rdparty/dear-imgui/imgui.cpp:856: ../../../../../3rdparty/bgfx/3rdparty/dear-imgui/imgui.h:2522:60: error: first argument in call to 'memset' is a pointer to non-trivially copyable type 'ImDrawList' [-Werror,-Wnontrivial-memcall] 2522 | ImDrawList(ImDrawListSharedData* shared_data) { memset(this, 0, sizeof(this)); _Data = shared_data; } | ^ ../../../../../3rdparty/bgfx/3rdparty/dear-imgui/imgui.h:2522:60: note: explicitly cast the pointer to silence this warning 2522 | ImDrawList(ImDrawListSharedData shared_data) { memset(this, 0, sizeof(this)); _Data = shared_data; } | ^ | (void)
This is the code at line 2522:
code// If you want to create ImDrawList instances, pass them ImGui::GetDrawListSharedData() or create and use your own ImDrawListSharedData (so you can use ImDrawList without ImGui) ImDrawList(ImDrawListSharedData* shared_data) { memset(this, 0, sizeof(*this)); _Data = shared_data; } - Assistant
- User
And how can i changed: inline ImDrawListSplitter() { memset(this, 0, sizeof(*this)); }
- Assistant
Similar to the constructor for
ImDrawList, usingmemsetto initialize theImDrawListSplitter(assuming it has a non-trivially copyable type) can lead to issues with your code. Instead of usingmemset, you should use member initializer lists to ensure that all members of the struct/class are properly initialized.Here’s how you can modify the
ImDrawListSplitterconstructor: - User
What ybout this: inline ImDrawListSplitter() : _Current(0), _Count(1), _Channels() { }
- Assistant
Using an initializer list in the constructor, as you've shown, is a great approach! The line you provided initializes members of the class directly, which is the preferred way to initialize members, especially for non-trivial types.