After doing a quick search, it appears other projects have hit this (and also wonder about the fact that it doesn't check for trivially_copyable).
Warn when the destination of a call to a raw memory function such as memset or memcpy is an object of class type, and when writing into such an object might bypass the class non-trivial or deleted constructor or copy assignment, violate const-correctness or encapsulation, or corrupt virtual table pointers.
Right. Also, the wording on the warning's documentation somewhat sidesteps the issue - it doesn't actually use the standard's terms for trivially-copyable. Rather:Warn when the destination of a call to a raw memory function such as memset or memcpy is an object of class type, and when writing into such an object might bypass the class non-trivial or deleted constructor or copy assignment, violate const-correctness or encapsulation, or corrupt virtual table pointers.That's fuzzy enough (to me), that I think it might be WAI? (Even if I disagree with the principle of warning in this case).
On Mon, Apr 29, 2024 at 1:56 PM Daniel Cheng <dch...@chromium.org> wrote:I think the officially-recommended way to mark this safe for gcc's warning is to use a cast, as Brian noted above (and that's what I did in the reland: https://skia-review.googlesource.com/c/skia/+/836616)I didn't search for a pre-existing GCC bug (or try filing a new one). IMO, as far as GCC workarounds go, this one is fairly benign, and I didn't really have the time to advocate for changing this in gcc.DanielOn Mon, 29 Apr 2024 at 08:31, Peter Kasting <pkas...@chromium.org> wrote:On Wednesday, April 3, 2024 at 11:27:34 AM UTC-7 brian...@google.com wrote:After doing a quick search, it appears other projects have hit this (and also wonder about the fact that it doesn't check for trivially_copyable).Is there a gcc bug? If not, sounds like we should file one -- I agree that copying with memcpy() should not produce a warning for types marked trivially-copyable.PK
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAMcBjo6tc2EHc4X%2BP1-Gx21en0LNDW1-2mosNOU_VmTH3y-kBw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAAE6AQs6fCZ1aaw--cEDhOV_279aRg%3D%2BC170yYyfo%3DUm4M_Yg%40mail.gmail.com.
On Mon, Apr 29, 2024 at 11:00 AM 'Brian Osman' via cxx <c...@chromium.org> wrote:Right. Also, the wording on the warning's documentation somewhat sidesteps the issue - it doesn't actually use the standard's terms for trivially-copyable. Rather:Warn when the destination of a call to a raw memory function such as memset or memcpy is an object of class type, and when writing into such an object might bypass the class non-trivial or deleted constructor or copy assignment, violate const-correctness or encapsulation, or corrupt virtual table pointers.That's fuzzy enough (to me), that I think it might be WAI? (Even if I disagree with the principle of warning in this case).That just feels like it moves the issue to "the intention is wrong", though? Being something you can safely copy with memcpy is basically the point of "trivially copyable" so it seems incorrect for the compiler to invent a different definition of it.The only bug I'm aware of for this is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107361.