]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Suppress -Wclass-memaccess warnings in bits/stl_uninitialized.h
authorJonathan Wakely <jwakely@redhat.com>
Tue, 30 Sep 2025 09:49:08 +0000 (10:49 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 1 Oct 2025 12:54:59 +0000 (13:54 +0100)
commitf4409fd79463803267a2dfe28c1d9736241ab356
tree5e17203800e0db0773584e417cb47445f331b861
parentc6865e7e15bc9a1337df00d2ca03604e1712a2dd
libstdc++: Suppress -Wclass-memaccess warnings in bits/stl_uninitialized.h

Running the testsuite with warnings enabled gives:

FAIL: 20_util/specialized_algorithms/uninitialized_copy/58982.cc  -std=gnu++26 (test for excess errors)
Excess errors:
.../libstdc++-v3/include/bits/stl_uninitialized.h:293: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' writing to an object of type 'struct T' with no trivial copy-assignment; use copy-initialization instead [-Wclass-memaccess]

This is because -Wclass-memaccess warns about using memcpy on types
which have a deleted assignment, even though those can be trivially
copyable and so using memcpy on them is technically valid. Where these
warnings occur in bits/stl_uninitialized.h we're only using memcpy after
checking for trivially copyable (and any other relevant conditions) so
we can be confident that we're using it safely. We also don't actually
care about assignment here because we're only constructing new objects,
not copying over existing ones (which is what std::copy does, but not
std::uninitialized_copy).

Uses of memcpy in the C++98 code don't need to have -Wclass-memaccess
suppressed, because there are no deleted functions in C++98 so there are
no types which are trivially copyable but trigger the warning.

libstdc++-v3/ChangeLog:

* include/bits/stl_uninitialized.h (uninitialized_copy)
(uninitialized_fill, uninitialized_fill_n): Use pragmas to
suppress -Wclass-memaccess warnings.

Reviewed-by: Tomasz KamiƄski <tkaminsk@redhat.com>
libstdc++-v3/include/bits/stl_uninitialized.h