272 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s2// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s3 4// p1099 'using SCOPEDENUM::MEMBER;'5 6namespace Zero {7namespace Bob {8enum class Kevin {9 Stuart,10 AlsoStuart11#if __cplusplus >= 202002L12// expected-note@-3{{target of using declaration}}13// expected-note@-3{{target of using declaration}}14#endif15};16} // namespace Bob17 18using Bob::Kevin::Stuart;19#if __cplusplus < 202002L20// expected-warning@-2{{using declaration naming a scoped enumerator is a C++20 extension}}21#else22using Bob::Kevin::Stuart;23 24auto b = Stuart;25 26namespace Foo {27int Stuart; // expected-note{{conflicting declaration}}28using Bob::Kevin::Stuart; // expected-error{{target of using declaration conflicts}}29 30using Bob::Kevin::AlsoStuart; // expected-note{{using declaration}}31int AlsoStuart; // expected-error{{declaration conflicts with target}}32} // namespace Foo33#endif34 35} // namespace Zero36 37namespace One {38 39// derived from [namespace.udecl]/340enum class button { up,41 down };42struct S {43 using button::up;44#if __cplusplus < 202002L45 // expected-warning@-2{{a C++20 extension}}46 // expected-error@-3{{using declaration in class}}47#else48 button b = up;49#endif50};51 52#if __cplusplus >= 202002L53// some more54struct T : S {55 button c = up;56};57#endif58enum E2 { e2 };59} // namespace One60 61namespace Two {62enum class E1 { e1 };63 64struct S {65 using One::e2;66#if __cplusplus < 202002L67 // expected-error@-2{{using declaration in class}}68#else69 One::E2 c = e2;70#endif71};72 73} // namespace Two74 75namespace Three {76 77enum E3 { e3 };78struct e3;79 80struct S {81 using Three::e3; // expected-error{{using declaration in class}}82 83 enum class E4 { e4 };84 enum E5 { e5 };85};86 87using S::e5;88using S::E4::e4;89#if __cplusplus < 202002L90// expected-error@-3{{using declaration cannot refer to class member}}91// expected-note@-4{{use a constexpr variable instead}}92// expected-warning@-4{{a C++20 extension}}93// expected-error@-5{{using declaration cannot refer to class member}}94// expected-note@-6{{use a constexpr variable instead}}95#else96auto a = e4;97auto b = e5;98#endif99} // namespace Three100 101namespace Four {102 103template <typename T>104struct TPL {105 enum class E1 { e1 };106 struct IN {107 enum class E2 { e2 };108 };109 110protected:111 enum class E3 { e3 }; // expected-note{{declared protected here}}112};113 114using TPL<int>::E1::e1;115#if __cplusplus < 202002L116// expected-warning@-2{{a C++20 extension}}117// expected-error@-3{{using declaration cannot refer to class member}}118// expected-note@-4{{use a constexpr variable instead}}119#else120using TPL<float>::IN::E2::e2;121 122auto a = e1;123auto b = e2;124#endif125 126enum class E4 { e4 };127template <typename T>128struct DER : TPL<int> {129 using TPL<T>::E1::e1;130#if __cplusplus < 202002L131 // expected-warning@-2{{a C++20 extension}}132 // expected-warning@-3{{using declaration naming a scoped}}133 // expected-error@-4{{which is not a base}}134#endif135 using TPL<T>::E3::e3; // expected-error{{is a protected member}}136#if __cplusplus < 202002L137 // expected-warning@-2 2{{using declaration naming a scoped}}138 // expected-error@-3{{which is not a base}}139#endif140 141 using E4::e4;142#if __cplusplus < 202002L143 // expected-warning@-2{{a C++20 extension}}144 // expected-error@-3{{which is not a class}}145#else146 auto Foo() { return e1; }147 auto Bar() { return e2; }148#endif149};150 151DER<float> x; // expected-note{{requested here}}152DER<int> y;153#if __cplusplus < 202002L154// expected-note@-2{{requested here}}155#else156auto y1 = y.Foo();157auto y2 = y.Bar();158#endif159} // namespace Four160 161namespace Five {162template <unsigned I, unsigned K>163struct Quux {164 enum class Q : unsigned; // expected-note{{member is declared here}}165 enum class R : unsigned { i = I,166 k = K };167};168 169using Quux<1, 2>::Q::nothing; // expected-error{{implicit instantiation of undefined}}170using Quux<1, 2>::R::i;171#if __cplusplus < 202002L172// expected-warning@-2{{a C++20 extension}}173// expected-error@-3{{using declaration cannot refer to class member}}174// expected-note@-4{{use a constexpr variable instead}}175#endif176 177} // namespace Five178 179namespace Six {180template <unsigned I, unsigned K>181struct Quux {182 enum class Q : unsigned; // expected-note{{member is declared here}}183 enum class R : unsigned { i = I,184 k = K };185};186 187template <unsigned I> struct Fido {188 using Quux<I, I>::Q::nothing; // expected-error{{implicit instantiation of undefined}}189};190 191Fido<2> a; // expected-note{{in instantiation}}192 193} // namespace Six194 195namespace Seven {196template <unsigned I, unsigned K>197struct Quux {198 enum class R : unsigned { i = I,199 k = K };200};201 202template <unsigned I> struct Toto {203 using Quux<I, I>::R::i;204#if __cplusplus < 202002L205 // expected-warning@-2{{a C++20 extension}}206// expected-error@-3{{refers into}}207#else208 static_assert(unsigned(i) == I);209#endif210};211 212Toto<2> b;213#if __cplusplus < 202002L214// expected-note@-2{{in instantiation}}215#endif216 217} // namespace Seven218 219namespace Eight {220struct Kevin {221 enum class B { a };222 enum a {};223};224 225using Kevin::B::a;226#if __cplusplus < 202002L227// expected-warning@-2{{a C++20 extension}}228// expected-error@-3{{using declaration cannot refer to class member}}229// expected-note@-4{{use a constexpr variable instead}}230#endif231using Kevin::B::a;232#if __cplusplus < 202002L233// expected-warning@-2{{a C++20 extension}}234// expected-error@-3{{using declaration cannot refer to class member}}235// expected-note@-4{{use a constexpr variable instead}}236#endif237 238class X : Kevin {239 using Kevin::B::a; // expected-note{{previous using declaration}}240#if __cplusplus < 202002L241// expected-warning@-2{{a C++20 extension}}242#endif243 using Kevin::a;244 using Kevin::B::a; // expected-error{{redeclaration of using declaration}}245};246 247} // namespace Eight248 249namespace Nine {250namespace Q {251enum class Bob { a };252using Bob::a;253#if __cplusplus < 202002L254// expected-warning@-2{{a C++20 extension}}255#endif256} // namespace Q257 258using Q::a;259using Q::Bob::a;260#if __cplusplus < 202002L261// expected-warning@-2{{a C++20 extension}}262#endif263 264#if __cplusplus >= 202002L265struct Foo {266 using Q::a; // expected-note{{previous using declaration}}267 using Q::Bob::a;268 using Q::a; // expected-error{{redeclaration of using declaration}}269};270#endif271} // namespace Nine272