This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/81413] New: overloaded new and delete might not be called when dynamically linked with libstdc++
- From: "space_sk8er8 at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 12 Jul 2017 13:01:59 +0000
- Subject: [Bug libstdc++/81413] New: overloaded new and delete might not be called when dynamically linked with libstdc++
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81413
Bug ID: 81413
Summary: overloaded new and delete might not be called when
dynamically linked with libstdc++
Product: gcc
Version: 7.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: space_sk8er8 at hotmail dot com
Target Milestone: ---
new and delete operator overloading might or might not work when compiled using
different compilers and different c++ standards.
I used the following code to test the compilers.
#include <iostream>
void * operator new(size_t size)
{
std::cout << "1\n";
return malloc(size);
}
void operator delete(void * ptr) noexcept
{
std::cout << "2\n";
free(ptr);
}
int main(void)
{
int *n1 = new int;
delete n1;
int *n2 = new int[10];
delete[] n2;
}
Here are the results I got from several compilers I have tested the code on.
mingw-w64 official build - x86_64-7.1.0-release-posix-seh-rt_v5-rev0.7z
c++11
1
2
c++14
1
clang x86_64 - v4.0.0 manually built without patches using the compiler above
c++11 and c++14
1
2
msvc - platform toolset v141 & sdk v10.0.15063.0
/std:c++14 & /std:c++latest
1
2
1
2
All tests are performed on Windows 7. I can't test compilers on GNU/Linux OS
because I don't have any VMs set up.
Apparently, if -static or -static-libstdc++ is specified, it outputs the
intended result.
c++11 and c++14
1
2
1
2
More discussions at
https://sourceforge.net/p/mingw-w64/bugs/634/
and
https://stackoverflow.com/questions/44907098/c-new-and-delete-overloading