This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[fixincludes, v3] Enable full ISO C99 support for C++ on Solaris 10+
- From: Rainer Orth <ro at CeBiTec dot Uni-Bielefeld dot DE>
- To: gcc-patches at gcc dot gnu dot org
- Cc: libstdc++ at gcc dot gnu dot org, Bruce Korb <bkorb at gnu dot org>
- Date: Tue, 18 May 2010 00:25:59 +0200
- Subject: [fixincludes, v3] Enable full ISO C99 support for C++ on Solaris 10+
While checking libstdc++ configure results on Solaris 11, I noticed that
C99 support wasn't enabled because various tests failed:
/* #undef _GLIBCXX_USE_C99_COMPLEX */
config.log has
conftest.cpp:44:15: error: 'cabsf' was not declared in this scope
The declaration is wrapped in #if !defined(__cplusplus) in <complex.h>,
so we need to fixinclude this.
/* #undef _GLIBCXX_USE_C99_COMPLEX_TR1 */
conftest.cpp:65:25: error: 'cacosf' was not declared in this scope
Same problem.
/* #undef _GLIBCXX_USE_C99_MATH */
conftest.cpp:35:18: error: 'fpclassify' was not declared in this scope
Wrapped in
#if defined(_STDC_C99) || _XOPEN_SOURCE - 0 >= 600 || defined(__C99FEATURES__)
So we need -D_XOPEN_SOURCE=600, while currently config/sol2.h
(TARGET_OS_CPP_BUILTINS) has this:
if (c_dialect_cxx ()) \
{ \
builtin_define ("_XOPEN_SOURCE=500"); \
builtin_define ("_LARGEFILE_SOURCE=1"); \
builtin_define ("_LARGEFILE64_SOURCE=1"); \
builtin_define ("__EXTENSIONS__"); \
} \
/* #undef _GLIBCXX_USE_C99_MATH_TR1 */
conftest.cpp:118:22: error: 'llrint' was not declared in this scope
Wrapped in
#if !defined(_STRICT_STDC) && !defined(_NO_LONGLONG) || defined(_STDC_C99) || \
defined(__C99FEATURES__)
So in addition to the fixincludes stuff in <complex.h>, we need to
update the _XOPEN_SOURCE definition, which doesn't work without
__STDC_VERSION__=199901L.
To make this work, we need another fixincludes change: currently,
<sys/feature_tests.h> has
#if (defined(__STDC__) && defined(_STDC_C99))
#define _RESTRICT_KYWD restrict
#else
#define _RESTRICT_KYWD
#endif
In order to make this work with C++, we need to define _RESTRICT_KYWD as
__restrict for __cplusplus.
With those changes, all C99 features in libstdc++ become enabled.
Tested on i386-pc-solaris2.11 with clean g++ and libstdc++-v3, with
three exceptions:
FAIL: 26_numerics/headers/cmath/c99_classification_macros_c.cc (test for excess errors)
Excess errors:
/vol/gcc/src/hg/trunk/solaris/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc:40:16: error: macro "isgreater" requires 2 arguments, but only 1 given
<iso/math_c99.h> has
#undef isgreater
#define isgreater(x, y) __builtin_isgreater(x, y)
which conflicts with
void isgreater() { }
A similar problem seems to exist on other platforms, so I'm adding
*-*-solaris2* to dg-xfail-if and dg-excess-errors.
This leaves us with two real new failures (the tests didn't run before):
FAIL: 30_threads/future/members/wait.cc (test for excess errors)
WARNING: 30_threads/future/members/wait.cc compilation failed to produce executable
Excess errors:
/vol/gcc/src/hg/trunk/solaris/libstdc++-v3/testsuite/30_threads/future/members/wait.cc:44:36: error: no matching function for call to 'std::thread::thread(<unresolved overloaded function type>, std::reference_wrapper<std::future<void> >)'
/vol/gcc/obj/gcc-4.6.0-20100430/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/thread:129:5: note: candidates are: std::thread::thread(std::thread&&)
/vol/gcc/obj/gcc-4.6.0-20100430/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/thread:126:5: note: std::thread::thread()
<thread> is guarded by _GLIBCXX_HAS_GTHREADS &&
_GLIBCXX_USE_C99_STDINT_TR1, so this test wasn't run before. I've no
idea how/where to fix this.
FAIL: 30_threads/shared_future/members/wait.cc (test for excess errors)
WARNING: 30_threads/shared_future/members/wait.cc compilation failed to produce executable
Similar error.
Once it's clear how to deal with those two testsuite failures, ok for
mainline? Before committing, I'll test at least on sparc-sun-solaris2.9
and perhaps sparc-sun-solaris2.8 to make sure this doesn't break older
releases.
I'm not sure this is appropriate for the 4.5 branch, though I suppose it
is. 4.4 is probably out of bounds for such a change, though.
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
2010-05-01 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
gcc:
* config/sol2.h (TARGET_OS_CPP_BUILTINS): Define
__STDC_VERSION__=199901L, _XOPEN_SOURCE=600 for C++.
fixincludes:
* inclhack.def (solaris__restrict, solaris_complex_cxx): New fixes
* fixincl.x: Regenerate.
* tests/base/complex.h [SOLARIS_COMPLEX_CXX_CHECK]: New test.
* tests/base/sys/feature_tests.h: New file.
libstdc++-v3:
* testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc:
Add *-*-solaris2* to dg-xfail-if, dg-excess-errors.
diff -r f70b3bf2d230 fixincludes/inclhack.def
--- a/fixincludes/inclhack.def Sat May 08 18:02:09 2010 +0200
+++ b/fixincludes/inclhack.def Sat May 08 18:17:43 2010 +0200
@@ -3249,6 +3249,23 @@
/*
+ * Solaris 10+ <sys/feature_tests.h> defines _RESTRICT_KYWD as restrict
+ * for C99. This is wrong for C++, which needs many C99 features, but
+ * only supports __restrict.
+ */
+fix = {
+ hackname = solaris___restrict;
+ files = sys/feature_tests.h;
+ select = "#define[ \t]*_RESTRICT_KYWD[ \t]*restrict";
+ mach = "*-*-solaris2*";
+ c_fix = format;
+ c_fix_arg = "#ifdef __cplusplus\n#define\t_RESTRICT_KYWD\t__restrict\n"
+ "#else\n%0\n#endif";
+ test_text = "#define _RESTRICT_KYWD restrict";
+};
+
+
+/*
* Solaris 10+ complex.h defines _Complex_I and _Imaginary_I in terms of
* themselves, which are Sun Studio compiler intrinsics. Remove _Imaginary_I
* and imaginary definitions which are not supported by GCC.
@@ -3273,6 +3290,23 @@
/*
+ * Solaris 10+ <complex.h> is wrapped in #ifndef __cplusplus. Wrap in
+ * extern "C" instead so libstdc++ can use it.
+ */
+fix = {
+ hackname = solaris_complex_cxx;
+ mach = "*-*-solaris2.*";
+ files = complex.h;
+ sed = "/#if[ \t]*!defined(__cplusplus)/c"
+ "#ifdef\t__cplusplus\\\nextern \"C\" {\\\n#endif";
+ sed = "/#endif[ \t]*\\/\\* !defined(__cplusplus) \\*\\//c"
+ "#ifdef\t__cplusplus\\\n}\\\n#endif";
+ test_text = "#if !defined(__cplusplus)\n"
+ "#endif /* !defined(__cplusplus) */";
+};
+
+
+/*
* Sun Solaris 10 defines several C99 math macros in terms of
* builtins specific to the Studio compiler, in particular not
* compatible with the GNU compiler.
diff -r f70b3bf2d230 fixincludes/tests/base/complex.h
--- a/fixincludes/tests/base/complex.h Sat May 08 18:02:09 2010 +0200
+++ b/fixincludes/tests/base/complex.h Sat May 08 18:17:43 2010 +0200
@@ -33,3 +33,13 @@
#undef I
#define I _Complex_I
#endif /* SOLARIS_COMPLEX_CHECK */
+
+
+#if defined( SOLARIS_COMPLEX_CXX_CHECK )
+#ifdef __cplusplus
+extern "C" {
+#endif
+#ifdef __cplusplus
+}
+#endif
+#endif /* SOLARIS_COMPLEX_CXX_CHECK */
diff -r f70b3bf2d230 fixincludes/tests/base/sys/feature_tests.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fixincludes/tests/base/sys/feature_tests.h Sat May 08 18:17:43 2010 +0200
@@ -0,0 +1,18 @@
+/* DO NOT EDIT THIS FILE.
+
+ It has been auto-edited by fixincludes from:
+
+ "fixinc/tests/inc/sys/feature_tests.h"
+
+ This had to be done to correct non-standard usages in the
+ original, manufacturer supplied header file. */
+
+
+
+#if defined( SOLARIS___RESTRICT_CHECK )
+#ifdef __cplusplus
+#define _RESTRICT_KYWD __restrict
+#else
+#define _RESTRICT_KYWD restrict
+#endif
+#endif /* SOLARIS___RESTRICT_CHECK */
diff -r f70b3bf2d230 gcc/config/sol2.h
--- a/gcc/config/sol2.h Sat May 08 18:02:09 2010 +0200
+++ b/gcc/config/sol2.h Sat May 08 18:17:43 2010 +0200
@@ -99,7 +99,8 @@
library. */ \
if (c_dialect_cxx ()) \
{ \
- builtin_define ("_XOPEN_SOURCE=500"); \
+ builtin_define ("__STDC_VERSION__=199901L");\
+ builtin_define ("_XOPEN_SOURCE=600"); \
builtin_define ("_LARGEFILE_SOURCE=1"); \
builtin_define ("_LARGEFILE64_SOURCE=1"); \
builtin_define ("__EXTENSIONS__"); \
diff -r f70b3bf2d230 libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc
--- a/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc Sat May 08 18:02:09 2010 +0200
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/c99_classification_macros_c.cc Sat May 08 18:17:43 2010 +0200
@@ -20,8 +20,8 @@
// { dg-do compile }
// { dg-add-options no_pch }
-// { dg-xfail-if "" { { *-*-linux* *-*-darwin* hppa*-*-hpux* } || { uclibc || newlib } } { "*" } { "" } }
-// { dg-excess-errors "" { target { { *-*-linux* *-*-darwin* hppa*-*-hpux* } || { uclibc || newlib } } } }
+// { dg-xfail-if "" { { *-*-linux* *-*-darwin* *-*-solaris2* hppa*-*-hpux* } || { uclibc || newlib } } { "*" } { "" } }
+// { dg-excess-errors "" { target { { *-*-linux* *-*-darwin* *-*-solaris2* hppa*-*-hpux* } || { uclibc || newlib } } } }
#include <math.h>