| 1 |
/* |
| 2 |
PERMUTE_ARGS: |
| 3 |
RUN_OUTPUT: |
| 4 |
--- |
| 5 |
Success |
| 6 |
--- |
| 7 |
*/ |
| 8 |
|
| 9 |
extern(C) int printf(const char*, ...); |
| 10 |
|
| 11 |
/**********************************************/ |
| 12 |
|
| 13 |
enum Bar |
| 14 |
{ |
| 15 |
bar2 = 2, |
| 16 |
bar3, |
| 17 |
bar4 = 0 |
| 18 |
} |
| 19 |
|
| 20 |
void test1() |
| 21 |
{ |
| 22 |
Bar b; |
| 23 |
|
| 24 |
assert(b == 2); |
| 25 |
} |
| 26 |
|
| 27 |
/**********************************************/ |
| 28 |
|
| 29 |
void test2() |
| 30 |
{ |
| 31 |
enum E |
| 32 |
{ |
| 33 |
a=-1 |
| 34 |
} |
| 35 |
|
| 36 |
assert(E.min == -1); |
| 37 |
assert(E.max == -1); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
/**********************************************/ |
| 42 |
|
| 43 |
void test3() |
| 44 |
{ |
| 45 |
enum E |
| 46 |
{ |
| 47 |
a = 1, |
| 48 |
b = -1, |
| 49 |
c = 3, |
| 50 |
d = 2 |
| 51 |
} |
| 52 |
|
| 53 |
assert(E.min == -1); |
| 54 |
assert(E.max == 3); |
| 55 |
} |
| 56 |
|
| 57 |
/**********************************************/ |
| 58 |
|
| 59 |
void test4() |
| 60 |
{ |
| 61 |
enum E |
| 62 |
{ |
| 63 |
a = -1, |
| 64 |
b = -1, |
| 65 |
c = -3, |
| 66 |
d = -3 |
| 67 |
} |
| 68 |
|
| 69 |
assert(E.min==-3); |
| 70 |
assert(E.max==-1); |
| 71 |
} |
| 72 |
|
| 73 |
/**********************************************/ |
| 74 |
|
| 75 |
enum Enum5 |
| 76 |
{ |
| 77 |
A = 3, |
| 78 |
B = 10, |
| 79 |
E = -5, |
| 80 |
} |
| 81 |
|
| 82 |
void test5() |
| 83 |
{ |
| 84 |
assert(Enum5.init == Enum5.A); |
| 85 |
assert(Enum5.init == 3); |
| 86 |
Enum5 e; |
| 87 |
assert(e == Enum5.A); |
| 88 |
assert(e == 3); |
| 89 |
} |
| 90 |
|
| 91 |
/***********************************/ |
| 92 |
|
| 93 |
enum E6 : byte |
| 94 |
{ |
| 95 |
NORMAL_VALUE = 0, |
| 96 |
REFERRING_VALUE = NORMAL_VALUE + 1, |
| 97 |
OTHER_NORMAL_VALUE = 2 |
| 98 |
} |
| 99 |
|
| 100 |
void foo6(E6 e) |
| 101 |
{ |
| 102 |
} |
| 103 |
|
| 104 |
void test6() |
| 105 |
{ |
| 106 |
foo6(E6.NORMAL_VALUE); |
| 107 |
foo6(E6.REFERRING_VALUE); |
| 108 |
foo6(E6.OTHER_NORMAL_VALUE); |
| 109 |
} |
| 110 |
|
| 111 |
/**********************************************/ |
| 112 |
// https://issues.dlang.org/show_bug.cgi?id=2407 |
| 113 |
|
| 114 |
int i2407; |
| 115 |
|
| 116 |
void add2407() { ++i2407; } |
| 117 |
void sub2407() { --i2407; } |
| 118 |
|
| 119 |
enum EF2407f : void function() |
| 120 |
{ |
| 121 |
a = &add2407, |
| 122 |
s = &sub2407, |
| 123 |
} |
| 124 |
|
| 125 |
enum EF2407s |
| 126 |
{ |
| 127 |
a = &add2407, |
| 128 |
s = &sub2407, |
| 129 |
} |
| 130 |
|
| 131 |
enum |
| 132 |
{ |
| 133 |
a2407 = &add2407, |
| 134 |
s2407 = &sub2407, |
| 135 |
} |
| 136 |
|
| 137 |
enum : void function() |
| 138 |
{ |
| 139 |
at2407 = &add2407, |
| 140 |
st2407 = &sub2407, |
| 141 |
} |
| 142 |
|
| 143 |
enum EEF2407 : EF2407s |
| 144 |
{ |
| 145 |
a = EF2407s.a, |
| 146 |
s = EF2407s.s, |
| 147 |
} |
| 148 |
|
| 149 |
void test2407() |
| 150 |
{ |
| 151 |
alias i2407 i; |
| 152 |
|
| 153 |
EF2407f.a(); |
| 154 |
assert(i == 1); |
| 155 |
EF2407f.s(); |
| 156 |
assert(i == 0); |
| 157 |
|
| 158 |
EF2407s.a(); |
| 159 |
assert(i == 1); |
| 160 |
EF2407s.s(); |
| 161 |
assert(i == 0); |
| 162 |
|
| 163 |
a2407(); |
| 164 |
assert(i == 1); |
| 165 |
s2407(); |
| 166 |
assert(i == 0); |
| 167 |
|
| 168 |
at2407(); |
| 169 |
assert(i == 1); |
| 170 |
st2407(); |
| 171 |
assert(i == 0); |
| 172 |
|
| 173 |
EEF2407.a(); |
| 174 |
assert(i == 1); |
| 175 |
EEF2407.s(); |
| 176 |
assert(i == 0); |
| 177 |
|
| 178 |
EEF2407.init(); |
| 179 |
assert(i == 1); |
| 180 |
|
| 181 |
struct S { int i; } |
| 182 |
enum ES : S |
| 183 |
{ |
| 184 |
a = S(1), |
| 185 |
b = S(3), |
| 186 |
c = S(2), |
| 187 |
} |
| 188 |
static assert(ES.init == S(1)); |
| 189 |
static assert(!__traits(compiles, ES.min)); |
| 190 |
static assert(!__traits(compiles, ES.max)); |
| 191 |
|
| 192 |
enum EES : ES |
| 193 |
{ |
| 194 |
a = ES.a, |
| 195 |
b = ES.b, |
| 196 |
c = ES.c, |
| 197 |
} |
| 198 |
static assert(EES.init == S(1)); |
| 199 |
static assert(!__traits(compiles, EES.min)); |
| 200 |
static assert(!__traits(compiles, EES.max)); |
| 201 |
|
| 202 |
ES es = ES.c; |
| 203 |
assert(es.i == 2); |
| 204 |
es = ES.b; |
| 205 |
assert(es.i == 3); |
| 206 |
|
| 207 |
class C { this(int i) { this.i = i; } int i; } |
| 208 |
enum EC : C |
| 209 |
{ |
| 210 |
a = new C(42), |
| 211 |
b = null, |
| 212 |
c = new C(1), |
| 213 |
d = new C(33), |
| 214 |
} |
| 215 |
static assert(EC.init.i == (new C(42)).i); |
| 216 |
static assert(!__traits(compiles, EC.min)); |
| 217 |
static assert(!__traits(compiles, EC.max)); |
| 218 |
|
| 219 |
EC ec = EC.d; |
| 220 |
assert(ec.i == 33); |
| 221 |
ec = EC.b; |
| 222 |
assert(ec is null); |
| 223 |
} |
| 224 |
|
| 225 |
/**********************************************/ |
| 226 |
// https://issues.dlang.org/show_bug.cgi?id=3096 |
| 227 |
|
| 228 |
void test3096() |
| 229 |
{ |
| 230 |
template Tuple(T...) { alias Tuple = T; } |
| 231 |
|
| 232 |
template Base(E) |
| 233 |
{ |
| 234 |
static if(is(E B == enum)) |
| 235 |
alias Base = B; |
| 236 |
} |
| 237 |
|
| 238 |
template GetEnum(T) |
| 239 |
{ |
| 240 |
enum GetEnum { v = T.init } |
| 241 |
} |
| 242 |
|
| 243 |
struct S { } |
| 244 |
class C { } |
| 245 |
|
| 246 |
foreach (Type; Tuple!(char, wchar, dchar, byte, ubyte, |
| 247 |
short, ushort, int, uint, long, |
| 248 |
ulong, float, double, real, S, C)) |
| 249 |
{ |
| 250 |
static assert(is(Base!(GetEnum!Type) == Type)); |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
/**********************************************/ |
| 255 |
// https://issues.dlang.org/show_bug.cgi?id=7719 |
| 256 |
|
| 257 |
enum foo7719 = bar7719; |
| 258 |
enum { bar7719 = 1 } |
| 259 |
|
| 260 |
/**********************************************/ |
| 261 |
// https://issues.dlang.org/show_bug.cgi?id=9845 |
| 262 |
|
| 263 |
enum { A9845 = B9845 } |
| 264 |
enum { B9845 = 1 } |
| 265 |
|
| 266 |
/**********************************************/ |
| 267 |
// https://issues.dlang.org/show_bug.cgi?id=9846 |
| 268 |
|
| 269 |
const int A9846 = B9846; |
| 270 |
enum { B9846 = 1 } |
| 271 |
|
| 272 |
/**********************************************/ |
| 273 |
// https://issues.dlang.org/show_bug.cgi?id=10105 |
| 274 |
|
| 275 |
enum E10105 : char[1] { a = "a" } |
| 276 |
|
| 277 |
/**********************************************/ |
| 278 |
// https://issues.dlang.org/show_bug.cgi?id=10113 |
| 279 |
|
| 280 |
enum E10113 : string |
| 281 |
{ |
| 282 |
a = "a", |
| 283 |
b = "b", |
| 284 |
abc = "abc" |
| 285 |
} |
| 286 |
|
| 287 |
void test10113() |
| 288 |
{ |
| 289 |
E10113 v = E10113.b; |
| 290 |
bool check = false; |
| 291 |
|
| 292 |
final switch (v) { |
| 293 |
case E10113.a: assert(false); |
| 294 |
case E10113.b: check = true; break; |
| 295 |
case E10113.abc: assert(false); |
| 296 |
} |
| 297 |
|
| 298 |
assert(check); |
| 299 |
} |
| 300 |
|
| 301 |
/**********************************************/ |
| 302 |
// https://issues.dlang.org/show_bug.cgi?id=10503 |
| 303 |
|
| 304 |
@property int octal10503(string num)() |
| 305 |
{ |
| 306 |
return num.length; |
| 307 |
} |
| 308 |
|
| 309 |
enum |
| 310 |
{ |
| 311 |
A10503 = octal10503!"2000000", |
| 312 |
B10503 = octal10503!"4000", |
| 313 |
} |
| 314 |
|
| 315 |
/**********************************************/ |
| 316 |
// https://issues.dlang.org/show_bug.cgi?id=10505 |
| 317 |
|
| 318 |
enum |
| 319 |
{ |
| 320 |
a10505 = true, |
| 321 |
b10505 = 10.0f, |
| 322 |
c10505 = false, |
| 323 |
d10505 = 10, |
| 324 |
e10505 = null |
| 325 |
} |
| 326 |
|
| 327 |
static assert(is(typeof(a10505) == bool)); |
| 328 |
static assert(is(typeof(b10505) == float)); |
| 329 |
static assert(is(typeof(c10505) == bool)); |
| 330 |
static assert(is(typeof(d10505) == int)); |
| 331 |
static assert(is(typeof(e10505) == typeof(null))); |
| 332 |
|
| 333 |
/**********************************************/ |
| 334 |
// https://issues.dlang.org/show_bug.cgi?id=10561 |
| 335 |
|
| 336 |
void test10561() |
| 337 |
{ |
| 338 |
template Tuple(T...) { alias Tuple = T; } |
| 339 |
|
| 340 |
foreach (Type; Tuple!(char, wchar, dchar, byte, ubyte, |
| 341 |
short, ushort, int, uint, long, |
| 342 |
ulong, float, double, real)) |
| 343 |
{ |
| 344 |
enum : Type { v = 0, w = 0, x, y = x } |
| 345 |
static assert(is(typeof(v) == Type)); |
| 346 |
static assert(is(typeof(w) == Type)); |
| 347 |
static assert(is(typeof(x) == Type)); |
| 348 |
static assert(is(typeof(y) == Type)); |
| 349 |
} |
| 350 |
|
| 351 |
class B { } |
| 352 |
class D : B { } |
| 353 |
enum : B { a = new D, b = new B, c = null } |
| 354 |
static assert(is(typeof(a) == B)); |
| 355 |
static assert(is(typeof(b) == B)); |
| 356 |
static assert(is(typeof(c) == B)); |
| 357 |
|
| 358 |
struct S { this(int) { } } |
| 359 |
enum : S { d = S(1), e = S(2) } |
| 360 |
static assert(is(typeof(d) == S)); |
| 361 |
static assert(is(typeof(e) == S)); |
| 362 |
|
| 363 |
enum : float[] { f = [], g = [1.0, 2.0], h = [1.0f] } |
| 364 |
static assert(is(typeof(f) == float[])); |
| 365 |
static assert(is(typeof(g) == float[])); |
| 366 |
static assert(is(typeof(h) == float[])); |
| 367 |
} |
| 368 |
|
| 369 |
/**********************************************/ |
| 370 |
// https://issues.dlang.org/show_bug.cgi?id=10612 |
| 371 |
|
| 372 |
int[E10612] ie10612; |
| 373 |
E10612[int] ei10612; |
| 374 |
E10612[E10612] ee10612; |
| 375 |
|
| 376 |
enum E10612 { a } |
| 377 |
|
| 378 |
/**********************************************/ |
| 379 |
// https://issues.dlang.org/show_bug.cgi?id=10788 |
| 380 |
|
| 381 |
enum v10788 = e10788; |
| 382 |
enum : int { e10788 } |
| 383 |
|
| 384 |
/**********************************************/ |
| 385 |
|
| 386 |
class C7 |
| 387 |
{ |
| 388 |
enum Policy |
| 389 |
{ |
| 390 |
PREFER_READERS, |
| 391 |
PREFER_WRITERS |
| 392 |
} |
| 393 |
|
| 394 |
void foo1( Policy policy = Policy.PREFER_READERS ) { } |
| 395 |
void foo2( Policy policy = Policy.PREFER_WRITERS ) { } |
| 396 |
} |
| 397 |
|
| 398 |
/**********************************************/ |
| 399 |
|
| 400 |
void test8() |
| 401 |
{ |
| 402 |
enum E |
| 403 |
{ |
| 404 |
A = B, |
| 405 |
E = D + 7, |
| 406 |
B = 3, |
| 407 |
C, |
| 408 |
D, |
| 409 |
} |
| 410 |
|
| 411 |
assert(E.A == 3); |
| 412 |
assert(E.B == 3); |
| 413 |
assert(E.C == 4); |
| 414 |
assert(E.D == 5); |
| 415 |
assert(E.E == 12); |
| 416 |
assert(E.max == 12); |
| 417 |
} |
| 418 |
|
| 419 |
/**********************************************/ |
| 420 |
// https://issues.dlang.org/show_bug.cgi?id=13220 |
| 421 |
|
| 422 |
enum E13220a; |
| 423 |
@(1) enum E13220b; |
| 424 |
|
| 425 |
void test13220() |
| 426 |
{ |
| 427 |
auto prot = __traits(getProtection, E13220a); |
| 428 |
assert(prot == "public"); |
| 429 |
|
| 430 |
auto udas = __traits(getAttributes, E13220b); |
| 431 |
assert(udas[0] == 1); |
| 432 |
} |
| 433 |
|
| 434 |
/**********************************************/ |
| 435 |
|
| 436 |
int main() |
| 437 |
{ |
| 438 |
test1(); |
| 439 |
test2(); |
| 440 |
test3(); |
| 441 |
test4(); |
| 442 |
test5(); |
| 443 |
test6(); |
| 444 |
test2407(); |
| 445 |
test10113(); |
| 446 |
test10561(); |
| 447 |
test8(); |
| 448 |
test13220(); |
| 449 |
|
| 450 |
printf("Success\n"); |
| 451 |
return 0; |
| 452 |
} |