This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gets with C++ and GCC before 4.7


GCC (4.7 and later) now has a fix for libstdc++ expecting the gets
declaration, but older GCC is still broken with current stdio.h.  I
propose this patch to enable the gets declaration for C++ with GCC
versions before 4.7, even with __USE_GNU, which I think is the best
practical solution for working well with existing releases of GCC.
Tested x86_64.

2012-03-05  Joseph Myers  <joseph@codesourcery.com>

	[BZ #13566]
	* libio/stdio.h (gets): Also declare for C++ with GCC before 4.7.

diff --git a/libio/stdio.h b/libio/stdio.h
index c69b382..afac433 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -623,7 +623,8 @@ extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
      __wur;
 
 #if !defined __USE_ISOC11 \
-    || (defined __cplusplus && __cplusplus <= 201103L && !defined __USE_GNU)
+    || (defined __cplusplus && __cplusplus <= 201103L \
+	&& (!defined __USE_GNU || (defined __GNUC__ && !__GNUC_PREREQ (4, 7))))
 /* Get a newline-terminated string from stdin, removing the newline.
    DO NOT USE THIS FUNCTION!!  There is no limit on how much it will read.
 
@@ -631,7 +632,9 @@ extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
    is used to also remove it from the GNU feature list.  It is now only
    available when explicitly using an old ISO C, Unix, or POSIX standard.
    GCC defines _GNU_SOURCE when building C++ code and the function is still
-   in C++11, so it is also available for C++.
+   in C++11, and GCC versions before 4.7 are not prepared for the
+   declaration to be missing from stdio.h, so it is also available for
+   C++ with older compilers.
 
    This function is a possible cancellation point and therefore not
    marked with __THROW.  */

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]