Debian Codegraph @

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

raw
1
2 struct Token
3 {
4 TokenType type;
5 }
6
7 enum TokenType : ushort
8 {
9 invalid
10 }
11
12 class Parser
13 {
14 bool peekIsOneOf(TokenType[] types...)
15 {
16 canFind(types, tokens[1].type);
17 return true;
18 }
19
20 Token[] tokens;
21 }
22
23 /*************************************************/
24 // std.algorithm
25
26 R find(alias pred = "a == b", R, E)(R haystack, E needle)
27 {
28 enum isIntegralNeedle = isSomeChar!E/* || isIntegral!E || isBoolean!E*/;
29
30 return haystack;
31 }
32
33 bool canFind(alias pred = "a == b", R, E)(R haystack, E needle)
34 if (is(typeof(find!pred(haystack, needle)))) // 1st instantiate of find template with error gagging
35 {
36 return find!pred(haystack, needle).length != 0; // 2nd instantiate of find template without gagging
37 }
38
39 /*************************************************/
40 // std.traits
41
42 template CharTypeOf(T)
43 {
44 inout( char) idx( inout( char) );
45 inout(wchar) idx( inout(wchar) );
46 inout(dchar) idx( inout(dchar) );
47 shared(inout char) idx( shared(inout char) );
48 shared(inout wchar) idx( shared(inout wchar) );
49 shared(inout dchar) idx( shared(inout dchar) );
50
51 static if (is(T == enum))
52 {
53 /* This line instantiates CharTypeOf!short and will make error.
54 * But, when CharTypeOf!short is re-instantiated without gagging,
55 * that's for correct error report, its 'members' does not re-created.
56 * so, members' semantic will call FuncDeclaration::overloadInsert of
57 * 'idx' functions, and will make circular linked list of
58 * FuncDeclaration::overnext. Finally, iterating it will cause
59 * infinite recursion and compiler segfault.
60 */
61 alias .CharTypeOf!(OriginalType!T) CharTypeOf;
62 }
63 else static if (is(typeof(idx(T.init)) X))
64 {
65 alias X CharTypeOf;
66 }
67 else
68 static assert(0, T.stringof~" is not a character type");
69 }
70
71 template isSomeChar(T)
72 {
73 enum isSomeChar = is(CharTypeOf!T);
74 }
75
76 template OriginalType(T)
77 {
78 alias OriginalType = ushort;
79 }