mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-21 19:35:28 -05:00
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.
22 lines
432 B
C
22 lines
432 B
C
// PR c++/121068
|
|
// { dg-do compile { target c++26 } }
|
|
|
|
constexpr void *operator new (__SIZE_TYPE__, void *p) { return p; }
|
|
constexpr void *operator new[] (__SIZE_TYPE__, void *p) { return p; }
|
|
|
|
consteval int
|
|
foo(int n)
|
|
{
|
|
using T = int;
|
|
union { T arr[3]; };
|
|
new(arr) T[n]; // makes arr active
|
|
for (int i = 0; i < 3; ++i)
|
|
arr[i].~T();
|
|
|
|
new (arr + 2) T{10}; // A
|
|
|
|
return 1;
|
|
};
|
|
|
|
constexpr int g = foo(3);
|