Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / cxx20-using-enum.cpp
blob872353aad8a0d48e2f4d575830588dade217e87c
1 // RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
4 // p1099 'using enum ELABORATED-ENUM-SPECIFIER ;'
6 namespace One {
7 namespace Bob {
8 enum A { a, // expected-note{{declared here}}
9 b,
10 c };
11 class C;
12 enum class D : int;
13 enum class D { d,
15 f };
16 enum class D : int;
17 } // namespace Bob
19 using enum Bob::A;
20 #if __cplusplus < 202002
21 // expected-warning@-2{{is a C++20 extension}}
22 #endif
23 using enum Bob::B; // expected-error{{unknown type name B}}
24 #if __cplusplus < 202002
25 // expected-warning@-2{{is a C++20 extension}}
26 #endif
27 using enum Bob::C; // expected-error{{'Bob::C' is not an enumerated type}}
28 #if __cplusplus < 202002
29 // expected-warning@-2{{is a C++20 extension}}
30 #endif
31 auto v = a;
33 A g; // expected-error{{unknown type name 'A'}}
35 int A;
37 using enum Bob::D;
38 #if __cplusplus < 202002
39 // expected-warning@-2{{is a C++20 extension}}
40 #endif
42 void DR2621() {
43 using A_t = Bob::A;
44 using enum A_t;
45 #if __cplusplus < 202002
46 // expected-warning@-2{{is a C++20 extension}}
47 #endif
48 A_t x = a;
51 } // namespace One
53 namespace Two {
54 namespace Kevin {
55 enum class B { d,
57 f };
60 using enum Kevin::B;
61 #if __cplusplus < 202002
62 // expected-warning@-2{{is a C++20 extension}}
63 #endif
64 auto w = e;
66 } // namespace Two
68 #if __cplusplus >= 202002
69 // Now only check c++20 onwards
71 namespace Three {
72 namespace Stuart {
73 enum class C : int; // expected-note{{declared here}}
76 using enum Stuart::C; // expected-error{{is incomplete}}
77 } // namespace Three
79 namespace Four {
80 class Dave {
81 public:
82 enum D { a,
84 c };
86 private:
87 enum class E { d, // expected-note{{declared private here}}
89 f };
92 using enum Dave::D;
93 using enum Dave::E; // expected-error{{is a private member}}
95 } // namespace Four
97 namespace Five {
98 enum class A { b,
99 c };
100 class Dave {
101 public:
102 using enum A;
103 A f = b;
106 } // namespace Five
108 namespace Six {
109 template <typename T> class TPL;
110 template <> class TPL<int> {
111 public:
112 enum A { a };
115 template <typename T> class USR {
116 using enum TPL<T>::B; // expected-error{{cannot name a dependent type}}
117 using enum TPL<int>::A;
119 } // namespace Six
121 // Now instantiate things
122 namespace Seven {
123 namespace Stuart {
124 enum class A { a,
126 c };
129 static_assert(!int(Stuart::A::a));
130 constexpr int Bar() {
131 using enum Stuart::A;
132 return int(b);
134 static_assert(Bar() == 1);
136 template <int I> constexpr int Foo() {
137 using enum Stuart::A;
138 return int(b) + I;
141 static_assert(Foo<10>() == 11);
143 template <int I> struct C {
144 using enum Stuart::A;
145 static constexpr int V = int(c) + I;
147 enum class D { d,
149 f };
150 using enum D;
152 static constexpr int W = int(f) + I;
155 static_assert(C<2>::V == 4);
156 static_assert(C<20>::W == 22);
158 } // namespace Seven
160 namespace Eight {
161 enum class Bob : int {};
162 using enum Bob;
163 } // namespace Eight
165 namespace Nine {
166 template <int I> struct C {
167 enum class D { i = I };
168 enum class E : int; // expected-note{{declared here}}
171 using enum C<2>::D;
173 constexpr auto d = i;
174 static_assert(unsigned(d) == 2);
176 using enum C<2>::E; // expected-error{{instantiation of undefined member}}
177 } // namespace Nine
179 namespace Ten {
180 enum class Bob { a };
182 void Foo() {
183 extern void a();
186 // We don't see the hidden extern a fn!
187 using enum Bob;
189 auto v = a;
190 } // namespace Ten
192 namespace Eleven {
193 enum class Bob { a }; // expected-note{{conflicting declaration}}
195 struct Base {
196 enum { a }; // expected-note{{target of using}}
199 template <typename B>
200 class TPLa : B {
201 using enum Bob;
202 using B::a; // expected-error{{target of using declaration}}
205 TPLa<Base> a; // expected-note{{in instantiation}}
207 } // namespace Eleven
209 namespace Twelve {
210 enum class Bob { a }; // expected-note{{target of using}}
212 struct Base {
213 enum { a };
216 template <typename B>
217 class TPLb : B {
218 using B::a; // expected-note{{conflicting declaration}}
219 using enum Bob; // expected-error{{target of using declaration}}
222 TPLb<Base> b;
224 } // namespace Twelve
226 namespace Thirteen {
227 enum class Bob { a };
228 class Foo {
229 using enum Bob; // expected-note{{previous using-enum}}
230 using enum Bob; // expected-error{{redeclaration of using-enum}}
233 template <typename B>
234 class TPLa {
235 using enum Bob; // expected-note{{previous using-enum}}
236 using enum Bob; // expected-error{{redeclaration of using-enum}}
239 TPLa<int> a;
241 } // namespace Thirteen
243 namespace GH58057 {
244 struct Wrap {
245 enum Things {
246 Value1,
247 Value2
251 using enum Wrap::Things;
253 int f() {
254 return (Value1 | Value2);
258 namespace GH59014 {
259 struct X {
260 enum Masks {Mask = 1,Shift = 0};
263 void f(int a) {
264 using enum X::Masks;
266 auto u = (Mask);
267 auto v = (Mask << Shift);
268 void (~(Mask));
272 #endif