- To: Mark Mitchell <mark at codesourcery dot com>
- Subject: Re: Putting builtins in the std namespace
- From: benjamin kosnik <bkoz at nabi dot net>
- Date: Wed, 18 Oct 2000 15:08:21 -0700
- CC: gcc-patches at gcc dot gnu dot org, jason at cygnus dot com
- References: <20001018094312Q.mitchell@codesourcery.com>
- Reply-To: bkoz at nabi dot net
> Benjamin requested that I work on putting builtins (like `abs') in the
> `std' namespace in C++ (when -fhonor-std is in use) since the
> libstdc++ people need that for some work they're doing.
Hey Mark, thanks for paying attention to my plea.
> Here's a first cut. This patch doesn't move builtins whose names
> start with a `_' since those are already reserved names, and since I
> bet a lot of macros depend on them.
don't worry about those.
> The following simple program worked:
>
> namespace std {
> int abs (int);
> }
>
> int main ()
> {
> return std::abs (-3);
> }
Err. Yeah.
As Phil noted, this change has hosed v-3 builds, which I'm sure is a just a simple mix up on
your part.
The real problem that I was trying to solve was with a v-3 build (which, as Phil also noted,
turns on -fhonor-std by default and which is the reason we would like it fully operational)
is the following:
(line 55 of libsupc++/new)
// replaceable signatures
void *operator new (size_t) throw (std::bad_alloc);
Note this line no longer compiles with your change.
I'm trying to get this to work so that I can change the above line to:
void *operator new (std::size_t) throw (std::bad_alloc);
Which, I'm sure you'll agree, is a truly-C++ standard-compliant signature. (see 18.4)
Seems simple enough. However, it's a bit more complicated than that., because the C++ type
for size_t has to match the extern "C" size_t type. (Long, complicated analysis of this is
on www.cantrip.org/cheaders.html) The libstdc++-v3 attempt to deal with this is
--enable-cshadow-headers, which uses include/c_std instead of the default include/c
directory to correctly wrap the "C" library headers for use with the C+ library for cFOO
type headers (ie ctype.h -> cctype, FOO == ctype)
Anyway. Perhaps more detail that you cared about.
The end result is that both of these cases have to compile, when using -fhonor-std,
hopefully with one <new> header.
#if 1
// stddef.h
extern "C" {typedef unsigned int size_t ;}
#else
// cstddef
namespace _C_legacy {
extern "C" {
typedef unsigned int size_t;
}
} // namespace _C_legacy
namespace std {
using _C_legacy::size_t;
} // namespace std
#endif
void *operator new (std::size_t) throw (std::bad_alloc);
I hope this makes the problem I was trying to solve a bit easier to grasp.
thanks again,
benjamin