From 1814157e886b0f7050ae3a70024b3856dd8d58e4 Mon Sep 17 00:00:00 2001
From: Paolo Carlini <paolo.carlini@oracle.com>
Date: Wed, 6 Aug 2008 23:17:05 +0000
Subject: [PATCH] acinclude.m4 ([GLIBCXX_CHECK_STDIO_MACROS]): New, checks for
 common values of EOF, SEEK_CUR, SEEK_END.

2008-08-06  Paolo Carlini  <paolo.carlini@oracle.com>

	* acinclude.m4 ([GLIBCXX_CHECK_STDIO_MACROS]): New, checks for
	common values of EOF, SEEK_CUR, SEEK_END.
	* configure.ac: Use it.
	* include/bits/ios_base.h: Likewise.
	* include/bits/char_traits.h: Likewise.
	* config/locale/gnu/ctype_members.cc: Include <cstdio>.
	* config/locale/generic/ctype_members.cc: Likewise.
	* testsuite/27_io/ios_base/cons/assign_neg.cc: Adjust dg-error lines.
	* testsuite/27_io/ios_base/cons/copy_neg.cc: Likewise.
	* configure: Regenerate.
	* config.h.in: Likewise.

From-SVN: r138829
---
 libstdc++-v3/ChangeLog                        | 16 ++++-
 libstdc++-v3/acinclude.m4                     | 23 ++++++
 libstdc++-v3/config.h.in                      |  3 +
 .../config/locale/generic/ctype_members.cc    |  3 +-
 .../config/locale/gnu/ctype_members.cc        |  3 +-
 libstdc++-v3/configure                        | 72 +++++++++++++++++++
 libstdc++-v3/configure.ac                     |  3 +
 libstdc++-v3/include/bits/char_traits.h       | 14 ++--
 libstdc++-v3/include/bits/ios_base.h          | 14 +++-
 .../27_io/ios_base/cons/assign_neg.cc         |  2 +-
 .../testsuite/27_io/ios_base/cons/copy_neg.cc |  2 +-
 11 files changed, 143 insertions(+), 12 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 8d81860ee749..2a4e4adfa314 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,4 +1,18 @@
-008-08-06  Paolo Carlini  <paolo.carlini@oracle.com>
+2008-08-06  Paolo Carlini  <paolo.carlini@oracle.com>
+
+	* acinclude.m4 ([GLIBCXX_CHECK_STDIO_MACROS]): New, checks for
+	common values of EOF, SEEK_CUR, SEEK_END.
+	* configure.ac: Use it.
+	* include/bits/ios_base.h: Likewise.
+	* include/bits/char_traits.h: Likewise.
+	* config/locale/gnu/ctype_members.cc: Include <cstdio>.
+	* config/locale/generic/ctype_members.cc: Likewise.
+	* testsuite/27_io/ios_base/cons/assign_neg.cc: Adjust dg-error lines.
+	* testsuite/27_io/ios_base/cons/copy_neg.cc: Likewise.
+	* configure: Regenerate.
+	* config.h.in: Likewise.
+
+2008-08-06  Paolo Carlini  <paolo.carlini@oracle.com>
 
 	* acinclude.m4 ([GLIBCXX_CHECK_INT64_T]): Also check whether int64_t
 	is actually a typedef to long or long long.
diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 50f207c23826..3197682df8ff 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -1460,6 +1460,29 @@ AC_DEFUN([GLIBCXX_CHECK_RANDOM_TR1], [
 
 ])
 
+dnl
+dnl Check whether EOF, SEEK_CUR, and SEEK_END have the most common values:
+dnl in that case including <cstdio> in some C++ headers can be avoided.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_STDIO_MACROS], [
+
+  AC_MSG_CHECKING([for EOF == -1, SEEK_CUR == 1, SEEK_END == 2])
+  AC_CACHE_VAL(glibcxx_cv_stdio_macros, [
+  AC_TRY_COMPILE([#include <stdio.h>],
+                 [#if ((EOF != -1) || (SEEK_CUR != 1) || (SEEK_END != 2))
+	            unusual values...
+	          #endif
+	         ], [glibcxx_cv_stdio_macros=yes],
+		    [glibcxx_cv_stdio_macros=no])
+  ])
+  AC_MSG_RESULT($glibcxx_cv_stdio_macros)
+  if test x"$glibcxx_cv_stdio_macros" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_STDIO_MACROS, 1,
+              [Define if EOF == -1, SEEK_CUR == 1, SEEK_END == 2.])
+  fi
+
+])
+
 dnl
 dnl Check whether macros, etc are present for <system_error>
 dnl
diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in
index 438fe1488c47..b4cb3f3b5c7a 100644
--- a/libstdc++-v3/config.h.in
+++ b/libstdc++-v3/config.h.in
@@ -767,6 +767,9 @@
 /* Define if the compiler is configured for setjmp/longjmp exceptions. */
 #undef _GLIBCXX_SJLJ_EXCEPTIONS
 
+/* Define if EOF == -1, SEEK_CUR == 1, SEEK_END == 2. */
+#undef _GLIBCXX_STDIO_MACROS
+
 /* Define to use symbol versioning in the shared library. */
 #undef _GLIBCXX_SYMVER
 
diff --git a/libstdc++-v3/config/locale/generic/ctype_members.cc b/libstdc++-v3/config/locale/generic/ctype_members.cc
index ae1c7cf1d0fd..6b4fbd7ea7d9 100644
--- a/libstdc++-v3/config/locale/generic/ctype_members.cc
+++ b/libstdc++-v3/config/locale/generic/ctype_members.cc
@@ -1,6 +1,6 @@
 // std::ctype implementation details, generic version -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -37,6 +37,7 @@
 #include <locale>
 #include <cstdlib>
 #include <cstring>
+#include <cstdio>
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
diff --git a/libstdc++-v3/config/locale/gnu/ctype_members.cc b/libstdc++-v3/config/locale/gnu/ctype_members.cc
index 3aec312f89b3..9e5176059142 100644
--- a/libstdc++-v3/config/locale/gnu/ctype_members.cc
+++ b/libstdc++-v3/config/locale/gnu/ctype_members.cc
@@ -1,6 +1,6 @@
 // std::ctype implementation details, GNU version -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -35,6 +35,7 @@
 // Written by Benjamin Kosnik <bkoz@redhat.com>
 
 #include <locale>
+#include <cstdio>
 #include <bits/c++locale_internal.h>
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 5fb310780a64..fd776092e1f9 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -41812,6 +41812,78 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
+  #
+
+
+  echo "$as_me:$LINENO: checking for EOF == -1, SEEK_CUR == 1, SEEK_END == 2" >&5
+echo $ECHO_N "checking for EOF == -1, SEEK_CUR == 1, SEEK_END == 2... $ECHO_C" >&6
+  if test "${glibcxx_cv_stdio_macros+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <stdio.h>
+int
+main ()
+{
+#if ((EOF != -1) || (SEEK_CUR != 1) || (SEEK_END != 2))
+	            unusual values...
+	          #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  glibcxx_cv_stdio_macros=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+glibcxx_cv_stdio_macros=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+
+  echo "$as_me:$LINENO: result: $glibcxx_cv_stdio_macros" >&5
+echo "${ECHO_T}$glibcxx_cv_stdio_macros" >&6
+  if test x"$glibcxx_cv_stdio_macros" = x"yes"; then
+
+cat >>confdefs.h <<\_ACEOF
+#define _GLIBCXX_STDIO_MACROS 1
+_ACEOF
+
+  fi
+
+
+
   # For TLS support.
 
    # Check whether --enable-tls or --disable-tls was given.
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index b23e17714dd2..6f530b3faa4f 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -167,6 +167,9 @@ if $GLIBCXX_IS_NATIVE; then
   # For gettimeofday support.
   GLIBCXX_CHECK_GETTIMEOFDAY
 
+  #
+  GLIBCXX_CHECK_STDIO_MACROS
+
   # For TLS support.
   GCC_CHECK_TLS
 
diff --git a/libstdc++-v3/include/bits/char_traits.h b/libstdc++-v3/include/bits/char_traits.h
index ae0f6cfbe092..85e4167758e1 100644
--- a/libstdc++-v3/include/bits/char_traits.h
+++ b/libstdc++-v3/include/bits/char_traits.h
@@ -1,7 +1,7 @@
 // Character Traits for use by standard string and iostream -*- C++ -*-
 
 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007
+// 2006, 2007, 2008
 // Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
@@ -45,9 +45,15 @@
 
 #include <bits/stl_algobase.h>  // std::copy, std::fill_n
 #include <bits/postypes.h>      // For streampos
-#include <cstdio>               // For EOF
 #include <cwchar>               // For WEOF, wmemmove, wmemset, etc.
 
+#ifndef _GLIBCXX_STDIO_MACROS
+# include <cstdio>              // For EOF
+# define _CHAR_TRAITS_EOF EOF
+#else
+# define _CHAR_TRAITS_EOF (-1)
+#endif
+
 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
 
   /**
@@ -138,7 +144,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
 
       static int_type
       eof()
-      { return static_cast<int_type>(EOF); }
+      { return static_cast<int_type>(_CHAR_TRAITS_EOF); }
 
       static int_type
       not_eof(const int_type& __c)
@@ -292,7 +298,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       { return __c1 == __c2; }
 
       static int_type
-      eof() { return static_cast<int_type>(EOF); }
+      eof() { return static_cast<int_type>(_CHAR_TRAITS_EOF); }
 
       static int_type
       not_eof(const int_type& __c)
diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h
index 95a3d2b91042..8b55028c537c 100644
--- a/libstdc++-v3/include/bits/ios_base.h
+++ b/libstdc++-v3/include/bits/ios_base.h
@@ -46,7 +46,15 @@
 #include <ext/atomicity.h>
 #include <bits/localefwd.h>
 #include <bits/locale_classes.h>
-#include <cstdio>  // For SEEK_CUR, SEEK_END
+
+#ifndef _GLIBCXX_STDIO_MACROS
+# include <cstdio>   // For SEEK_CUR, SEEK_END
+# define _IOS_BASE_SEEK_CUR SEEK_CUR
+# define _IOS_BASE_SEEK_END SEEK_END
+#else
+# define _IOS_BASE_SEEK_CUR 1
+# define _IOS_BASE_SEEK_END 2
+#endif
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
@@ -186,8 +194,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
   enum _Ios_Seekdir 
     { 
       _S_beg = 0,
-      _S_cur = SEEK_CUR,
-      _S_end = SEEK_END,
+      _S_cur = _IOS_BASE_SEEK_CUR,
+      _S_end = _IOS_BASE_SEEK_END,
       _S_ios_seekdir_end = 1L << 16 
     };
 
diff --git a/libstdc++-v3/testsuite/27_io/ios_base/cons/assign_neg.cc b/libstdc++-v3/testsuite/27_io/ios_base/cons/assign_neg.cc
index 5325523a0cca..7df9d4633436 100644
--- a/libstdc++-v3/testsuite/27_io/ios_base/cons/assign_neg.cc
+++ b/libstdc++-v3/testsuite/27_io/ios_base/cons/assign_neg.cc
@@ -43,5 +43,5 @@ void test01()
 }
 // { dg-error "synthesized" "" { target *-*-* } 42 } 
 // { dg-error "within this context" "" { target *-*-* } 35 } 
-// { dg-error "is private" "" { target *-*-* } 786 } 
+// { dg-error "is private" "" { target *-*-* } 794 } 
 // { dg-error "operator=" "" { target *-*-* } 0 } 
diff --git a/libstdc++-v3/testsuite/27_io/ios_base/cons/copy_neg.cc b/libstdc++-v3/testsuite/27_io/ios_base/cons/copy_neg.cc
index 536682eb6f33..8f17ac6b884d 100644
--- a/libstdc++-v3/testsuite/27_io/ios_base/cons/copy_neg.cc
+++ b/libstdc++-v3/testsuite/27_io/ios_base/cons/copy_neg.cc
@@ -43,5 +43,5 @@ void test02()
 }
 // { dg-error "within this context" "" { target *-*-* } 36 } 
 // { dg-error "synthesized" "" { target *-*-* } 42 } 
-// { dg-error "is private" "" { target *-*-* } 783 } 
+// { dg-error "is private" "" { target *-*-* } 791 } 
 // { dg-error "copy constructor" "" { target *-*-* } 0 } 
-- 
GitLab