Debian Codegraph @

gcc/testsuite/g++.dg/ext/underlying_type8.C

raw
1 // { dg-do compile { target c++11 } }
2
3 enum E1 : unsigned { E1_en = 1 };
4 enum E2 : char { E2_en = 1 };
5 enum class E3 { a = -1 };
6 enum class E4 : unsigned char { c = 1 };
7 enum class E5 : int { a = -1, b = 1 };
8 enum class E6 : long { c = __LONG_MAX__ };
9
10 template<typename T1, typename T2>
11 struct is_same
12 { static const bool value = false; };
13
14 template<typename T>
15 struct is_same<T, T>
16 { static const bool value = true; };
17
18 template<typename>
19 struct underlying_type;
20
21 template<typename T, typename U>
22 void
23 test(T, U, typename underlying_type<T>::type);
24
25 template<typename T>
26 struct underlying_type
27 { typedef __underlying_type(T) type; };
28
29 template<typename T, typename U>
30 void
31 test(T, U, typename underlying_type<T>::type)
32 {
33 static_assert(is_same<typename underlying_type<T>::type, U>::value,
34 "Error");
35 }
36
37 int main()
38 {
39 test(E1::E1_en, unsigned(), 1);
40 test(E2::E2_en, char(), 1);
41 test(E3::a, int(), -1);
42 test(E4::c, (unsigned char)(1), 1);
43 test(E5::a, int(), -1);
44 test(E6::c, long(), __LONG_MAX__);
45 }