diff mbox

[fixincludes] Only declare gets for C++ < 2014 on Solaris (PR libstdc++/78979)

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

Commit Message

Rainer Orth Jan. 12, 2017, 10:41 a.m. UTC
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

> While investigating PR libstdc++/78979, it turns out that Solaris

> <stdio.h> incorrectly declares std::gets even for C++14 where it's been

> removed.  This patch fixes that by adding an additional __cplusplus <

> 201402L guard via fixincludes.  This works for Solaris 12 (and 11), but

> Solaris 10 declares the function unconditionally (i.e. without the

> __STDC_VERSION__ < 201112L guard and the deprecated attribute), so

> another fix adds both to handle that version, too.  With this in place,

> the std::gets declaration in <stdio.h> needs a guard, too.

>

> While testing this patch together with

>

> 	https://gcc.gnu.org/ml/gcc-patches/2017-01/msg00288.html

>

> it turned out another fix is needed which I'm throwing in here, too:

>

> <iso/stdlib_c99.h> declares

>

> #if defined(_STDC_C11)

> extern _Noreturn void quick_exit(int);

> #else

> extern void quick_exit(int) __NORETURN;

> #endif  /* _STDC_C11 */

>

> and the first one now breaks badly with __STDC_VERSION__ defined to the

> C11 value:

>

> /usr/include/iso/stdlib_c99.h:83:8: error: '_Noreturn' does not name a type

>  extern _Noreturn void quick_exit(int);

>         ^~~~~~~~~

>

> To avoid this, I've changed to C11-only _Noreturn to

> __attribute__((__noreturn__)).

>

> Bootstrapped without regressions on i386-pc-solaris2.1[02] and

> sparc-sun-solaris2.12 and fixing

>

> FAIL: 27_io/headers/cstdio/functions_neg.cc  (test for errors, line 24)

>

> as designed.  fixincludes make check, passes, too.

>

> Ok for mainline now?  I'd like to backport the patch to the gcc-5 and

> gcc-6 branches which are equally affected.


I just noticed that the submitted patch lacked the _Noreturn part
described above.  Here it is.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
diff mbox

Patch

# HG changeset patch
# Parent  8b946d3b0b1ff1d40660db201feee5925260f9ee
Only declare gets for C++ < 2014 on Solaris (PR libstdc++/78979)

diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def
--- a/fixincludes/inclhack.def
+++ b/fixincludes/inclhack.def
@@ -3593,6 +3593,43 @@  fix = {
 };
 
 /*
+ *  Solaris <iso/stdio_iso.h> should deprecate gets before C11.
+ */
+fix = {
+    hackname  = solaris_gets_c11;
+    mach      = "*-*-solaris2*";
+    files     = "iso/stdio_iso.h";
+    select    = "(extern char[ \t]*\\*gets\\(char \\*\\));";
+
+    c_fix     = format;
+    c_fix_arg = "#if __STDC_VERSION__ < 201112L && __cplusplus < 201402L\n"
+    		"%1 __attribute__((__deprecated__));\n"
+		"#endif";
+
+    test_text = "extern char	*gets(char *);";
+};
+
+/*
+ *  Solaris <iso/stdio_iso.h> shouldn't declare gets for C++14.
+ */
+fix = {
+    hackname  = solaris_gets_cxx14;
+    mach      = "*-*-solaris2*";
+    files     = "iso/stdio_iso.h";
+    select    = <<- _EOSelect_
+(#if __STDC_VERSION__ < 201112L)
+(extern char	\*gets\(char \*\) __ATTR_DEPRECATED;)
+_EOSelect_;
+    c_fix     = format;
+    c_fix_arg = "%1 && __cplusplus < 201402L\n%2";
+
+    test_text = <<- _EOText_
+#if __STDC_VERSION__ < 201112L
+extern char	*gets(char *) __ATTR_DEPRECATED;
+_EOText_;
+};
+
+/*
  * Sun Solaris 2 has a version of sys/int_const.h that defines
  * UINT8_C and UINT16_C to unsigned constants.
  */
@@ -3982,6 +4019,21 @@  fix = {
 };
 
 /*
+ *  Solaris <stdio.h> shouldn't use std::gets for C++14.
+ */
+fix = {
+    hackname  = solaris_std_gets_cxx14;
+    mach      = "*-*-solaris2*";
+    files     = "stdio.h";
+    select    = "using std::gets;";
+
+    c_fix     = format;
+    c_fix_arg = "#if __cplusplus < 201402L\n%0\n#endif";
+
+    test_text = "using std::gets;";
+};
+
+/*
  * 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.
@@ -4000,6 +4052,21 @@  fix = {
 };
 
 /*
+ *  Solaris <stdlib.h> shouldn't use _Noreturn, breaks with C++.
+ */
+fix = {
+    hackname  = solaris_stdlib_noreturn;
+    mach      = "*-*-solaris2*";
+    files     = "iso/stdlib_c99.h";
+    select    = "(extern) _Noreturn (void quick_exit\\(int\\));";
+
+    c_fix     = format;
+    c_fix_arg = "%1 %2 __attribute__((__noreturn__));";
+
+    test_text = "extern _Noreturn void quick_exit(int);";
+};
+
+/*
  *  a missing semi-colon at the end of the statsswtch structure definition.
  */
 fix = {
diff --git a/fixincludes/tests/base/iso/stdio_iso.h b/fixincludes/tests/base/iso/stdio_iso.h
--- a/fixincludes/tests/base/iso/stdio_iso.h
+++ b/fixincludes/tests/base/iso/stdio_iso.h
@@ -12,3 +12,16 @@ 
 #if defined( SOLARIS_GETC_STRICT_STDC_CHECK )
 #if	!defined(_REENTRANT) && !defined(_LP64) && (!defined(_STRICT_STDC) || (__cplusplus >= 199711L))
 #endif  /* SOLARIS_GETC_STRICT_STDC_CHECK */
+
+
+#if defined( SOLARIS_GETS_C11_CHECK )
+#if __STDC_VERSION__ < 201112L && __cplusplus < 201402L
+extern char	*gets(char *) __attribute__((__deprecated__));
+#endif
+#endif  /* SOLARIS_GETS_C11_CHECK */
+
+
+#if defined( SOLARIS_GETS_CXX14_CHECK )
+#if __STDC_VERSION__ < 201112L && __cplusplus < 201402L
+extern char	*gets(char *) __ATTR_DEPRECATED;
+#endif  /* SOLARIS_GETS_CXX14_CHECK */
diff --git a/fixincludes/tests/base/iso/stdlib_c99.h b/fixincludes/tests/base/iso/stdlib_c99.h
new file mode 100644
--- /dev/null
+++ b/fixincludes/tests/base/iso/stdlib_c99.h
@@ -0,0 +1,14 @@ 
+/*  DO NOT EDIT THIS FILE.
+
+    It has been auto-edited by fixincludes from:
+
+	"fixinc/tests/inc/iso/stdlib_c99.h"
+
+    This had to be done to correct non-standard usages in the
+    original, manufacturer supplied header file.  */
+
+
+
+#if defined( SOLARIS_STDLIB_NORETURN_CHECK )
+extern void quick_exit(int) __attribute__((__noreturn__));
+#endif  /* SOLARIS_STDLIB_NORETURN_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
@@ -90,6 +90,13 @@  using std::__flsbuf;
 #endif  /* SOLARIS_STD___FILBUF_CHECK */
 
 
+#if defined( SOLARIS_STD_GETS_CXX14_CHECK )
+#if __cplusplus < 201402L
+using std::gets;
+#endif
+#endif  /* SOLARIS_STD_GETS_CXX14_CHECK */
+
+
 #if defined( STDIO_STDARG_H_CHECK )
 
 #endif  /* STDIO_STDARG_H_CHECK */