GCC 15 may fold new and delete pairs, like
A *bb = new A[10];
delete [] bb;
bb = new (std::nothrow) A [10];
delete [] bb;
as shown in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115712
Avoid folding new and delete pairs by adding a function call between new
and delete.
* testsuite/ld-elf/dl5.cc: Include "dl5.h".
(A): Removed.
Call foo between new and delete.
* testsuite/ld-elf/dl5.h: New file.
* testsuite/ld-elf/new.cc: Include "dl5.h".
(foo): New function.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
#include <stdio.h>
#include <stdlib.h>
#include <new>
+#include "dl5.h"
int pass = 0;
free (ptr);
}
-class A
-{
-public:
- A() {}
- ~A() { }
- int a;
- int b;
-};
-
-
int
main (void)
{
A *bb = new A[10];
delete [] bb;
+ foo (bb);
bb = new (std::nothrow) A [10];
+ foo (bb);
delete [] bb;
if (pass == 4)
--- /dev/null
+class A
+{
+public:
+ A() {}
+ ~A() { }
+ int a;
+ int b;
+};
+
+extern void foo (A *);
#include <new>
+#include "dl5.h"
using std::bad_alloc;
{
return ::operator new(sz, nothrow);
}
+
+void
+foo (A *)
+{
+}