]>
Commit | Line | Data |
---|---|---|
83ffe9cd | 1 | // Copyright (C) 2021-2023 Free Software Foundation, Inc. |
b8ecdc77 JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
b8ecdc77 JW |
18 | // { dg-do compile { target c++23 } } |
19 | ||
20 | #include <type_traits> | |
21 | ||
22 | #ifndef __cpp_lib_is_scoped_enum | |
23 | # error "Feature test macro for is_scoped_enum is missing in <type_traits>" | |
24 | #elif __cpp_lib_is_scoped_enum < 202011L | |
25 | # error "Feature test macro for is_scoped_enum has wrong value in <type_traits>" | |
26 | #endif | |
27 | ||
28 | #include <testsuite_tr1.h> | |
29 | ||
30 | template<typename T> | |
31 | concept Is_scoped_enum | |
32 | = __gnu_test::test_category<std::is_scoped_enum, T>(true); | |
33 | ||
43ab1dc2 JW |
34 | struct Incomplete_struct; |
35 | ||
b8ecdc77 JW |
36 | void |
37 | test01() | |
38 | { | |
39 | enum class E { e1, e2 }; | |
40 | static_assert( Is_scoped_enum<E> ); | |
41 | enum class Ec : char { e1, e2 }; | |
42 | static_assert( Is_scoped_enum<Ec> ); | |
43 | ||
44 | // negative tests | |
45 | enum U { u1, u2 }; | |
46 | static_assert( ! Is_scoped_enum<U> ); | |
47 | enum F : int { f1, f2 }; | |
48 | static_assert( ! Is_scoped_enum<F> ); | |
43ab1dc2 JW |
49 | static_assert( ! Is_scoped_enum<Incomplete_struct> ); |
50 | struct S; | |
51 | static_assert( ! Is_scoped_enum<S> ); | |
b8ecdc77 JW |
52 | struct S { }; |
53 | static_assert( ! Is_scoped_enum<S> ); | |
54 | ||
55 | static_assert( ! Is_scoped_enum<int> ); | |
56 | static_assert( ! Is_scoped_enum<int[]> ); | |
57 | static_assert( ! Is_scoped_enum<int[2]> ); | |
58 | static_assert( ! Is_scoped_enum<int[][2]> ); | |
59 | static_assert( ! Is_scoped_enum<int[2][3]> ); | |
60 | static_assert( ! Is_scoped_enum<int*> ); | |
61 | static_assert( ! Is_scoped_enum<int&> ); | |
62 | static_assert( ! Is_scoped_enum<int*&> ); | |
63 | static_assert( ! Is_scoped_enum<int()> ); | |
64 | static_assert( ! Is_scoped_enum<int(*)()> ); | |
65 | static_assert( ! Is_scoped_enum<int(&)()> ); | |
66 | } | |
43ab1dc2 JW |
67 | |
68 | enum opaque_unscoped : short; | |
69 | enum class opaque_scoped; | |
70 | enum class opaque_scoped_with_base : long; | |
71 | ||
72 | static_assert( ! Is_scoped_enum<opaque_unscoped> ); | |
73 | static_assert( Is_scoped_enum<opaque_scoped> ); | |
74 | static_assert( Is_scoped_enum<opaque_scoped_with_base> ); | |
75 | ||
76 | void | |
77 | test02() | |
78 | { | |
79 | enum unscoped { | |
80 | u_is_enum = std::is_enum_v<unscoped>, | |
81 | u_is_scoped = std::is_scoped_enum_v<unscoped>, | |
82 | }; | |
83 | static_assert( unscoped::u_is_enum ); | |
84 | static_assert( ! unscoped::u_is_scoped ); | |
85 | ||
86 | enum unscoped_fixed : char { | |
87 | uf_is_enum = std::is_enum_v<unscoped_fixed>, | |
88 | uf_is_scoped = std::is_scoped_enum_v<unscoped_fixed>, | |
89 | }; | |
90 | static_assert( unscoped_fixed::uf_is_enum); | |
91 | static_assert( ! unscoped_fixed::uf_is_scoped ); | |
92 | ||
93 | enum class scoped { | |
94 | is_enum = std::is_enum_v<scoped>, | |
95 | is_scoped = std::is_scoped_enum_v<scoped>, | |
96 | }; | |
97 | static_assert( (bool) scoped::is_enum ); | |
98 | static_assert( (bool) scoped::is_scoped ); | |
99 | } |