mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-02 05:50:26 +08:00
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
This commit is contained in:
parent
4bd726d0bc
commit
3454c18fb5
@ -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.
|
||||
|
@ -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,15 +61,25 @@ _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.
|
||||
|
49
libstdc++-v3/testsuite/ext/type_traits/add_unsigned.cc
Normal file
49
libstdc++-v3/testsuite/ext/type_traits/add_unsigned.cc
Normal file
@ -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;
|
||||
}
|
@ -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" }
|
@ -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 }
|
49
libstdc++-v3/testsuite/ext/type_traits/remove_unsigned.cc
Normal file
49
libstdc++-v3/testsuite/ext/type_traits/remove_unsigned.cc
Normal file
@ -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;
|
||||
}
|
@ -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" }
|
@ -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 }
|
Loading…
x
Reference in New Issue
Block a user