OSDN Git Service

2006-09-29 Benjamin Kosnik <bkoz@redhat.com>
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 29 Sep 2006 13:38:58 +0000 (13:38 +0000)
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 29 Sep 2006 13:38:58 +0000 (13:38 +0000)
            Howard Hinnant  <hhinnant@apple.com>
            Paolo Carlini  <pcarlini@suse.de>

* include/ext/type_traits.h (__remove_unsigned): Fix up for signed
char, bool, wchar_t, and floating point types.
(__add_unsigned): Same.
* testsuite/ext/type_traits: New.
* testsuite/ext/type_traits.cc: Move...
* testsuite/ext/type_traits/numeric_traits.cc: ...here.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: New.
* testsuite/ext/type_traits/add_unsigned_integer_neg.cc: New.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: New.
* testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: New.
* testsuite/ext/type_traits/add_unsigned.cc: New.
* testsuite/ext/type_traits/remove_unsigned.cc: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117303 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/ext/type_traits.h
libstdc++-v3/testsuite/ext/type_traits/add_unsigned.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/type_traits/add_unsigned_floating_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/type_traits/add_unsigned_integer_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/type_traits/numeric_traits.cc [moved from libstdc++-v3/testsuite/ext/type_traits.cc with 100% similarity]
libstdc++-v3/testsuite/ext/type_traits/remove_unsigned.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_floating_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_integer_neg.cc [new file with mode: 0644]

index ab3f1e9..9a5de15 100644 (file)
@@ -1,3 +1,20 @@
+2006-09-29  Benjamin Kosnik  <bkoz@redhat.com>
+            Howard Hinnant  <hhinnant@apple.com>
+            Paolo Carlini  <pcarlini@suse.de>
+
+       * include/ext/type_traits.h (__remove_unsigned): Fix up for signed
+       char, bool, wchar_t, and floating point types.
+       (__add_unsigned): Same. 
+       * testsuite/ext/type_traits: New.
+       * testsuite/ext/type_traits.cc: Move...
+       * testsuite/ext/type_traits/numeric_traits.cc: ...here. 
+       * testsuite/ext/type_traits/add_unsigned_floating_neg.cc: New.
+       * testsuite/ext/type_traits/add_unsigned_integer_neg.cc: New.
+       * testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: New.
+       * testsuite/ext/type_traits/remove_unsigned_integer_neg.cc: New.
+       * testsuite/ext/type_traits/add_unsigned.cc: New.
+       * testsuite/ext/type_traits/remove_unsigned.cc: New.
+       
 2006-09-29  Joseph S. Myers  <joseph@codesourcery.com>
 
        * acinclude.m4 (enable_symvers): Default to no if unable to link.
index da71e98..56aebeb 100644 (file)
@@ -50,7 +50,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
     struct __enable_if<true, _Tp>
     { typedef _Tp __type; };
 
-  // XXX What about std::tr1::true_type?
+
   // Conditional expression for types. If true, first, if false, second.
   template<bool _Cond, typename _Iftrue, typename _Iffalse>
     struct __conditional_type
@@ -61,16 +61,26 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
     { typedef _Iffalse __type; };
 
 
-  // Given a builtin type, return the corresponding unsigned type.
-  template<typename _Value>
+  // Given an integral builtin type, return the corresponding unsigned type.
+  template<typename _T>
     struct __add_unsigned
-    { typedef _Value __type; };
+    { 
+    private:
+      typedef __enable_if<std::__is_integer<_T>::__value, _T> __if_type;
+      
+    public:
+      typedef typename __if_type::__type __type; 
+    };
 
   template<>
     struct __add_unsigned<char>
     { typedef unsigned char __type; };
 
   template<>
+    struct __add_unsigned<signed char>
+    { typedef unsigned char __type; };
+
+  template<>
     struct __add_unsigned<short>
     { typedef unsigned short __type; };
 
@@ -82,20 +92,36 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
     struct __add_unsigned<long>
     { typedef unsigned long __type; };
 
-#ifdef _GLIBCXX_USE_LONG_LONG
   template<>
     struct __add_unsigned<long long>
     { typedef unsigned long long __type; };
-#endif
 
-  // Given an builtin type, return the corresponding signed type.
-  template<typename _Value>
+  // Declare but don't define.
+  template<>
+    struct __add_unsigned<bool>;
+
+  template<>
+    struct __add_unsigned<wchar_t>;
+
+
+  // Given an integral builtin type, return the corresponding signed type.
+  template<typename _T>
     struct __remove_unsigned
-    { typedef _Value __type; };
+    { 
+    private:
+      typedef __enable_if<std::__is_integer<_T>::__value, _T> __if_type;
+      
+    public:
+      typedef typename __if_type::__type __type; 
+    };
+
+  template<>
+    struct __remove_unsigned<char>
+    { typedef signed char __type; };
 
   template<>
     struct __remove_unsigned<unsigned char>
-    { typedef char __type; };
+    { typedef signed char __type; };
 
   template<>
     struct __remove_unsigned<unsigned short>
@@ -109,11 +135,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
     struct __remove_unsigned<unsigned long>
     { typedef long __type; };
 
-#ifdef _GLIBCXX_USE_LONG_LONG
   template<>
     struct __remove_unsigned<unsigned long long>
     { typedef long long __type; };
-#endif
+
+  // Declare but don't define.
+  template<>
+    struct __remove_unsigned<bool>;
+
+  template<>
+    struct __remove_unsigned<wchar_t>;
+
 
   // Compile time constants for builtin types.
   // Sadly std::numeric_limits member functions cannot be used for this.
diff --git a/libstdc++-v3/testsuite/ext/type_traits/add_unsigned.cc b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned.cc
new file mode 100644 (file)
index 0000000..846bf09
--- /dev/null
@@ -0,0 +1,49 @@
+// -*- 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.
+
+#include <ext/type_traits.h>
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+
+template<typename T>
+  void
+  check_add_unsigned()
+  {
+    bool test __attribute__((unused)) = true;
+    typedef typename __gnu_cxx::__add_unsigned<T>::__type unsigned_type;
+    VERIFY( std::tr1::is_unsigned<unsigned_type>::value );
+  }
+
+int main()
+{
+  check_add_unsigned<char>();
+  check_add_unsigned<unsigned char>();
+  check_add_unsigned<signed char>();
+  check_add_unsigned<int>();
+  check_add_unsigned<unsigned int>();
+  check_add_unsigned<signed int>();
+  check_add_unsigned<long>();
+  check_add_unsigned<unsigned long>();
+  check_add_unsigned<signed long>();
+  check_add_unsigned<long long>();
+  check_add_unsigned<unsigned long long>();
+  check_add_unsigned<signed long long>();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_floating_neg.cc b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_floating_neg.cc
new file mode 100644 (file)
index 0000000..e39f960
--- /dev/null
@@ -0,0 +1,40 @@
+// { dg-do compile }
+// -*- 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.
+
+#include <ext/type_traits.h>
+#include <tr1/type_traits>
+
+template<typename T>
+  void
+  check_add_unsigned()
+  {
+    typedef typename __gnu_cxx::__add_unsigned<T>::__type unsigned_type;
+  }
+
+int main()
+{
+  check_add_unsigned<float>();  // { dg-error "instantiated from" }
+  return 0;
+}
+
+// { dg-error "instantiated from" "" { target *-*-* } 29 } 
+// { dg-error "no type" "" { target *-*-* } 72 } 
+// { dg-excess-errors "In instantiation of" }
diff --git a/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_integer_neg.cc b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_integer_neg.cc
new file mode 100644 (file)
index 0000000..0c55662
--- /dev/null
@@ -0,0 +1,40 @@
+// { dg-do compile }
+// -*- 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.
+
+#include <ext/type_traits.h>
+#include <tr1/type_traits>
+
+template<typename T>
+  void
+  check_add_unsigned()
+  {
+    typedef typename __gnu_cxx::__add_unsigned<T>::__type unsigned_type;
+  }
+
+int main()
+{
+  check_add_unsigned<bool>();  // { dg-error "instantiated from" }
+  check_add_unsigned<wchar_t>();  // { dg-error "instantiated from" }
+  return 0;
+}
+
+// { dg-error "invalid use of incomplete" "" { target *-*-* } 29 } 
+// { dg-error "declaration of" "" { target *-*-* } 67 } 
diff --git a/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned.cc b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned.cc
new file mode 100644 (file)
index 0000000..2cad88a
--- /dev/null
@@ -0,0 +1,49 @@
+// -*- 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.
+
+#include <ext/type_traits.h>
+#include <tr1/type_traits>
+#include <testsuite_hooks.h>
+
+template<typename T>
+  void
+  check_remove_unsigned()
+  {
+    bool test __attribute__((unused)) = true;
+    typedef typename __gnu_cxx::__remove_unsigned<T>::__type signed_type;
+    VERIFY( std::tr1::is_signed<signed_type>::value );
+  }
+
+int main()
+{
+  check_remove_unsigned<char>();
+  check_remove_unsigned<unsigned char>();
+  check_remove_unsigned<signed char>();
+  check_remove_unsigned<int>();
+  check_remove_unsigned<unsigned int>();
+  check_remove_unsigned<signed int>();
+  check_remove_unsigned<long>();
+  check_remove_unsigned<unsigned long>();
+  check_remove_unsigned<signed long>();
+  check_remove_unsigned<long long>();
+  check_remove_unsigned<unsigned long long>();
+  check_remove_unsigned<signed long long>();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_floating_neg.cc b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_floating_neg.cc
new file mode 100644 (file)
index 0000000..6f1b89a
--- /dev/null
@@ -0,0 +1,40 @@
+// { dg-do compile }
+// -*- 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.
+
+#include <ext/type_traits.h>
+#include <tr1/type_traits>
+
+template<typename T>
+  void
+  check_remove_unsigned()
+  {
+    typedef typename __gnu_cxx::__remove_unsigned<T>::__type signed_type;
+  }
+
+int main()
+{
+  check_remove_unsigned<float>();  // { dg-error "instantiated from" }
+  return 0;
+}
+
+// { dg-error "instantiated from" "" { target *-*-* } 29 }
+// { dg-error "no type" "" { target *-*-* } 115 }
+// { dg-excess-errors "In instantiation of" }
diff --git a/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_integer_neg.cc b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_integer_neg.cc
new file mode 100644 (file)
index 0000000..826d2ec
--- /dev/null
@@ -0,0 +1,40 @@
+// { dg-do compile }
+// -*- 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.
+
+#include <ext/type_traits.h>
+#include <tr1/type_traits>
+
+template<typename T>
+  void
+  check_remove_unsigned()
+  {
+    typedef typename __gnu_cxx::__remove_unsigned<T>::__type signed_type;
+  }
+
+int main()
+{
+  check_remove_unsigned<bool>();  // { dg-error "instantiated from" }
+  check_remove_unsigned<wchar_t>();  // { dg-error "instantiated from" }
+  return 0;
+}
+
+// { dg-error "invalid use of incomplete" "" { target *-*-* } 29 } 
+// { dg-error "declaration of" "" { target *-*-* } 110 }