This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] tr1/c_compatibility, cinttypes
- From: Paolo Carlini <pcarlini at suse dot de>
- To: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 30 Jan 2006 15:20:39 +0100
- Subject: [v3] tr1/c_compatibility, cinttypes
Hi,
tested x86-linux, committed to mainline.
Paolo.
//////////////////////
2006-01-30 Paolo Carlini <pcarlini@suse.de>
* include/tr1/cinttypes: New.
* include/Makefile.am: Add.
* testsuite/tr1/8_c_compatibility/cinttypes/functions: New.
* testsuite/tr1/8_c_compatibility/cinttypes/types: Likewise.
* acinclude.m4 ([GLIBCXX_CHECK_C99_TR1]): Add <inttypes.h> checks.
* docs/html/ext/tr1.html: Update.
* include/Makefile.in: Regenerate.
* config.h.in: Likewise.
* configure: Likewise.
* testsuite/tr1/8_c_compatibility/cfenv/functions.cc: Cosmetic tweak.
* testsuite/tr1/8_c_compatibility/cfenv/types.cc: Likewise.
* testsuite/tr1/8_c_compatibility/cstdint/types.cc: Fix, check in
std::tr1.
Index: include/tr1/cinttypes
===================================================================
--- include/tr1/cinttypes (revision 0)
+++ include/tr1/cinttypes (revision 0)
@@ -0,0 +1,83 @@
+// TR1 cinttypes -*- C++ -*-
+
+// Copyright (C) 2006 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 2, 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 COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/** @file
+ * This is a TR1 C++ Library header.
+ */
+
+#ifndef _TR1_CINTTYPES
+#define _TR1_CINTTYPES 1
+
+#include <bits/c++config.h>
+
+#include <tr1/cstdint>
+
+#if _GLIBCXX_HAVE_INTTYPES_H
+// For 8.11.1/1 (see C99, Note 184)
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#endif
+
+#if _GLIBCXX_USE_C99_INTTYPES_TR1
+
+// namespace std::tr1
+namespace std
+{
+_GLIBCXX_BEGIN_NAMESPACE(tr1)
+
+ // types
+ using ::imaxdiv_t;
+
+ // functions
+ using ::imaxabs;
+
+ inline intmax_t
+ abs(intmax_t __i)
+ { return imaxabs(__i); }
+
+ using ::imaxdiv;
+
+ inline imaxdiv_t
+ div(intmax_t __numer, intmax_t __denom)
+ { return imaxdiv(__numer, __denom); }
+
+ using ::strtoimax;
+ using ::strtoumax;
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ using ::wcstoimax;
+ using ::wcstoumax;
+#endif
+
+_GLIBCXX_END_NAMESPACE
+}
+
+#endif
+
+#endif
Index: include/Makefile.am
===================================================================
--- include/Makefile.am (revision 110378)
+++ include/Makefile.am (working copy)
@@ -486,6 +486,7 @@
${tr1_srcdir}/boost_shared_ptr.h \
${tr1_srcdir}/cctype \
${tr1_srcdir}/cfenv \
+ ${tr1_srcdir}/cinttypes \
${tr1_srcdir}/common.h \
${tr1_srcdir}/complex \
${tr1_srcdir}/cstdint \
Index: docs/html/ext/tr1.html
===================================================================
--- docs/html/ext/tr1.html (revision 110378)
+++ docs/html/ext/tr1.html (working copy)
@@ -1907,25 +1907,25 @@
<tr>
<td>8.11</td>
<td>Header <code><cinttypes></code></td>
+ <td>done</td>
<td></td>
<td></td>
- <td>missing</td>
<td></td>
</tr>
<tr>
<td>8.11.1</td>
<td>Synopsis</td>
+ <td>done</td>
<td></td>
<td></td>
- <td>missing</td>
<td></td>
</tr>
<tr>
<td>8.11.2</td>
<td>Definitions</td>
+ <td>done</td>
<td></td>
<td></td>
- <td>missing</td>
<td></td>
</tr>
<tr>
Index: testsuite/tr1/8_c_compatibility/cfenv/types.cc
===================================================================
--- testsuite/tr1/8_c_compatibility/cfenv/types.cc (revision 110378)
+++ testsuite/tr1/8_c_compatibility/cfenv/types.cc (working copy)
@@ -28,9 +28,8 @@
{
#if _GLIBCXX_USE_C99_FENV_TR1
- // Check for required typedefs
- typedef std::tr1::fenv_t my_fenv_t;
- typedef std::tr1::fexcept_t my_fexcept_t;
+ typedef std::tr1::fenv_t my_fenv_t;
+ typedef std::tr1::fexcept_t my_fexcept_t;
#endif
}
Index: testsuite/tr1/8_c_compatibility/cfenv/functions.cc
===================================================================
--- testsuite/tr1/8_c_compatibility/cfenv/functions.cc (revision 110377)
+++ testsuite/tr1/8_c_compatibility/cfenv/functions.cc (working copy)
@@ -32,21 +32,21 @@
std::tr1::fexcept_t* pflag = 0;
std::tr1::fenv_t* penv = 0;
- int r;
+ int ret;
- r = std::tr1::feclearexcept(except);
- r = std::tr1::fegetexceptflag(pflag, except);
- r = std::tr1::feraiseexcept(except);
- r = std::tr1::fesetexceptflag(pflag, except);
- r = std::tr1::fetestexcept(except);
+ ret = std::tr1::feclearexcept(except);
+ ret = std::tr1::fegetexceptflag(pflag, except);
+ ret = std::tr1::feraiseexcept(except);
+ ret = std::tr1::fesetexceptflag(pflag, except);
+ ret = std::tr1::fetestexcept(except);
- r = std::tr1::fegetround();
- r = std::tr1::fesetround(mode);
+ ret = std::tr1::fegetround();
+ ret = std::tr1::fesetround(mode);
- r = std::tr1::fegetenv(penv);
- r = std::tr1::feholdexcept(penv);
- r = std::tr1::fesetenv(penv);
- r = std::tr1::feupdateenv(penv);
+ ret = std::tr1::fegetenv(penv);
+ ret = std::tr1::feholdexcept(penv);
+ ret = std::tr1::fesetenv(penv);
+ ret = std::tr1::feupdateenv(penv);
#endif
}
Index: testsuite/tr1/8_c_compatibility/cinttypes/types.cc
===================================================================
--- testsuite/tr1/8_c_compatibility/cinttypes/types.cc (revision 0)
+++ testsuite/tr1/8_c_compatibility/cinttypes/types.cc (revision 0)
@@ -0,0 +1,34 @@
+// { dg-do compile }
+
+// 2006-01-30 Paolo Carlini <pcarlini@suse.de>
+//
+// Copyright (C) 2006 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 2, 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 COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 8.11 Header <cinttypes>
+
+#include <tr1/cinttypes>
+
+void test01()
+{
+#if _GLIBCXX_USE_C99_INTTYPES_TR1
+
+ typedef std::tr1::imaxdiv_t my_imaxdiv_t;
+
+#endif
+}
Index: testsuite/tr1/8_c_compatibility/cinttypes/functions.cc
===================================================================
--- testsuite/tr1/8_c_compatibility/cinttypes/functions.cc (revision 0)
+++ testsuite/tr1/8_c_compatibility/cinttypes/functions.cc (revision 0)
@@ -0,0 +1,58 @@
+// { dg-do compile }
+
+// 2006-01-30 Paolo Carlini <pcarlini@suse.de>
+//
+// Copyright (C) 2006 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 2, 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 COPYING. If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 8.11 Header <cinttypes>
+
+#include <tr1/cinttypes>
+
+void test01()
+{
+#if _GLIBCXX_USE_C99_INTTYPES_TR1
+
+ std::tr1::intmax_t i = 0, numer = 0, denom = 0, base = 0;
+ const char* s = 0;
+ char** endptr = 0;
+#ifdef _GLIBCXX_USE_WCHAR_T
+ const wchar_t* ws = 0;
+ wchar_t** wendptr = 0;
+#endif
+
+ std::tr1::intmax_t ret;
+ std::tr1::uintmax_t uret;
+ std::tr1::imaxdiv_t dret;
+
+ ret = std::tr1::imaxabs(i);
+ ret = std::tr1::abs(i);
+
+ dret = std::tr1::imaxdiv(numer, denom);
+ dret = std::tr1::div(numer, denom);
+
+ ret = std::tr1::strtoimax(s, endptr, base);
+ uret = std::tr1::strtoumax(s, endptr, base);
+
+#ifdef _GLIBCXX_USE_WCHAR_T
+ ret = std::tr1::wcstoimax(ws, wendptr, base);
+ uret = std::tr1::wcstoumax(ws, wendptr, base);
+#endif
+
+#endif
+}
Index: testsuite/tr1/8_c_compatibility/cstdint/types.cc
===================================================================
--- testsuite/tr1/8_c_compatibility/cstdint/types.cc (revision 110378)
+++ testsuite/tr1/8_c_compatibility/cstdint/types.cc (working copy)
@@ -28,34 +28,34 @@
{
#if _GLIBCXX_USE_C99_STDINT_TR1
- typedef int8_t my_int8_t;
- typedef int16_t my_int16_t;
- typedef int32_t my_int32_t;
- typedef int64_t my_int64_t;
- typedef int_fast8_t my_int_fast8_t;
- typedef int_fast16_t my_int_fast16_t;
- typedef int_fast32_t my_int_fast32_t;
- typedef int_fast64_t my_int_fast64_t;
- typedef int_least8_t my_int_least8_t;
- typedef int_least16_t my_int_least16_t;
- typedef int_least32_t my_int_least32_t;
- typedef int_least64_t my_int_least64_t;
- typedef intmax_t my_intmax_t;
- typedef intptr_t my_intptr_t;
- typedef uint8_t my_uint8_t;
- typedef uint16_t my_uint16_t;
- typedef uint32_t my_uint32_t;
- typedef uint64_t my_uint64_t;
- typedef uint_fast8_t my_uint_fast8_t;
- typedef uint_fast16_t my_uint_fast16_t;
- typedef uint_fast32_t my_uint_fast32_t;
- typedef uint_fast64_t my_uint_fast64_t;
- typedef uint_least8_t my_uint_least8_t;
- typedef uint_least16_t my_uint_least16_t;
- typedef uint_least32_t my_uint_least32_t;
- typedef uint_least64_t my_uint_least64_t;
- typedef uintmax_t my_uintmax_t;
- typedef uintptr_t my_uintptr_t;
+ typedef std::tr1::int8_t my_int8_t;
+ typedef std::tr1::int16_t my_int16_t;
+ typedef std::tr1::int32_t my_int32_t;
+ typedef std::tr1::int64_t my_int64_t;
+ typedef std::tr1::int_fast8_t my_int_fast8_t;
+ typedef std::tr1::int_fast16_t my_int_fast16_t;
+ typedef std::tr1::int_fast32_t my_int_fast32_t;
+ typedef std::tr1::int_fast64_t my_int_fast64_t;
+ typedef std::tr1::int_least8_t my_int_least8_t;
+ typedef std::tr1::int_least16_t my_int_least16_t;
+ typedef std::tr1::int_least32_t my_int_least32_t;
+ typedef std::tr1::int_least64_t my_int_least64_t;
+ typedef std::tr1::intmax_t my_intmax_t;
+ typedef std::tr1::intptr_t my_intptr_t;
+ typedef std::tr1::uint8_t my_uint8_t;
+ typedef std::tr1::uint16_t my_uint16_t;
+ typedef std::tr1::uint32_t my_uint32_t;
+ typedef std::tr1::uint64_t my_uint64_t;
+ typedef std::tr1::uint_fast8_t my_uint_fast8_t;
+ typedef std::tr1::uint_fast16_t my_uint_fast16_t;
+ typedef std::tr1::uint_fast32_t my_uint_fast32_t;
+ typedef std::tr1::uint_fast64_t my_uint_fast64_t;
+ typedef std::tr1::uint_least8_t my_uint_least8_t;
+ typedef std::tr1::uint_least16_t my_uint_least16_t;
+ typedef std::tr1::uint_least32_t my_uint_least32_t;
+ typedef std::tr1::uint_least64_t my_uint_least64_t;
+ typedef std::tr1::uintmax_t my_uintmax_t;
+ typedef std::tr1::uintptr_t my_uintptr_t;
#endif
}
Index: acinclude.m4
===================================================================
--- acinclude.m4 (revision 110378)
+++ acinclude.m4 (working copy)
@@ -1181,6 +1181,29 @@
<tr1/cstdint> in namespace std::tr1.])
fi
+ # Check for the existence of <inttypes.h> functions.
+ AC_MSG_CHECKING([for ISO C99 support to TR1 in <inttypes.h>])
+ AC_CACHE_VAL(ac_c99_inttypes_tr1, [
+ AC_TRY_COMPILE([#include <inttypes.h>],
+ [intmax_t i, numer, denom, base;
+ const char* s;
+ char** endptr;
+ intmax_t ret;
+ uintmax_t uret;
+ imaxdiv_t dret;
+ ret = imaxabs(i);
+ dret = imaxdiv(numer, denom);
+ ret = strtoimax(s, endptr, base);
+ uret = strtoumax(s, endptr, base);
+ ],[ac_c99_inttypes_tr1=yes], [ac_c99_inttypes_tr1=no])
+ ])
+ AC_MSG_RESULT($ac_c99_inttypes_tr1)
+ if test x"$ac_c99_inttypes_tr1" = x"yes"; then
+ AC_DEFINE(_GLIBCXX_USE_C99_INTTYPES_TR1, 1,
+ [Define if C99 functions in <inttypes.h> should be imported in
+ <tr1/cinttypes> in namespace std::tr1.])
+ fi
+
AC_LANG_RESTORE
])