public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/50594] New: Option -fwhole-program discards replaced new operator for std::string
@ 2011-10-02 22:54 z0sh at sogetthis dot com
  2011-10-02 23:03 ` [Bug c++/50594] " pinskia at gcc dot gnu.org
                   ` (24 more replies)
  0 siblings, 25 replies; 26+ messages in thread
From: z0sh at sogetthis dot com @ 2011-10-02 22:54 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: z0sh@sogetthis.com


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();
}


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2012-03-12 16:32 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-02 22:54 [Bug c++/50594] New: Option -fwhole-program discards replaced new operator for std::string z0sh at sogetthis dot com
2011-10-02 23:03 ` [Bug c++/50594] " pinskia at gcc dot gnu.org
2011-10-02 23:08 ` paolo.carlini at oracle dot com
2011-10-02 23:33 ` z0sh at sogetthis dot com
2011-10-02 23:41 ` paolo.carlini at oracle dot com
2011-10-03 13:18 ` daniel.kruegler at googlemail dot com
2011-10-03 13:23 ` paolo.carlini at oracle dot com
2011-10-03 13:42 ` redi at gcc dot gnu.org
2011-10-03 13:44 ` redi at gcc dot gnu.org
2011-10-03 13:46 ` paolo.carlini at oracle dot com
2011-10-03 13:49 ` daniel.kruegler at googlemail dot com
2011-10-03 15:04 ` redi at gcc dot gnu.org
2011-10-03 15:13 ` paolo.carlini at oracle dot com
2011-10-03 16:12 ` z0sh at sogetthis dot com
2011-10-04  9:27 ` rguenth at gcc dot gnu.org
2011-10-04  9:37 ` paolo.carlini at oracle dot com
2011-10-04  9:55 ` redi at gcc dot gnu.org
2011-10-04 10:06 ` rguenther at suse dot de
2011-10-04 10:12 ` redi at gcc dot gnu.org
2011-10-04 12:00 ` z0sh at sogetthis dot com
2011-10-04 18:38 ` jason at gcc dot gnu.org
2011-10-11 23:30 ` paolo.carlini at oracle dot com
2011-10-11 23:40 ` paolo.carlini at oracle dot com
2011-10-12 18:41 ` paolo at gcc dot gnu.org
2011-10-12 18:43 ` paolo.carlini at oracle dot com
2012-03-12 16:32 ` fang at csl dot cornell.edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).