http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50594
Bug #: 50594
Summary: Option -fwhole-program discards replaced new operator
for std::string
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
The following program fails to output the messages in the replaced allocation
operators, but *only* during the string allocation *and* when the option
`-fwhole-program` is present. (Tested on 4.6.1 and 4.4.3.) That is, the program
behaves differently when compiles with the following two commands:
g++ -std=c++0x -o prog prog.cpp
g++ -std=c++0x -o prog prog.cpp -fwhole-program
Note that the allocation used by the "map" is always done correctly.
Program code:
#include <new>
#include <string>
#include <iostream>
#include <cstdlib>
#include <map>
void * operator new(std::size_t n) throw(std::bad_alloc)
{
void * const p = std::malloc(n);
if (p == NULL) throw std::bad_alloc();
std::cerr << "new() requests " << n << " bytes, allocated at " << p << ".\n";
return p;
}
void operator delete(void * p) throw()
{
std::cerr << "delete() at " << p << ".\n";
std::free(p);
}
int main()
{
std::string s = "Hello World.";
std::map<int, int> m { { 0, 1 } };
return s.length();
}