This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

3.4 PATCH: Properly check for lrand48 in libstdc++-v3


Looking into mips-sgi-irix6.5o32 testsuite failures compared to the basic
mips-sgi-irix6.5 configuration, I noticed several of the following:

FAIL: g++.dg/init/array4.C (test for excess errors)
Excess errors:
In file included from /var/tmp/gcc-obj/gcc-3.4-20030807/6.5o32-cc-gas/mips-sgi-irix6.5o32/libstdc++-v3/include/algorithm:69,
                 from /var/tmp/gcc-obj/gcc-3.4-20030807/6.5o32-cc-gas/mips-sgi-irix6.5o32/libstdc++-v3/include/string:56,
                 from /.vol/gcc/src/gcc-dist/gcc/testsuite/g++.dg/init/array4.C:8:
/var/tmp/gcc-obj/gcc-3.4-20030807/6.5o32-cc-gas/mips-sgi-irix6.5o32/libstdc++-v3/include/bits/stl_algo.h:1616: error: there are no arguments to `lrand48' that depend on a template parameter, so a declaration of `lrand48' must be available
/var/tmp/gcc-obj/gcc-3.4-20030807/6.5o32-cc-gas/mips-sgi-irix6.5o32/libstdc++-v3/include/bits/stl_algo.h:1616: error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)

While in the end I found that this happens because the IRIX 6 configuration
predefines __EXTENSIONS__ and _SGI_SOURCE even with -ansi to make the
lrand48 declaration visible, the following patch still seems useful: 

* While configure checks for drand48, the result is used to decide if
  lrand48 is present.  This is plain wrong.

* It was only tested if drand48 exists at link time, but a declaration test
  is also needed.

* Even though this new declaration test may succeed, the testsuite may
  still produce the failures above, since there g++ -ansi is run, which may
  hide declarations present without -ansi.  This part is not fixed by this
  patch.

Bootstrapped without regressions on mips-sgi-irix6.5o32.

Ok for mainline?

	Rainer

-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University


Fri Aug  8 00:00:31 2003  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>

	* linkage.m4 (GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_0): Define.
	(GLIBCXX_CHECK_STDLIB_SUPPORT): Use it to test for lrand48
	instead of drand48.
	* acconfig.h (HAVE_DRAND48): Renamed to HAVE_LRAND48.
	* crossconfig.m4 (*-freebsd*): Define HAVE_LRAND48 instead of
	HAVE_DRAND48.
	* config.h.in, configure: Regenerate.
	* include/bits/stl_algo.h: Use _GLIBCXX_HAVE_LRAND48 to guard
	lrand48 use.

Index: libstdc++-v3/acconfig.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/acconfig.h,v
retrieving revision 1.32
diff -u -p -r1.32 acconfig.h
--- libstdc++-v3/acconfig.h	5 Aug 2003 02:00:02 -0000	1.32
+++ libstdc++-v3/acconfig.h	25 Sep 2003 15:12:20 -0000
@@ -63,8 +63,8 @@
 // Define if gthr-default.h exists (meaning that threading support is enabled).
 #undef HAVE_GTHR_DEFAULT
 
-// Define if drand48 exists.
-#undef HAVE_DRAND48
+// Define if lrand48 exists.
+#undef HAVE_LRAND48
 
 // Define if getpagesize exists.
 #undef HAVE_GETPAGESIZE
Index: libstdc++-v3/crossconfig.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/crossconfig.m4,v
retrieving revision 1.2
diff -u -p -r1.2 crossconfig.m4
--- libstdc++-v3/crossconfig.m4	20 Aug 2003 03:32:00 -0000	1.2
+++ libstdc++-v3/crossconfig.m4	25 Sep 2003 15:12:24 -0000
@@ -54,7 +54,7 @@ case "${host}" in
     GLIBCXX_CHECK_COMPLEX_MATH_SUPPORT
     GLIBCXX_CHECK_WCHAR_T_SUPPORT
     AC_DEFINE(HAVE_LC_MESSAGES)
-    AC_DEFINE(HAVE_DRAND48)
+    AC_DEFINE(HAVE_LRAND48)
     AC_DEFINE(HAVE_GETPAGESIZE)
     AC_DEFINE(HAVE_SETENV)
     AC_DEFINE(HAVE_SIGSETJMP)
Index: libstdc++-v3/linkage.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/linkage.m4,v
retrieving revision 1.2
diff -u -p -r1.2 linkage.m4
--- libstdc++-v3/linkage.m4	17 Aug 2003 20:23:06 -0000	1.2
+++ libstdc++-v3/linkage.m4	25 Sep 2003 15:12:24 -0000
@@ -173,6 +173,35 @@ dnl 2) has "C" linkage
 dnl
 dnl argument 1 is name of function to check
 dnl
+dnl ASSUMES argument is a stdlib function without parameters
+dnl
+dnl GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_0
+AC_DEFUN(GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_0, [
+  AC_MSG_CHECKING([for $1 declaration])
+  if test x${glibcxx_cv_func_$1_use+set} != xset; then
+    AC_CACHE_VAL(glibcxx_cv_func_$1_use, [
+      AC_LANG_SAVE
+      AC_LANG_CPLUSPLUS
+      AC_TRY_COMPILE([#include <stdlib.h>],
+                     [ $1();],
+                     [glibcxx_cv_func_$1_use=yes], [glibcxx_cv_func_$1_use=no])
+      AC_LANG_RESTORE
+    ])
+  fi
+  AC_MSG_RESULT($glibcxx_cv_func_$1_use)
+  if test x$glibcxx_cv_func_$1_use = x"yes"; then
+    AC_CHECK_FUNCS($1)
+  fi
+])
+
+
+dnl
+dnl Check to see if the (stdlib function) argument passed is
+dnl 1) declared when using the c++ compiler
+dnl 2) has "C" linkage
+dnl
+dnl argument 1 is name of function to check
+dnl
 dnl ASSUMES argument is a math function with TWO parameters
 dnl
 dnl GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2
@@ -342,7 +371,7 @@ dnl This might seem like overkill but ex
 dnl
 dnl Define HAVE_STRTOLD if "strtold" is declared and links
 dnl Define HAVE_STRTOF if "strtof" is declared and links
-dnl Define HAVE_DRAND48 if "drand48" is declared and links
+dnl Define HAVE_LRAND48 if "lrand48" is declared and links
 dnl
 dnl GLIBCXX_CHECK_STDLIB_SUPPORT
 AC_DEFUN(GLIBCXX_CHECK_STDLIB_SUPPORT, [
@@ -352,7 +381,7 @@ AC_DEFUN(GLIBCXX_CHECK_STDLIB_SUPPORT, [
 
   GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2(strtold)
   GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2(strtof)
-  AC_CHECK_FUNCS(drand48)
+  GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_0(lrand48)
 
   CXXFLAGS="$ac_save_CXXFLAGS"
 ])
Index: libstdc++-v3/include/bits/stl_algo.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_algo.h,v
retrieving revision 1.35
diff -u -p -r1.35 stl_algo.h
--- libstdc++-v3/include/bits/stl_algo.h	15 Jul 2003 07:30:19 -0000	1.35
+++ libstdc++-v3/include/bits/stl_algo.h	25 Sep 2003 15:12:49 -0000
@@ -1612,7 +1612,7 @@ namespace std
     inline _Distance
     __random_number(_Distance __n)
     {
-  #ifdef _GLIBCXX_HAVE_DRAND48
+  #ifdef _GLIBCXX_HAVE_LRAND48
       return lrand48() % __n;
   #else
       return rand() % __n;


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