Patchwork C++ conversion - pull in cstdlib

login
register
mail settings
Submitter Oleg Endo
Date Aug. 25, 2012, 9:59 p.m.
Message ID <1345931981.2398.27.camel@yam-132-YW-E178-FTW>
Download mbox | patch
Permalink /patch/179989/
State New
Headers show

Comments

Oleg Endo - Aug. 25, 2012, 9:59 p.m.
Hello,

This one makes system.h pull in <cstdlib> when compiling as C++.
It fixes issues when e.g. including <algorithm>.
Tested on my SH cross compiler config with 'make all-gcc', after
including the following std headers in one of the RTL passes:
<algorithm> <limits> <bitset> <cassert> <cctype> <cerrno> <cfloat>
<climits> <clocale> <cmath> <complex> <csetjmp> <csignal> <cstdarg>
<cstddef> <cstdio> <cstdlib> <cstring> <ctime> <deque>e <exception>
<fstream> <functional> <iomanip> <ios> <iosfwd> <iostream> <istream>
<iterator> <limits> <list> <locale> <map> <memory> <new>e <numeric>
<ostream> <queue> <set> <sstream> <stack> <stdexcept> <strstream>
<streambuf> <string> <typeinfo> <utility> <valarray> <vector>.

My host GCC is:
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --enable-objc-gc
--enable-targets=all --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=i686-linux-gnu
--host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

Cheers,
Oleg

ChangeLog:

	* system.h: Include <cstdlib> instead of <stdlib.h> when
	compiling as C++.
Oleg Endo - Sept. 1, 2012, 1:43 p.m.
Ping!

This allows one to include e.g. <algorithm> in GCC source files.
Since the switch to C++ has been made, this should be OK to do now, I
guess.

Cheers,
Oleg

On Sat, 2012-08-25 at 23:59 +0200, Oleg Endo wrote:
> Hello,
> 
> This one makes system.h pull in <cstdlib> when compiling as C++.
> It fixes issues when e.g. including <algorithm>.
> Tested on my SH cross compiler config with 'make all-gcc', after
> including the following std headers in one of the RTL passes:
> <algorithm> <limits> <bitset> <cassert> <cctype> <cerrno> <cfloat>
> <climits> <clocale> <cmath> <complex> <csetjmp> <csignal> <cstdarg>
> <cstddef> <cstdio> <cstdlib> <cstring> <ctime> <deque>e <exception>
> <fstream> <functional> <iomanip> <ios> <iosfwd> <iostream> <istream>
> <iterator> <limits> <list> <locale> <map> <memory> <new>e <numeric>
> <ostream> <queue> <set> <sstream> <stack> <stdexcept> <strstream>
> <streambuf> <string> <typeinfo> <utility> <valarray> <vector>.
> 
> My host GCC is:
> gcc -v
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
> Target: i686-linux-gnu
> Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
> 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
> --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
> --program-suffix=-4.6 --enable-shared --enable-linker-build-id
> --with-system-zlib --libexecdir=/usr/lib --without-included-gettext
> --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
> --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
> --enable-libstdcxx-debug --enable-libstdcxx-time=yes
> --enable-gnu-unique-object --enable-plugin --enable-objc-gc
> --enable-targets=all --disable-werror --with-arch-32=i686
> --with-tune=generic --enable-checking=release --build=i686-linux-gnu
> --host=i686-linux-gnu --target=i686-linux-gnu
> Thread model: posix
> gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
> 
> Cheers,
> Oleg
> 
> ChangeLog:
> 
> 	* system.h: Include <cstdlib> instead of <stdlib.h> when
> 	compiling as C++.
Joseph S. Myers - Sept. 1, 2012, 4:17 p.m.
On Sat, 1 Sep 2012, Oleg Endo wrote:

> Ping!
> 
> This allows one to include e.g. <algorithm> in GCC source files.
> Since the switch to C++ has been made, this should be OK to do now, I
> guess.

This is not a review, but have you tested building the Ada front end with 
this patch applied?  Given recent issues relating to how Ada uses 
system.h, I think any such changes need testing for Ada.
Oleg Endo - Sept. 1, 2012, 4:25 p.m.
On Sat, 2012-09-01 at 16:17 +0000, Joseph S. Myers wrote:
> On Sat, 1 Sep 2012, Oleg Endo wrote:
> 
> > Ping!
> > 
> > This allows one to include e.g. <algorithm> in GCC source files.
> > Since the switch to C++ has been made, this should be OK to do now, I
> > guess.
> 
> This is not a review, but have you tested building the Ada front end with 
> this patch applied?  Given recent issues relating to how Ada uses 
> system.h, I think any such changes need testing for Ada.
> 

No I haven't. C and C++ only. Good to know, thanks.  Will try.

Cheers,
Oleg
Oleg Endo - Sept. 1, 2012, 11:19 p.m.
On Sat, 2012-09-01 at 18:25 +0200, Oleg Endo wrote:
> On Sat, 2012-09-01 at 16:17 +0000, Joseph S. Myers wrote:
> > On Sat, 1 Sep 2012, Oleg Endo wrote:
> > 
> > > Ping!
> > > 
> > > This allows one to include e.g. <algorithm> in GCC source files.
> > > Since the switch to C++ has been made, this should be OK to do now, I
> > > guess.
> > 
> > This is not a review, but have you tested building the Ada front end with 
> > this patch applied?  Given recent issues relating to how Ada uses 
> > system.h, I think any such changes need testing for Ada.
> > 
> 
> No I haven't. C and C++ only. Good to know, thanks.  Will try.
> 

OK, now I have. ada, c, c++, fortran, go, java, objc, obj-c++ do build
here.

Cheers,
Oleg
Oleg Endo - Sept. 12, 2012, 10:10 p.m.
Hello,

On Sun, 2012-09-02 at 01:19 +0200, Oleg Endo wrote:
> On Sat, 2012-09-01 at 18:25 +0200, Oleg Endo wrote:
> > On Sat, 2012-09-01 at 16:17 +0000, Joseph S. Myers wrote:
> > > On Sat, 1 Sep 2012, Oleg Endo wrote:
> > > 
> > > > Ping!
> > > > 
> > > > This allows one to include e.g. <algorithm> in GCC source files.
> > > > Since the switch to C++ has been made, this should be OK to do now, I
> > > > guess.
> > > 
> > > This is not a review, but have you tested building the Ada front end with 
> > > this patch applied?  Given recent issues relating to how Ada uses 
> > > system.h, I think any such changes need testing for Ada.
> > > 
> > 
> > No I haven't. C and C++ only. Good to know, thanks.  Will try.
> > 
> 
> OK, now I have. ada, c, c++, fortran, go, java, objc, obj-c++ do build
> here.
> 

Would it be OK to install the patch originally posted here:
http://gcc.gnu.org/ml/gcc-patches/2012-08/msg01761.html ?

If not OK, it's also fine.  Just let me know.  It seems the issue can be
worked around in individual source files by including <cstdlib> before
"system.h" (as it is already done in config/sh/sh.c).

Cheers,
Oleg
Richard Guenther - Sept. 13, 2012, 11:36 a.m.
On Thu, Sep 13, 2012 at 12:10 AM, Oleg Endo <oleg.endo@t-online.de> wrote:
> Hello,
>
> On Sun, 2012-09-02 at 01:19 +0200, Oleg Endo wrote:
>> On Sat, 2012-09-01 at 18:25 +0200, Oleg Endo wrote:
>> > On Sat, 2012-09-01 at 16:17 +0000, Joseph S. Myers wrote:
>> > > On Sat, 1 Sep 2012, Oleg Endo wrote:
>> > >
>> > > > Ping!
>> > > >
>> > > > This allows one to include e.g. <algorithm> in GCC source files.
>> > > > Since the switch to C++ has been made, this should be OK to do now, I
>> > > > guess.
>> > >
>> > > This is not a review, but have you tested building the Ada front end with
>> > > this patch applied?  Given recent issues relating to how Ada uses
>> > > system.h, I think any such changes need testing for Ada.
>> > >
>> >
>> > No I haven't. C and C++ only. Good to know, thanks.  Will try.
>> >
>>
>> OK, now I have. ada, c, c++, fortran, go, java, objc, obj-c++ do build
>> here.
>>
>
> Would it be OK to install the patch originally posted here:
> http://gcc.gnu.org/ml/gcc-patches/2012-08/msg01761.html ?
>
> If not OK, it's also fine.  Just let me know.  It seems the issue can be
> worked around in individual source files by including <cstdlib> before
> "system.h" (as it is already done in config/sh/sh.c).

In general system headers should be exclusively included from system.h.
As C++ standard headers may pull in system headers that includes them.
This is to allow various workarounds for host compiler / OS issues in a
central place as well as not affecting those headers with the #poisonings
we do at the end of system.h.

Richard.

> Cheers,
> Oleg
>
>
>

Patch

Index: gcc/system.h
===================================================================
--- gcc/system.h	(revision 190665)
+++ gcc/system.h	(working copy)
@@ -224,8 +224,12 @@ 
 # endif
 #endif
 
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
+#ifdef __cplusplus
+# include <cstdlib>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
 #endif
 
 /* If we don't have an overriding definition, set SUCCESS_EXIT_CODE and