diff mbox

[fixincludes] Allow properly defining __cplusplus with Solaris headers (PR libstdc++-v3/1773)

Message ID yddbovzq64h.fsf@manam.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth Aug. 9, 2011, 9:35 a.m. UTC
Work is currently underway to finally fix

PR libstdc++-v3/1773	__cplusplus defined to 1, should be 199711L

which hadn't been handled before because libstdc++ couldn't cope with
the (partial) C++ overloads in Solaris headers.  I started with Marc's
patches from the PR (thanks!), cleaned them up a bit (improving
comments, using actual header snippets as testcases, adding tests) and
had to add two more fixes for issues found during Solaris 8 and 9
testing.

The fixes avoid the following issues:

* <iso/stdlib_iso.h> has both C and C++ prototypes for bsearch and
  qsort, which g++ doesn't accept (PR c++/2316), so they are disabled if
  __GNUG__.

* <iso/stdio_iso.h> uses getc, but may not declare it in some
  circumstances for C++.

* On Solaris 8 and 9, longjmp isn't declared noreturn in
  <iso/setjmp_iso.h>, which breaks fortran compilation:

/vol/gcc/src/hg/trunk/solaris/gcc/fortran/parse.c: In function 'void unexpected_eof()':
/vol/gcc/src/hg/trunk/solaris/gcc/fortran/parse.c:1871:1: error: 'noreturn' function does return [-Werror]

  so add the attribute.

* <iso/math_iso.h> has pow({float, double, long double}, int) overloads
  which were removed in C++ 2011 and libstdc++ cannot deal with that, so
  make them conditional.

* On Solaris 8 and 9, __filbuf and flsbuf are used in <iso/stdio_iso.h>,
  but are missing from namespace std:

/vol/gcc/src/hg/trunk/solaris/libcpp/files.c: In function 'void _cpp_report_missing_guards(cpp_reader*)':
/vol/gcc/src/hg/trunk/solaris/libcpp/files.c:1311:4: error: '__flsbuf' was not declared in this scope
/vol/gcc/src/hg/trunk/solaris/libcpp/files.c:1311:4: note: suggested alternative:
/var/gcc/gcc-4.7.0-20110805/9-gcc-gas/./prev-gcc/include-fixed/iso/stdio_iso.h:232:12: note:   'std::__flsbuf'
/vol/gcc/src/hg/trunk/solaris/libcpp/files.c: In function 'char* read_filename_string(int, std::FILE*)':
/vol/gcc/src/hg/trunk/solaris/libcpp/files.c:1435:20: error: '__filbuf' was not declared in this scope
/vol/gcc/src/hg/trunk/solaris/libcpp/files.c:1435:20: note: suggested alternative:

  So add them back as on Solaris 10 and up.

With those fixes (and a few companion ones already posted or about to be
posted), I've successfully bootstrapped on i386-pc-solaris2.{8, 9, 10,
10} with __cplusplus=199711L, no regressions.

Ok for mainline (no point in backporting to release branches since this
will never be used)?

Thanks.
	Rainer


2011-08-07  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
	    Marc Glisse  <marc.glisse@normalesup.org>

	PR libstdc++-v3/1773
	* inclhack.def (solaris_cxx_linkage, solaris_getc_strict_stdc)
	(solaris_longjmp_noreturn, solaris_pow_int_overload)
	(solaris_std___filbuf): New fixes.
	* tests/base/iso/math_iso.h, tests/base/iso/setjmp_iso.h,
	tests/base/iso/stdio_iso.h, tests/base/iso/stdlib_iso.h: New tests.
	* tests/base/stdio.h [SOLARIS_STD___FILBUF_CHECK]: New test.

Comments

Bruce Korb Aug. 9, 2011, 12:51 p.m. UTC | #1
On Tue, Aug 9, 2011 at 2:35 AM, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
> Ok for mainline (no point in backporting to release branches since this
> will never be used)?

Hi Rainer,

"never be used"?  OK.  Looks good to me.  Cheers - Bruce
Rainer Orth Aug. 9, 2011, 1 p.m. UTC | #2
Hi Bruce,

> On Tue, Aug 9, 2011 at 2:35 AM, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote:
>> Ok for mainline (no point in backporting to release branches since this
>> will never be used)?
>
> Hi Rainer,
>
> "never be used"?  OK.  Looks good to me.  Cheers - Bruce

I doubt anyone would consider backporting the change in __cplusplus
definition to 4.6 :-)

Thanks.
        Rainer
diff mbox

Patch

diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def
--- a/fixincludes/inclhack.def
+++ b/fixincludes/inclhack.def
@@ -3358,6 +3358,59 @@  fix = {
 
 
 /*
+ *  g++ rejects functions declared with both C and C++ linkage.
+ */
+fix = {
+    hackname  = solaris_cxx_linkage;
+    mach      = '*-*-solaris2*';
+    files     = "iso/stdlib_iso.h";
+    select    = "(#if __cplusplus >= 199711L)\n"
+	        "(extern \"C\\+\\+\" \\{\n)"
+	        "(.*(bsearch|qsort).*)";
+    c_fix     = format;
+    c_fix_arg = "%1 && !__GNUG__\n%2%3";
+
+    test_text =
+    "#if __cplusplus >= 199711L\n"
+    "extern \"C++\" {\n"
+    "	void *bsearch(const void *, const void *, size_t, size_t,";
+};
+
+
+/*
+ *  Solaris <iso/stdio_iso.h> doesn't declare getc for C++ with
+ *  _STRICT_STDC, but uses it.
+ */
+fix = {
+    hackname  = solaris_getc_strict_stdc;
+    mach      = "*-*-solaris2*";
+    files     = "iso/stdio_iso.h";
+    select    = "(.*&& )!defined\\(_STRICT_STDC\\)(.*)";
+    c_fix     = format;
+    c_fix_arg = "%1(!defined(_STRICT_STDC) || (__cplusplus >= 199711L))%2";
+
+    test_text =
+    "#if	!defined(_REENTRANT) && !defined(_LP64) && !defined(_STRICT_STDC)";
+};
+
+
+/*
+ *  Before Solaris 10, <iso/setjmp_iso.h> doesn't mark longjump noreturn.
+ */
+fix = {
+    hackname  = solaris_longjmp_noreturn;
+    mach      = "*-*-solaris2*";
+    files     = "iso/setjmp_iso.h";
+    bypass    = "__NORETURN";
+    select    = "(.*longjmp\\(jmp_buf.*[^)]+\\));";
+    c_fix     = format;
+    c_fix_arg = "%1 __attribute__ ((__noreturn__));";
+
+    test_text = "extern void longjmp(jmp_buf, int);";
+};
+
+
+/*
  * 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.
@@ -3530,6 +3583,24 @@  fix = {
 
 
 /*
+ *  The pow overloads with int were removed in C++ 2011.
+ */
+fix = {
+    hackname  = solaris_pow_int_overload;
+    mach      = '*-*-solaris2*';
+    files     = "iso/math_iso.h";
+    select    = "^[ \t]*inline [a-z ]* pow\\([^()]*, int [^()]*\\)"
+		" *\\{[^{}]*\n[^{}]*\\}";
+    c_fix     = format;
+    c_fix_arg = "#ifndef __GXX_EXPERIMENTAL_CXX0X__\n%0\n#endif";
+
+    test_text =
+    "	inline long double pow(long double __X, int __Y) { return\n"
+    "		__powl(__X, (long double) (__Y)); }";
+};
+
+
+/*
  * Sun Solaris defines PTHREAD_RWLOCK_INITIALIZER with a "0" for some
  *  fields of the pthread_rwlock_t structure, which are of type
  *  upad64_t, which itself is typedef'd to int64_t, but with __STDC__
@@ -3723,6 +3794,27 @@  fix = {
 
 
 /*
+ * Before Solaris 10, <stdio.h> lacks declarations of std::__filbuf and
+ * std::__flsbuf, but <iso/stdio_iso.h> uses them.
+ */
+fix = {
+    hackname  = solaris_std___filbuf;
+    files     = stdio.h;
+    mach      = '*-*-solaris2*';
+    bypass    = "using std::__filbuf";
+    select    = "(using std::perror;\n)(#endif)";
+    c_fix     = format;
+    c_fix_arg = "%1#ifndef _LP64\n"
+		"using std::__filbuf;\n"
+		"using std::__flsbuf;\n"
+		"#endif\n%2";
+
+    test_text = "using std::perror;\n"
+		"#endif";
+};
+
+
+/*
  * Sun Solaris 8 has what appears to be some gross workaround for
  * some old version of their c++ compiler.  G++ doesn't want it
  * either, but doesn't want to be tied to SunPRO version numbers.
@@ -4617,4 +4709,6 @@  fix = {
     test_text = "extern char *\tsprintf();";
 };
 
+
+
 /*EOF*/
diff --git a/fixincludes/tests/base/iso/math_iso.h b/fixincludes/tests/base/iso/math_iso.h
new file mode 100644
--- /dev/null
+++ b/fixincludes/tests/base/iso/math_iso.h
@@ -0,0 +1,17 @@ 
+/*  DO NOT EDIT THIS FILE.
+
+    It has been auto-edited by fixincludes from:
+
+	"fixinc/tests/inc/iso/math_iso.h"
+
+    This had to be done to correct non-standard usages in the
+    original, manufacturer supplied header file.  */
+
+
+
+#if defined( SOLARIS_POW_INT_OVERLOAD_CHECK )
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
+	inline long double pow(long double __X, int __Y) { return
+		__powl(__X, (long double) (__Y)); }
+#endif
+#endif  /* SOLARIS_POW_INT_OVERLOAD_CHECK */
diff --git a/fixincludes/tests/base/iso/setjmp_iso.h b/fixincludes/tests/base/iso/setjmp_iso.h
new file mode 100644
--- /dev/null
+++ b/fixincludes/tests/base/iso/setjmp_iso.h
@@ -0,0 +1,14 @@ 
+/*  DO NOT EDIT THIS FILE.
+
+    It has been auto-edited by fixincludes from:
+
+	"fixinc/tests/inc/iso/setjmp_iso.h"
+
+    This had to be done to correct non-standard usages in the
+    original, manufacturer supplied header file.  */
+
+
+
+#if defined( SOLARIS_LONGJMP_NORETURN_CHECK )
+extern void longjmp(jmp_buf, int) __attribute__ ((__noreturn__));
+#endif  /* SOLARIS_LONGJMP_NORETURN_CHECK */
diff --git a/fixincludes/tests/base/iso/stdio_iso.h b/fixincludes/tests/base/iso/stdio_iso.h
new file mode 100644
--- /dev/null
+++ b/fixincludes/tests/base/iso/stdio_iso.h
@@ -0,0 +1,14 @@ 
+/*  DO NOT EDIT THIS FILE.
+
+    It has been auto-edited by fixincludes from:
+
+	"fixinc/tests/inc/iso/stdio_iso.h"
+
+    This had to be done to correct non-standard usages in the
+    original, manufacturer supplied header file.  */
+
+
+
+#if defined( SOLARIS_GETC_STRICT_STDC_CHECK )
+#if	!defined(_REENTRANT) && !defined(_LP64) && (!defined(_STRICT_STDC) || (__cplusplus >= 199711L))
+#endif  /* SOLARIS_GETC_STRICT_STDC_CHECK */
diff --git a/fixincludes/tests/base/iso/stdlib_iso.h b/fixincludes/tests/base/iso/stdlib_iso.h
new file mode 100644
--- /dev/null
+++ b/fixincludes/tests/base/iso/stdlib_iso.h
@@ -0,0 +1,16 @@ 
+/*  DO NOT EDIT THIS FILE.
+
+    It has been auto-edited by fixincludes from:
+
+	"fixinc/tests/inc/iso/stdlib_iso.h"
+
+    This had to be done to correct non-standard usages in the
+    original, manufacturer supplied header file.  */
+
+
+
+#if defined( SOLARIS_CXX_LINKAGE_CHECK )
+#if __cplusplus >= 199711L && !__GNUG__
+extern "C++" {
+	void *bsearch(const void *, const void *, size_t, size_t,
+#endif  /* SOLARIS_CXX_LINKAGE_CHECK */
diff --git a/fixincludes/tests/base/stdio.h b/fixincludes/tests/base/stdio.h
--- a/fixincludes/tests/base/stdio.h
+++ b/fixincludes/tests/base/stdio.h
@@ -65,6 +65,16 @@  extern int rename(const char *_old, cons
 #endif  /* RS6000_PARAM_CHECK */
 
 
+#if defined( SOLARIS_STD___FILBUF_CHECK )
+using std::perror;
+#ifndef _LP64
+using std::__filbuf;
+using std::__flsbuf;
+#endif
+#endif
+#endif  /* SOLARIS_STD___FILBUF_CHECK */
+
+
 #if defined( STDIO_STDARG_H_CHECK )
 
 #endif  /* STDIO_STDARG_H_CHECK */