Debian Codegraph @

gcc/testsuite/gdc.test/compilable/issue22646.d

raw
1 // https://issues.dlang.org/show_bug.cgi?id=22646
2
3 static template logicalOr22646(T, const T name)
4 {
5 enum bool ok = name.length < 3 || name[0..3] != "pad";
6 }
7 static template logicalAnd22646(T, const T name)
8 {
9 enum bool ok = name.length >= 3 && name[0..3] == "pad";
10 }
11
12 bool runtime22646Or(T, const T name)()
13 {
14 return name.length < 3 || name[0..3] != "pad";
15 }
16
17 // SCOPE.ctfe
18 static assert(logicalOr22646!(string, "x").ok == true);
19 static assert(logicalOr22646!(string, "foo").ok == true);
20 static assert(logicalOr22646!(string, "pad").ok == false);
21 static assert(logicalOr22646!(string, "pad123").ok == false);
22
23 static assert(logicalOr22646!(char[1], "x").ok == true);
24 static assert(logicalOr22646!(char[3], "foo").ok == true);
25 static assert(logicalOr22646!(char[3], "pad").ok == false);
26 static assert(logicalOr22646!(char[6], "pad123").ok == false);
27
28 static assert(logicalAnd22646!(string, "x").ok == false);
29 static assert(logicalAnd22646!(string, "foo").ok == false);
30 static assert(logicalAnd22646!(string, "pad").ok == true);
31 static assert(logicalAnd22646!(string, "pad123").ok == true);
32
33 static assert(logicalAnd22646!(char[1], "x").ok == false);
34 static assert(logicalAnd22646!(char[3], "foo").ok == false);
35 static assert(logicalAnd22646!(char[3], "pad").ok == true);
36 static assert(logicalAnd22646!(char[6], "pad123").ok == true);
37
38 // SCOPE.compile
39 enum char[1] x22646 = "x";
40 enum char[3] pad22646 = "pad";
41
42 static assert(__traits(compiles, x22646.length < 3 || x22646[0..3] != "pad") == true);
43 static assert(__traits(compiles, x22646.length >= 3 || x22646[0..3] == "pad") == true);
44 static assert(__traits(compiles, pad22646.length < 3 || pad22646[0..3] != "pad") == true);
45 static assert(__traits(compiles, pad22646.length >= 3 || pad22646[0..3] == "pad") == true);
46
47 // sc.intypeof
48 typeof(x22646.length < 3 || x22646[0..3] != "pad") typeof22646or1;
49 static assert(is(typeof(typeof22646or1) == bool));
50 typeof(pad22646.length < 3 || pad22646[0..3] != "pad") typeof22646or2;
51 static assert(is(typeof(typeof22646or2) == bool));
52
53 typeof(x22646.length >= 3 && x22646[0..3] == "pad") typeof22646and1;
54 static assert(is(typeof(typeof22646and1) == bool));
55 typeof(pad22646.length >= 3 && pad22646[0..3] == "pad") typeof22646and2;
56 static assert(is(typeof(typeof22646and2) == bool));
57
58 // No SCOPE flags
59 alias test22646a = runtime22646Or!(string, "x");
60 alias test22646b = runtime22646Or!(string, "foo");
61 alias test22646c = runtime22646Or!(string, "pad");
62 alias test22646d = runtime22646Or!(string, "pad123");
63
64 alias test22646e = runtime22646Or!(char[1], "x");
65 alias test22646f = runtime22646Or!(char[3], "foo");
66 alias test22646g = runtime22646Or!(char[3], "pad");
67 alias test22646h = runtime22646Or!(char[6], "pad123");