]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs-3.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / make_signed / requirements / typedefs-3.cc
CommitLineData
52066eae 1// { dg-do compile { target c++11 } }
73d81d3a 2
8d9254fc 3// Copyright (C) 2015-2020 Free Software Foundation, Inc.
73d81d3a
JW
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10//
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
20#include <type_traits>
21
22template<typename T, typename I0, typename... I>
23struct smallest_rank
24: std::conditional< sizeof(T) == sizeof(I0),
25 I0,
26 typename smallest_rank<T, I...>::type >
27{ };
28
29template<typename T, typename I0>
30struct smallest_rank<T, I0>
31{ using type = I0; };
32
33template<typename T>
34using smallest_rank_t
35 = typename smallest_rank<typename std::remove_cv<T>::type,
36 signed char, signed short, signed int,
37 signed long, signed long long>::type;
38
39using std::make_signed;
40using std::is_same;
41
42enum E1 : char { };
43using I1 = smallest_rank_t<E1>;
44static_assert(is_same<make_signed<E1>::type, I1>::value, "");
45static_assert(is_same<make_signed<E1 const>::type, I1 const>::value, "");
46
47enum E2 : short { };
48using I2 = smallest_rank_t<E2>;
49static_assert(is_same<make_signed<E2>::type, I2>::value, "");
50static_assert(is_same<make_signed<E2 const>::type, I2 const>::value, "");
51
52enum E3 : int { };
53using I3 = smallest_rank_t<E3>;
54static_assert(is_same<make_signed<E3>::type, I3>::value, "");
55static_assert(is_same<make_signed<E3 const>::type, I3 const>::value, "");
56
57enum E4 : long { };
58using I4 = smallest_rank_t<E4>;
59static_assert(is_same<make_signed<E4>::type, I4>::value, "");
60static_assert(is_same<make_signed<E4 const>::type, I4 const>::value, "");
61
22f1f4c7 62// PR libstdc++/60333
73d81d3a
JW
63enum E5 : long long { };
64using I5 = smallest_rank_t<E5>;
65static_assert(is_same<make_signed<E5>::type, I5>::value, "");
66static_assert(is_same<make_signed<E5 const>::type, I5 const>::value, "");
22f1f4c7
JW
67
68// PR libstdc++/85951
69using I6 = smallest_rank_t<char16_t>;
70static_assert(is_same<make_signed<char16_t>::type, I6>::value, "");
71static_assert(is_same<make_signed<char16_t const>::type, I6 const>::value, "");
72using I7 = smallest_rank_t<char32_t>;
73static_assert(is_same<make_signed<char32_t>::type, I7>::value, "");
74static_assert(is_same<make_signed<char32_t const>::type, I7 const>::value, "");
75#ifdef _GLIBCXX_USE_WCHAR_T
76using I8 = smallest_rank_t<wchar_t>;
77static_assert(is_same<make_signed<wchar_t>::type, I8>::value, "");
78static_assert(is_same<make_signed<wchar_t const>::type, I8 const>::value, "");
79#endif