Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore clang warning Wnontrivial-memaccess #8129

Merged

Conversation

mayawarrier
Copy link
Contributor

@mayawarrier mayawarrier commented Nov 5, 2024

  • Clang produces warning Wnontrivial-memaccess when memset is used on a non-trivially copyable type.
  • Platform: Clang 20.0.0, Emscripten 1
  • Warning log: warning_log.txt
  • Locations where warnings are triggered:
    image

- Produced when memset(this, ..) is used on a non-trivially copyable type
@ocornut
Copy link
Owner

ocornut commented Nov 5, 2024

Thank you Maya for your report and PR!

I'm quite surprised it would happen in e.g. imgui_impl_metal.mm where the only memset() is for a class with a raw pointer. My guess is that memset() being inside a constructor, it makes the class non-trivial from Clang's pov.

My other surprise is that we do have an equivalent warning silencing for GCC:

#pragma GCC diagnostic ignored "-Wclass-memaccess"      // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead

But this is used in more location than the files you touched, so that's curious. I'm merging for now.
Thanks!

@ocornut ocornut merged commit 88e2327 into ocornut:master Nov 5, 2024
ocornut added a commit that referenced this pull request Nov 7, 2024
Amend 88e2327
Use void* cast in backend where the memset are infrequent.
@mayawarrier mayawarrier deleted the clang-ignore-Wnontrivial-memaccess branch November 8, 2024 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants