| 1 |
// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s |
| 3 |
|
| 4 |
// p1099 'using SCOPEDENUM::MEMBER;' |
| 5 |
|
| 6 |
namespace Zero { |
| 7 |
namespace Bob { |
| 8 |
enum class Kevin { |
| 9 |
Stuart, |
| 10 |
AlsoStuart |
| 11 |
#if __cplusplus >= 202002L |
| 12 |
// expected-note@-3{{target of using declaration}} |
| 13 |
// expected-note@-3{{target of using declaration}} |
| 14 |
#endif |
| 15 |
}; |
| 16 |
} // namespace Bob |
| 17 |
|
| 18 |
using Bob::Kevin::Stuart; |
| 19 |
#if __cplusplus < 202002L |
| 20 |
// expected-warning@-2{{using declaration naming a scoped enumerator is a C++20 extension}} |
| 21 |
#else |
| 22 |
using Bob::Kevin::Stuart; |
| 23 |
|
| 24 |
auto b = Stuart; |
| 25 |
|
| 26 |
namespace Foo { |
| 27 |
int Stuart; // expected-note{{conflicting declaration}} |
| 28 |
using Bob::Kevin::Stuart; // expected-error{{target of using declaration conflicts}} |
| 29 |
|
| 30 |
using Bob::Kevin::AlsoStuart; // expected-note{{using declaration}} |
| 31 |
int AlsoStuart; // expected-error{{declaration conflicts with target}} |
| 32 |
} // namespace Foo |
| 33 |
#endif |
| 34 |
|
| 35 |
} // namespace Zero |
| 36 |
|
| 37 |
namespace One { |
| 38 |
|
| 39 |
// derived from [namespace.udecl]/3 |
| 40 |
enum class button { up, |
| 41 |
down }; |
| 42 |
struct S { |
| 43 |
using button::up; |
| 44 |
#if __cplusplus < 202002L |
| 45 |
// expected-warning@-2{{a C++20 extension}} |
| 46 |
// expected-error@-3{{using declaration in class}} |
| 47 |
#else |
| 48 |
button b = up; |
| 49 |
#endif |
| 50 |
}; |
| 51 |
|
| 52 |
#if __cplusplus >= 202002L |
| 53 |
// some more |
| 54 |
struct T : S { |
| 55 |
button c = up; |
| 56 |
}; |
| 57 |
#endif |
| 58 |
enum E2 { e2 }; |
| 59 |
} // namespace One |
| 60 |
|
| 61 |
namespace Two { |
| 62 |
enum class E1 { e1 }; |
| 63 |
|
| 64 |
struct S { |
| 65 |
using One::e2; |
| 66 |
#if __cplusplus < 202002L |
| 67 |
// expected-error@-2{{using declaration in class}} |
| 68 |
#else |
| 69 |
One::E2 c = e2; |
| 70 |
#endif |
| 71 |
}; |
| 72 |
|
| 73 |
} // namespace Two |
| 74 |
|
| 75 |
namespace Three { |
| 76 |
|
| 77 |
enum E3 { e3 }; |
| 78 |
struct e3; |
| 79 |
|
| 80 |
struct S { |
| 81 |
using Three::e3; // expected-error{{using declaration in class}} |
| 82 |
|
| 83 |
enum class E4 { e4 }; |
| 84 |
enum E5 { e5 }; |
| 85 |
}; |
| 86 |
|
| 87 |
using S::e5; |
| 88 |
using S::E4::e4; |
| 89 |
#if __cplusplus < 202002L |
| 90 |
// 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 |
#else |
| 96 |
auto a = e4; |
| 97 |
auto b = e5; |
| 98 |
#endif |
| 99 |
} // namespace Three |
| 100 |
|
| 101 |
namespace Four { |
| 102 |
|
| 103 |
template <typename T> |
| 104 |
struct TPL { |
| 105 |
enum class E1 { e1 }; |
| 106 |
struct IN { |
| 107 |
enum class E2 { e2 }; |
| 108 |
}; |
| 109 |
|
| 110 |
protected: |
| 111 |
enum class E3 { e3 }; // expected-note{{declared protected here}} |
| 112 |
}; |
| 113 |
|
| 114 |
using TPL<int>::E1::e1; |
| 115 |
#if __cplusplus < 202002L |
| 116 |
// 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 |
#else |
| 120 |
using TPL<float>::IN::E2::e2; |
| 121 |
|
| 122 |
auto a = e1; |
| 123 |
auto b = e2; |
| 124 |
#endif |
| 125 |
|
| 126 |
enum class E4 { e4 }; |
| 127 |
template <typename T> |
| 128 |
struct DER : TPL<int> { |
| 129 |
using TPL<T>::E1::e1; |
| 130 |
#if __cplusplus < 202002L |
| 131 |
// 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 |
#endif |
| 135 |
using TPL<T>::E3::e3; // expected-error{{is a protected member}} |
| 136 |
#if __cplusplus < 202002L |
| 137 |
// expected-warning@-2 2{{using declaration naming a scoped}} |
| 138 |
// expected-error@-3{{which is not a base}} |
| 139 |
#endif |
| 140 |
|
| 141 |
using E4::e4; |
| 142 |
#if __cplusplus < 202002L |
| 143 |
// expected-warning@-2{{a C++20 extension}} |
| 144 |
// expected-error@-3{{which is not a class}} |
| 145 |
#else |
| 146 |
auto Foo() { return e1; } |
| 147 |
auto Bar() { return e2; } |
| 148 |
#endif |
| 149 |
}; |
| 150 |
|
| 151 |
DER<float> x; // expected-note{{requested here}} |
| 152 |
DER<int> y; |
| 153 |
#if __cplusplus < 202002L |
| 154 |
// expected-note@-2{{requested here}} |
| 155 |
#else |
| 156 |
auto y1 = y.Foo(); |
| 157 |
auto y2 = y.Bar(); |
| 158 |
#endif |
| 159 |
} // namespace Four |
| 160 |
|
| 161 |
namespace Five { |
| 162 |
template <unsigned I, unsigned K> |
| 163 |
struct Quux { |
| 164 |
enum class Q : unsigned; // expected-note{{member is declared here}} |
| 165 |
enum class R : unsigned { i = I, |
| 166 |
k = K }; |
| 167 |
}; |
| 168 |
|
| 169 |
using Quux<1, 2>::Q::nothing; // expected-error{{implicit instantiation of undefined}} |
| 170 |
using Quux<1, 2>::R::i; |
| 171 |
#if __cplusplus < 202002L |
| 172 |
// 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 |
#endif |
| 176 |
|
| 177 |
} // namespace Five |
| 178 |
|
| 179 |
namespace Six { |
| 180 |
template <unsigned I, unsigned K> |
| 181 |
struct Quux { |
| 182 |
enum class Q : unsigned; // expected-note{{member is declared here}} |
| 183 |
enum class R : unsigned { i = I, |
| 184 |
k = K }; |
| 185 |
}; |
| 186 |
|
| 187 |
template <unsigned I> struct Fido { |
| 188 |
using Quux<I, I>::Q::nothing; // expected-error{{implicit instantiation of undefined}} |
| 189 |
}; |
| 190 |
|
| 191 |
Fido<2> a; // expected-note{{in instantiation}} |
| 192 |
|
| 193 |
} // namespace Six |
| 194 |
|
| 195 |
namespace Seven { |
| 196 |
template <unsigned I, unsigned K> |
| 197 |
struct Quux { |
| 198 |
enum class R : unsigned { i = I, |
| 199 |
k = K }; |
| 200 |
}; |
| 201 |
|
| 202 |
template <unsigned I> struct Toto { |
| 203 |
using Quux<I, I>::R::i; |
| 204 |
#if __cplusplus < 202002L |
| 205 |
// expected-warning@-2{{a C++20 extension}} |
| 206 |
// expected-error@-3{{refers into}} |
| 207 |
#else |
| 208 |
static_assert(unsigned(i) == I); |
| 209 |
#endif |
| 210 |
}; |
| 211 |
|
| 212 |
Toto<2> b; |
| 213 |
#if __cplusplus < 202002L |
| 214 |
// expected-note@-2{{in instantiation}} |
| 215 |
#endif |
| 216 |
|
| 217 |
} // namespace Seven |
| 218 |
|
| 219 |
namespace Eight { |
| 220 |
struct Kevin { |
| 221 |
enum class B { a }; |
| 222 |
enum a {}; |
| 223 |
}; |
| 224 |
|
| 225 |
using Kevin::B::a; |
| 226 |
#if __cplusplus < 202002L |
| 227 |
// 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 |
#endif |
| 231 |
using Kevin::B::a; |
| 232 |
#if __cplusplus < 202002L |
| 233 |
// 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 |
#endif |
| 237 |
|
| 238 |
class X : Kevin { |
| 239 |
using Kevin::B::a; // expected-note{{previous using declaration}} |
| 240 |
#if __cplusplus < 202002L |
| 241 |
// expected-warning@-2{{a C++20 extension}} |
| 242 |
#endif |
| 243 |
using Kevin::a; |
| 244 |
using Kevin::B::a; // expected-error{{redeclaration of using declaration}} |
| 245 |
}; |
| 246 |
|
| 247 |
} // namespace Eight |
| 248 |
|
| 249 |
namespace Nine { |
| 250 |
namespace Q { |
| 251 |
enum class Bob { a }; |
| 252 |
using Bob::a; |
| 253 |
#if __cplusplus < 202002L |
| 254 |
// expected-warning@-2{{a C++20 extension}} |
| 255 |
#endif |
| 256 |
} // namespace Q |
| 257 |
|
| 258 |
using Q::a; |
| 259 |
using Q::Bob::a; |
| 260 |
#if __cplusplus < 202002L |
| 261 |
// expected-warning@-2{{a C++20 extension}} |
| 262 |
#endif |
| 263 |
|
| 264 |
#if __cplusplus >= 202002L |
| 265 |
struct 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 |
#endif |
| 271 |
} // namespace Nine |