]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: clobber non-placement new
authorJason Merrill <jason@redhat.com>
Wed, 8 Oct 2025 15:09:49 +0000 (16:09 +0100)
committerJason Merrill <jason@redhat.com>
Wed, 8 Oct 2025 15:09:49 +0000 (16:09 +0100)
commitd77b548fb647d52817d0c44d45bb817d166b7a19
tree444b902dab0d3eaa83722c9059568268a9c0a087
parentd52a81fdb3cec0de08bbcefd3c0a31817133b95f
c++: clobber non-placement new

And also add the clobber for non-placement new.

For now let's limit the clobber of an array with non-constant bound to
placement new in constant evaluation, where we need it to set the active
member of a union.

And catch some additional cases of there being no actual data to clobber.

This changes the diagnostics in a couple of analyzer tests, but the new
diagnostics are also valid.

It also adds some -Wuninitialized warnings which seem like an improvement;
the lines that now warn about an uninitialized vptr are correct, since
trying to assign to a member of a virtual base reads the vptr of an object
that was never created.

gcc/cp/ChangeLog:

* init.cc (build_new_1): Also clobber for non-placement new.
Only loop clobber in constexpr.
* expr.cc (wrap_with_if_consteval): New.
* cp-tree.h (wrap_with_if_consteval): Declare.

gcc/testsuite/ChangeLog:

* g++.dg/analyzer/new-2.C: Adjust diags.
* g++.dg/analyzer/noexcept-new.C: Adjust diags.
* g++.dg/warn/Warray-bounds-23.C: Add warnings.
* g++.dg/warn/Warray-bounds-24.C: Add warnings.
* g++.dg/cpp26/constexpr-new4a.C: New test.
gcc/cp/cp-tree.h
gcc/cp/expr.cc
gcc/cp/init.cc
gcc/testsuite/g++.dg/analyzer/new-2.C
gcc/testsuite/g++.dg/analyzer/noexcept-new.C
gcc/testsuite/g++.dg/cpp26/constexpr-new4a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Warray-bounds-23.C
gcc/testsuite/g++.dg/warn/Warray-bounds-24.C