public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13220] New: Cannot overload local operator new and include <iostream>
@ 2003-11-28 18:29 tom at storagematrix dot com
  2003-11-28 19:17 ` [Bug c++/13220] " pinskia at gcc dot gnu dot org
  2003-11-28 20:38 ` gdr at integrable-solutions dot net
  0 siblings, 2 replies; 3+ messages in thread
From: tom at storagematrix dot com @ 2003-11-28 18:29 UTC (permalink / raw)
  To: gcc-bugs

A conflict exists between a module local overload of operator new and the 
definition of operator new that gets dragged in by <iostream>.  The following 
code fails to compile.  

The problem is caused by headers pulled in by <iostream> which can be verified 
by commenting out the include of <iostream>.

---- sample2.cpp ----
#include <stdlib.h>
#include <iostream>
//
static void* operator new(size_t size) { malloc(size); }
static void operator delete(void* p) { free(p); }
static void* operator new[](size_t size) { malloc(size); }
static void operator delete[](void* p) { free(p); }

int  main(){ return 0; }
---- EOF ----

How-To-Repeat:
$ g++ sample2.cpp -o sample
sample2.cpp: In function `void* operator new(unsigned int)':
sample2.cpp:4: error: `void* operator new(unsigned int)' was declared `extern'
   and later `static'
/usr/local/gcc-3.3.2/include/c++/3.3.2/new:82: error: previous declaration of `
   void* operator new(unsigned int)'
sample2.cpp: In function `void operator delete(void*)':
sample2.cpp:5: error: `void operator delete(void*)' was declared `extern' and
   later `static'
/usr/local/gcc-3.3.2/include/c++/3.3.2/new:84: error: previous declaration of `
   void operator delete(void*)'
...,etc.

Workaround:
The problem can be worked around by moving the include of <iostream> until 
after the code that overloads operator new and new[].  This won't work if the 
overloaded methods need to use <iostream>, however.

-- 
           Summary: Cannot overload local operator new and include
                    <iostream>
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tom at storagematrix dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13220


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

* [Bug c++/13220] Cannot overload local operator new and include <iostream>
  2003-11-28 18:29 [Bug c++/13220] New: Cannot overload local operator new and include <iostream> tom at storagematrix dot com
@ 2003-11-28 19:17 ` pinskia at gcc dot gnu dot org
  2003-11-28 20:38 ` gdr at integrable-solutions dot net
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-11-28 19:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-11-28 19:17 -------
The header "iostream" pulls in the header "new" which according to c++ standard (18.4) defines 
the functions as extern so this is not a bug in gcc.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13220


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

* [Bug c++/13220] Cannot overload local operator new and include <iostream>
  2003-11-28 18:29 [Bug c++/13220] New: Cannot overload local operator new and include <iostream> tom at storagematrix dot com
  2003-11-28 19:17 ` [Bug c++/13220] " pinskia at gcc dot gnu dot org
@ 2003-11-28 20:38 ` gdr at integrable-solutions dot net
  1 sibling, 0 replies; 3+ messages in thread
From: gdr at integrable-solutions dot net @ 2003-11-28 20:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From gdr at integrable-solutions dot net  2003-11-28 20:38 -------
Subject: Re:  New: Cannot overload local operator new and include <iostream>

"tom at storagematrix dot com" <gcc-bugzilla@gcc.gnu.org> writes:

| A conflict exists between a module local overload of operator new
| and the definition of operator new that gets dragged in by
| <iostream>.  The following code fails to compile.  

And that is to be expected.  Put differently, your program makes
unspoken assumptions.
More specifically, the C++ standard allows any standard header 
(not inherited from C) to include any other standard header.

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13220


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

end of thread, other threads:[~2003-11-28 20:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-28 18:29 [Bug c++/13220] New: Cannot overload local operator new and include <iostream> tom at storagematrix dot com
2003-11-28 19:17 ` [Bug c++/13220] " pinskia at gcc dot gnu dot org
2003-11-28 20:38 ` gdr at integrable-solutions dot net

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).