diff options
author | Benjamin Kosnik <bkoz@redhat.com> | 2006-09-29 13:38:58 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2006-09-29 13:38:58 +0000 |
commit | 3454c18fb5c3411019ce0ad7a418560acdc5cac1 (patch) | |
tree | 244e38f6261956ccf4a897d35f4cb4bfe4b924b1 | |
parent | 4bd726d0bc325a1a52aeda349399f2bc0895a0c7 (diff) | |
download | gcc-3454c18fb5c3411019ce0ad7a418560acdc5cac1.zip gcc-3454c18fb5c3411019ce0ad7a418560acdc5cac1.tar.gz gcc-3454c18fb5c3411019ce0ad7a418560acdc5cac1.tar.bz2 |
type_traits.h (__remove_unsigned): Fix up for signed char, bool, wchar_t, and floating point types.
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.
Co-Authored-By: Howard Hinnant <hhinnant@apple.com>
Co-Authored-By: Paolo Carlini <pcarlini@suse.de>
From-SVN: r117303
-rw-r--r-- | libstdc++-v3/ChangeLog | 17 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/type_traits.h | 56 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/ext/type_traits/add_unsigned.cc | 49 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/ext/type_traits/add_unsigned_floating_neg.cc | 40 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/ext/type_traits/add_unsigned_integer_neg.cc | 40 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/ext/type_traits/numeric_traits.cc (renamed from libstdc++-v3/testsuite/ext/type_traits.cc) | 0 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/ext/type_traits/remove_unsigned.cc | 49 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_floating_neg.cc | 40 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_integer_neg.cc | 40 |
9 files changed, 319 insertions, 12 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ab3f1e9..9a5de15 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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. diff --git a/libstdc++-v3/include/ext/type_traits.h b/libstdc++-v3/include/ext/type_traits.h index da71e98..56aebeb 100644 --- a/libstdc++-v3/include/ext/type_traits.h +++ b/libstdc++-v3/include/ext/type_traits.h @@ -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 index 0000000..846bf09 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned.cc @@ -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 index 0000000..e39f960 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_floating_neg.cc @@ -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 index 0000000..0c55662 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/type_traits/add_unsigned_integer_neg.cc @@ -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.cc b/libstdc++-v3/testsuite/ext/type_traits/numeric_traits.cc index ea58bb8..ea58bb8 100644 --- a/libstdc++-v3/testsuite/ext/type_traits.cc +++ b/libstdc++-v3/testsuite/ext/type_traits/numeric_traits.cc 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 index 0000000..2cad88a --- /dev/null +++ b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned.cc @@ -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 index 0000000..6f1b89a --- /dev/null +++ b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_floating_neg.cc @@ -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 index 0000000..826d2ec --- /dev/null +++ b/libstdc++-v3/testsuite/ext/type_traits/remove_unsigned_integer_neg.cc @@ -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 } |