From: Benjamin Kosnik Date: Fri, 29 Sep 2006 13:38:58 +0000 (+0000) Subject: type_traits.h (__remove_unsigned): Fix up for signed char, bool, wchar_t, and floatin... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3454c18fb5c3411019ce0ad7a418560acdc5cac1;p=gcc.git type_traits.h (__remove_unsigned): Fix up for signed char, bool, wchar_t, and floating point types. 2006-09-29 Benjamin Kosnik Howard Hinnant Paolo Carlini * 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 Co-Authored-By: Paolo Carlini From-SVN: r117303 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ab3f1e99555..9a5de15946d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2006-09-29 Benjamin Kosnik + Howard Hinnant + Paolo Carlini + + * 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 * 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 da71e986f75..56aebebdf4e 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 { typedef _Tp __type; }; - // XXX What about std::tr1::true_type? + // Conditional expression for types. If true, first, if false, second. template struct __conditional_type @@ -61,15 +61,25 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) { typedef _Iffalse __type; }; - // Given a builtin type, return the corresponding unsigned type. - template + // Given an integral builtin type, return the corresponding unsigned type. + template struct __add_unsigned - { typedef _Value __type; }; + { + private: + typedef __enable_if::__value, _T> __if_type; + + public: + typedef typename __if_type::__type __type; + }; template<> struct __add_unsigned { typedef unsigned char __type; }; + template<> + struct __add_unsigned + { typedef unsigned char __type; }; + template<> struct __add_unsigned { typedef unsigned short __type; }; @@ -82,20 +92,36 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) struct __add_unsigned { typedef unsigned long __type; }; -#ifdef _GLIBCXX_USE_LONG_LONG template<> struct __add_unsigned { typedef unsigned long long __type; }; -#endif - // Given an builtin type, return the corresponding signed type. - template + // Declare but don't define. + template<> + struct __add_unsigned; + + template<> + struct __add_unsigned; + + + // Given an integral builtin type, return the corresponding signed type. + template struct __remove_unsigned - { typedef _Value __type; }; + { + private: + typedef __enable_if::__value, _T> __if_type; + + public: + typedef typename __if_type::__type __type; + }; + + template<> + struct __remove_unsigned + { typedef signed char __type; }; template<> struct __remove_unsigned - { typedef char __type; }; + { typedef signed char __type; }; template<> struct __remove_unsigned @@ -109,11 +135,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) struct __remove_unsigned { typedef long __type; }; -#ifdef _GLIBCXX_USE_LONG_LONG template<> struct __remove_unsigned { typedef long long __type; }; -#endif + + // Declare but don't define. + template<> + struct __remove_unsigned; + + template<> + struct __remove_unsigned; + // 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.cc b/libstdc++-v3/testsuite/ext/type_traits.cc deleted file mode 100644 index ea58bb8afc7..00000000000 --- a/libstdc++-v3/testsuite/ext/type_traits.cc +++ /dev/null @@ -1,28 +0,0 @@ -// { dg-do compile } -// { dg-options "-pedantic" } -// -*- 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 - -using __gnu_cxx::__numeric_traits; -template struct __numeric_traits; -template struct __numeric_traits; -template struct __numeric_traits; 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 00000000000..846bf09ee55 --- /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 +#include +#include + +template + void + check_add_unsigned() + { + bool test __attribute__((unused)) = true; + typedef typename __gnu_cxx::__add_unsigned::__type unsigned_type; + VERIFY( std::tr1::is_unsigned::value ); + } + +int main() +{ + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + check_add_unsigned(); + 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 00000000000..e39f960ac33 --- /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 +#include + +template + void + check_add_unsigned() + { + typedef typename __gnu_cxx::__add_unsigned::__type unsigned_type; + } + +int main() +{ + check_add_unsigned(); // { 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 00000000000..0c55662bd4d --- /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 +#include + +template + void + check_add_unsigned() + { + typedef typename __gnu_cxx::__add_unsigned::__type unsigned_type; + } + +int main() +{ + check_add_unsigned(); // { dg-error "instantiated from" } + check_add_unsigned(); // { 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/numeric_traits.cc b/libstdc++-v3/testsuite/ext/type_traits/numeric_traits.cc new file mode 100644 index 00000000000..ea58bb8afc7 --- /dev/null +++ b/libstdc++-v3/testsuite/ext/type_traits/numeric_traits.cc @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-options "-pedantic" } +// -*- 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 + +using __gnu_cxx::__numeric_traits; +template struct __numeric_traits; +template struct __numeric_traits; +template struct __numeric_traits; 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 00000000000..2cad88afb9e --- /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 +#include +#include + +template + void + check_remove_unsigned() + { + bool test __attribute__((unused)) = true; + typedef typename __gnu_cxx::__remove_unsigned::__type signed_type; + VERIFY( std::tr1::is_signed::value ); + } + +int main() +{ + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + check_remove_unsigned(); + 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 00000000000..6f1b89a5230 --- /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 +#include + +template + void + check_remove_unsigned() + { + typedef typename __gnu_cxx::__remove_unsigned::__type signed_type; + } + +int main() +{ + check_remove_unsigned(); // { 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 00000000000..826d2ec2f87 --- /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 +#include + +template + void + check_remove_unsigned() + { + typedef typename __gnu_cxx::__remove_unsigned::__type signed_type; + } + +int main() +{ + check_remove_unsigned(); // { dg-error "instantiated from" } + check_remove_unsigned(); // { dg-error "instantiated from" } + return 0; +} + +// { dg-error "invalid use of incomplete" "" { target *-*-* } 29 } +// { dg-error "declaration of" "" { target *-*-* } 110 }