From: Jonathan Wakely Date: Tue, 28 Apr 2015 13:21:54 +0000 (+0100) Subject: re PR libstdc++/60333 (type_traits make_signed, make_unsigned missing support for... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=73d81d3a6b23ddbfd5286a93f38a45059f90dcec;p=gcc.git re PR libstdc++/60333 (type_traits make_signed, make_unsigned missing support for long long enumerations) PR libstdc++/60333 * include/std/type_traits (__make_unsigned_selector<_Tp, false, true>): Handle enumeration types larger than sizeof(long). (__make_signed_selector<_Tp, false, true>): Find unsigned type then make it signed. * testsuite/20_util/declval/requirements/1_neg.cc: Adjust dg-error. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Likewise. * testsuite/20_util/make_signed/requirements/typedefs-3.cc: New. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Adjust dg-error. * testsuite/20_util/make_unsigned/requirements/typedefs-3.cc: New. From-SVN: r222526 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e3242e8a163..a38b6e33703 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,18 @@ 2015-04-28 Jonathan Wakely + PR libstdc++/60333 + * include/std/type_traits (__make_unsigned_selector<_Tp, false, true>): + Handle enumeration types larger than sizeof(long). + (__make_signed_selector<_Tp, false, true>): Find unsigned type then + make it signed. + * testsuite/20_util/declval/requirements/1_neg.cc: Adjust dg-error. + * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: + Likewise. + * testsuite/20_util/make_signed/requirements/typedefs-3.cc: New. + * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Adjust + dg-error. + * testsuite/20_util/make_unsigned/requirements/typedefs-3.cc: New. + PR libstdc++/61645 * include/bits/forward_list.h (forward_list::splice_after): Add noexcept. diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 3ed1a7b5a0a..b8ec61f6892 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1739,13 +1739,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short); static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int); - typedef conditional<__b2, unsigned int, unsigned long> __cond2; + static const bool __b3 = sizeof(_Tp) <= sizeof(unsigned long); + typedef conditional<__b3, unsigned long, unsigned long long> __cond3; + typedef typename __cond3::type __cond3_type; + typedef conditional<__b2, unsigned int, __cond3_type> __cond2; typedef typename __cond2::type __cond2_type; typedef conditional<__b1, unsigned short, __cond2_type> __cond1; typedef typename __cond1::type __cond1_type; + typedef typename conditional<__b0, __smallest, __cond1_type>::type + __unsigned_type; + typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned; + public: - typedef typename conditional<__b0, __smallest, __cond1_type>::type __type; + typedef typename __cv_unsigned::__type __type; }; // Given an integral/enum type, return the corresponding unsigned @@ -1846,18 +1853,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template class __make_signed_selector<_Tp, false, true> { - // With -fshort-enums, an enum may be as small as a char. - typedef signed char __smallest; - static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); - static const bool __b1 = sizeof(_Tp) <= sizeof(signed short); - static const bool __b2 = sizeof(_Tp) <= sizeof(signed int); - typedef conditional<__b2, signed int, signed long> __cond2; - typedef typename __cond2::type __cond2_type; - typedef conditional<__b1, signed short, __cond2_type> __cond1; - typedef typename __cond1::type __cond1_type; + typedef typename __make_unsigned_selector<_Tp>::__type __unsigned_type; public: - typedef typename conditional<__b0, __smallest, __cond1_type>::type __type; + typedef typename __make_signed_selector<__unsigned_type>::__type __type; }; // Given an integral/enum type, return the corresponding signed diff --git a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc index 2e2a14a3920..263fff2d4df 100644 --- a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc +++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "static assertion failed" "" { target *-*-* } 2204 } +// { dg-error "static assertion failed" "" { target *-*-* } 2203 } #include diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-3.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-3.cc new file mode 100644 index 00000000000..b4862866cea --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-3.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// Copyright (C) 2015 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 3, 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 COPYING3. If not see +// . + +#include + +template +struct smallest_rank +: std::conditional< sizeof(T) == sizeof(I0), + I0, + typename smallest_rank::type > +{ }; + +template +struct smallest_rank +{ using type = I0; }; + +template +using smallest_rank_t + = typename smallest_rank::type, + signed char, signed short, signed int, + signed long, signed long long>::type; + +using std::make_signed; +using std::is_same; + +enum E1 : char { }; +using I1 = smallest_rank_t; +static_assert(is_same::type, I1>::value, ""); +static_assert(is_same::type, I1 const>::value, ""); + +enum E2 : short { }; +using I2 = smallest_rank_t; +static_assert(is_same::type, I2>::value, ""); +static_assert(is_same::type, I2 const>::value, ""); + +enum E3 : int { }; +using I3 = smallest_rank_t; +static_assert(is_same::type, I3>::value, ""); +static_assert(is_same::type, I3 const>::value, ""); + +enum E4 : long { }; +using I4 = smallest_rank_t; +static_assert(is_same::type, I4>::value, ""); +static_assert(is_same::type, I4 const>::value, ""); + +// PI libstdc++/60333 +enum E5 : long long { }; +using I5 = smallest_rank_t; +static_assert(is_same::type, I5>::value, ""); +static_assert(is_same::type, I5 const>::value, ""); diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc index 629d732972a..5fbf311516a 100644 --- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc @@ -48,5 +48,4 @@ void test01() // { dg-error "required from here" "" { target *-*-* } 40 } // { dg-error "required from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1869 } -// { dg-error "declaration of" "" { target *-*-* } 1833 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1868 } diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-3.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-3.cc new file mode 100644 index 00000000000..07c35bcc5cc --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs-3.cc @@ -0,0 +1,67 @@ +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +// Copyright (C) 2015 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 3, 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 COPYING3. If not see +// . + +#include + +template +struct smallest_rank +: std::conditional< sizeof(T) == sizeof(I0), + I0, + typename smallest_rank::type > +{ }; + +template +struct smallest_rank +{ using type = I0; }; + +template +using smallest_rank_t + = typename smallest_rank::type, + unsigned char, unsigned short, unsigned int, + unsigned long, unsigned long long>::type; + +using std::make_unsigned; +using std::is_same; + +enum E1 : char { }; +using I1 = smallest_rank_t; +static_assert(is_same::type, I1>::value, ""); +static_assert(is_same::type, I1 const>::value, ""); + +enum E2 : short { }; +using I2 = smallest_rank_t; +static_assert(is_same::type, I2>::value, ""); +static_assert(is_same::type, I2 const>::value, ""); + +enum E3 : int { }; +using I3 = smallest_rank_t; +static_assert(is_same::type, I3>::value, ""); +static_assert(is_same::type, I3 const>::value, ""); + +enum E4 : long { }; +using I4 = smallest_rank_t; +static_assert(is_same::type, I4>::value, ""); +static_assert(is_same::type, I4 const>::value, ""); + +// PI libstdc++/60333 +enum E5 : long long { }; +using I5 = smallest_rank_t; +static_assert(is_same::type, I5>::value, ""); +static_assert(is_same::type, I5 const>::value, ""); diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc index 2dee1192c36..4e54b1842d7 100644 --- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc @@ -48,5 +48,5 @@ void test01() // { dg-error "required from here" "" { target *-*-* } 40 } // { dg-error "required from here" "" { target *-*-* } 42 } -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1757 } +// { dg-error "invalid use of incomplete type" "" { target *-*-* } 1764 } // { dg-error "declaration of" "" { target *-*-* } 1721 }