gcc build warning #5104

Closed
opened 2022-03-13 08:53:16 +00:00 by JamesBoer · 4 comments
JamesBoer commented 2022-03-13 08:53:16 +00:00 (Migrated from github.com)

In gcc, when compiling at maximum error and warning levels (-Wall -Wextra -pedantic -Werror), there is a build warning (which is treated as an error for my project), at imgui_impl_glfw.cpp, line 129.

/home/jamesboer/Projects/ImFrame/Source/ImGui/imgui_impl_glfw.cpp: In constructor ‘ImGui_ImplGlfw_Data::ImGui_ImplGlfw_Data()’:
/home/jamesboer/Projects/ImFrame/Source/ImGui/imgui_impl_glfw.cpp:129:60: error: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct ImGui_ImplGlfw_Data’; use assignment or value-initialization instead [-Werror=class-memaccess]
129 | ImGui_ImplGlfw_Data() { memset(this, 0, sizeof(*this)); }
| ^
/home/jamesboer/Projects/ImFrame/Source/ImGui/imgui_impl_glfw.cpp:107:8: note: ‘struct ImGui_ImplGlfw_Data’ declared here
107 | struct ImGui_ImplGlfw_Data
| ^~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/ImFrame.dir/build.make:89: CMakeFiles/ImFrame.dir/Source/ImGui/imgui_impl_glfw.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:288: CMakeFiles/ImFrame.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

gcc does not like zeroing a struct with non trivial data using memset. If you don't wish to initialize individual members, you can get around this warning by casting the this pointer to void*.

ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }

In gcc, when compiling at maximum error and warning levels (-Wall -Wextra -pedantic -Werror), there is a build warning (which is treated as an error for my project), at imgui_impl_glfw.cpp, line 129. /home/jamesboer/Projects/ImFrame/Source/ImGui/imgui_impl_glfw.cpp: In constructor ‘ImGui_ImplGlfw_Data::ImGui_ImplGlfw_Data()’: /home/jamesboer/Projects/ImFrame/Source/ImGui/imgui_impl_glfw.cpp:129:60: error: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct ImGui_ImplGlfw_Data’; use assignment or value-initialization instead [-Werror=class-memaccess] 129 | ImGui_ImplGlfw_Data() { memset(this, 0, sizeof(*this)); } | ^ /home/jamesboer/Projects/ImFrame/Source/ImGui/imgui_impl_glfw.cpp:107:8: note: ‘struct ImGui_ImplGlfw_Data’ declared here 107 | struct ImGui_ImplGlfw_Data | ^~~~~~~~~~~~~~~~~~~ cc1plus: all warnings being treated as errors make[2]: *** [CMakeFiles/ImFrame.dir/build.make:89: CMakeFiles/ImFrame.dir/Source/ImGui/imgui_impl_glfw.cpp.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:288: CMakeFiles/ImFrame.dir/all] Error 2 make: *** [Makefile:84: all] Error 2 gcc does not like zeroing a struct with non trivial data using memset. If you don't wish to initialize individual members, you can get around this warning by casting the this pointer to void*. ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }
ocornut commented 2022-03-13 11:21:06 +00:00 (Migrated from github.com)

Pushed a fix as part of fd06ed833b
Thank you!

(PS: I don't think it makes any sense to be compiling third-party code with zealous warnings let alone warnings on error. If you use third-party code you are implicitly trusting what the code does.)

Pushed a fix as part of fd06ed833be6a4ac9a99c0383ca014011535c246 Thank you! (PS: I don't think it makes any sense to be compiling third-party code with zealous warnings let alone warnings on error. If you use third-party code you are implicitly trusting what the code does.)
JamesBoer commented 2022-03-13 12:43:17 +00:00 (Migrated from github.com)

I typically compile 3rd party, ImGui included, with less strict settings, for obvious reasons. In this particular case, I copy those particular files into my own project, and thus they are subject to the more strict compiler settings my own code uses.

I typically compile 3rd party, ImGui included, with less strict settings, for obvious reasons. In this particular case, I copy those particular files into my own project, and thus they are subject to the more strict compiler settings my own code uses.
ocornut commented 2022-03-13 12:45:20 +00:00 (Migrated from github.com)

You are right, and I guess this is exacerbated by dear imgui’s position on suggesting to do so, I hadn’t thought about that aspect before. Thanks for bringing to light.

You are right, and I guess this is exacerbated by dear imgui’s position on suggesting to do so, I hadn’t thought about that aspect before. Thanks for bringing to light.
JamesBoer commented 2022-03-13 13:01:19 +00:00 (Migrated from github.com)

Not a problem.

I do appreciate ImGui providing such handy drop-in integration files, as it really makes integration and maintenance a snap. When I previously integrated it into my own game engine using it's own APIs, for which there obviously weren't convenient integration files, it certainly was a lot more work. So I definitely think it's the right approach.

Anyhow, as always, I appreciate the work you do on this great library.

Not a problem. I do appreciate ImGui providing such handy drop-in integration files, as it really makes integration and maintenance a snap. When I previously integrated it into my own game engine using it's own APIs, for which there obviously weren't convenient integration files, it certainly was a lot more work. So I definitely think it's the right approach. Anyhow, as always, I appreciate the work you do on this great library.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#5104
No description provided.