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]

[patch] libstdc++/69626 Test for C99 stdlib.h functions with -std=c++98


When r230324 split the GLIBCXX_ENABLE_C99 configure checks to test
everything twice, once with -std=gnu++98 and once with -std=gnu++11,
we failed to check the stdlib.h functions with gnu++98. As a result
_GLIBCXX98_USE_C99_STDLIB was never defined, and so various C99
functions disappeared from namespace std in c++98 mode.

This adds the missing checks back, so those functions are added to
namespace std again.

The new test only runs on *-*-linux-gnu because we can't run it
everywhere, as some targets don't support the functions in C++98 mode
and so correctly don't define _GLIBCXX98_USE_C99_STDLIB. Some other
targets such as freebsd and dragonfly override
_GLIBCXX98_USE_C99_STDLIB in os_defines.h so were unaffected anyway.

Tested powerpc64-linux, committed to trunk.

commit 9e58b6517b5886357b6bfce328dd8bd2b89497f9
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Feb 4 21:48:39 2016 +0000

    Test for C99 stdlib.h functions with -std=c++98
    
    	PR libstdc++/69626
    	* acinclude.m4 (GLIBCXX_ENABLE_C99): Check C99 stdlib.h functions
    	with -std=c++98 and define _GLIBCXX98_USE_C99_STDLIB.
    	* config.h.in: Regenerate.
    	* configure: Regenerate.
    	* testsuite/21_strings/c_strings/char/69626.cc: New.

diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
index 2d06670..057b58e 100644
--- a/libstdc++-v3/acinclude.m4
+++ b/libstdc++-v3/acinclude.m4
@@ -1059,6 +1059,35 @@ AC_DEFUN([GLIBCXX_ENABLE_C99], [
         in <cstdio> in namespace std for C++98.])
     fi
 
+    # Check for the existence in <stdlib.h> of lldiv_t, et. al.
+    AC_MSG_CHECKING([for ISO C99 support in <stdlib.h> for C++98])
+    AC_CACHE_VAL(glibcxx_cv_c99_stdlib_cxx98, [
+      GCC_TRY_COMPILE_OR_LINK(
+        [#include <stdlib.h>
+         volatile float f;
+         volatile long double ld;
+         volatile unsigned long long ll;
+         lldiv_t mydivt;],
+        [char* tmp;
+         f = strtof("gnu", &tmp);
+         ld = strtold("gnu", &tmp);
+         ll = strtoll("gnu", &tmp, 10);
+         ll = strtoull("gnu", &tmp, 10);
+         ll = llabs(10);
+         mydivt = lldiv(10,1);
+         ll = mydivt.quot;
+         ll = mydivt.rem;
+         ll = atoll("10");
+         _Exit(0);
+        ], [glibcxx_cv_c99_stdlib_cxx98=yes], [glibcxx_cv_c99_stdlib_cxx98=no])
+    ])
+    AC_MSG_RESULT($glibcxx_cv_c99_stdlib_cxx98)
+    if test x"$glibcxx_cv_c99_stdlib_cxx98" = x"yes"; then
+      AC_DEFINE(_GLIBCXX98_USE_C99_STDLIB, 1,
+        [Define if C99 functions or macros in <stdlib.h> should be imported
+        in <cstdlib> in namespace std for C++98.])
+    fi
+
     # Check for the existence in <wchar.h> of wcstold, etc.
     if test x"$ac_has_wchar_h" = xyes &&
        test x"$ac_has_wctype_h" = xyes; then
diff --git a/libstdc++-v3/testsuite/21_strings/c_strings/char/69626.cc b/libstdc++-v3/testsuite/21_strings/c_strings/char/69626.cc
new file mode 100644
index 0000000..be3cdb3
--- /dev/null
+++ b/libstdc++-v3/testsuite/21_strings/c_strings/char/69626.cc
@@ -0,0 +1,27 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++98" }
+// { dg-do compile { target *-*-linux-gnu } }
+
+#include <cstdlib>
+
+long long test01()
+{
+  char* ep;
+  return std::strtoll("0", &ep, 10);
+}

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